I have gotten to the point where I can use
git diff --ignore-all-space --ignore-blank-lines --ignore-space-at-eol origin/main -W
To get a clean diff with only non white space changes. This outputs the whole file. What I need though is a check to determine if a specific field had a change in the diff.
For instance this field could be
"description": {
"en-US": "Muh kinda description."
},
I need to have a truthy value in my bash script if the contents of en-US changed. Or any value between the curlies.
However description could also be this:
"description": "Muh description"
In both cases, if there is a diff from the main branch I need a to be able to make a use of it in an if statement.
However, that's only to try and achieve these ends. The end goal is that I can have a script that exits with a non zero code only if changes besides those definitions are changed. It's not just this field that could be changed. It could be another. But if it's description's content that has changed and only that I need to be able to use it as a control flow value.
So to clarify, description can follow two formats. One is a pair of key and string or key and curly braces containing multiple language interpretations of that description. I need to know if those are the only changes in a file or not.
If they are the only changes I need my azure devops pipeline to just be fine with continuing. If there are other parts of the file that changed I need to pass a separate bool check that verifies another line in fact has also changed. The challenge is this description field. I am having a hard time capturing that this changed while also verifying no other parts have changed.
I have gotten to the point where I can use
git diff --ignore-all-space --ignore-blank-lines --ignore-space-at-eol origin/main -W
To get a clean diff with only non white space changes. This outputs the whole file. What I need though is a check to determine if a specific field had a change in the diff.
For instance this field could be
"description": {
"en-US": "Muh kinda description."
},
I need to have a truthy value in my bash script if the contents of en-US changed. Or any value between the curlies.
However description could also be this:
"description": "Muh description"
In both cases, if there is a diff from the main branch I need a to be able to make a use of it in an if statement.
However, that's only to try and achieve these ends. The end goal is that I can have a script that exits with a non zero code only if changes besides those definitions are changed. It's not just this field that could be changed. It could be another. But if it's description's content that has changed and only that I need to be able to use it as a control flow value.
So to clarify, description can follow two formats. One is a pair of key and string or key and curly braces containing multiple language interpretations of that description. I need to know if those are the only changes in a file or not.
If they are the only changes I need my azure devops pipeline to just be fine with continuing. If there are other parts of the file that changed I need to pass a separate bool check that verifies another line in fact has also changed. The challenge is this description field. I am having a hard time capturing that this changed while also verifying no other parts have changed.
Share Improve this question edited Mar 13 at 21:54 oguz ismail 51k16 gold badges60 silver badges79 bronze badges asked Mar 13 at 20:46 rlperezrlperez 1,3203 gold badges22 silver badges44 bronze badges1 Answer
Reset to default 1You can use textconv's to check exactly the parts you care about, by having json files use any configured json differ but not configuring one except when you want it:
echo \*.json diff=json >>.git/info/attributes # make these files use json diffs locally
git -c diff.json.textconv='jq -c '\''.description.["en-US"]'\' diff origin/main --
and if you don't provide any configuration for the json diffs Git will just use its defaults, see the docs for this to see all the tweaks. The odd singlequote escaping is there because the textconv value is being passed as a shell command, they're there for the second round.
I need to have a truthy value in my bash script if the contents of en-US changed. Or any value between the curlies.
Then git -c diff.json.textconv='jq -c .description' diff --quiet origin/main -- that.json
with that setup and going on your example snippet should do it.