Reputation: 382
I want to look at the latest commit and determine if there were any changes made to files in the following file or filename. Respectively apiproxy (folder) or edge.json (filename)
I'm running the following code (the steps.sh is some library specific thing the company uses. It's just a shell command):
if((steps.sh ('git show --name-only HEAD | grep "apiproxy"')) || (steps.sh ('git show --name-only HEAD | grep "edge.json"'))){
echo "latest commit was a change to either edge.json or apiproxy"
}
When above executes while the latest changes were only made to match the first condition, the second condition will fail. In my thinking the ||
in between should prevent this from happening.
This is the first problem I'd like to solve. Evaluate both conditions and don't exit with exit code 1 when one of these fail.
Secondly I would like to put the ||
conditions in a single grep command if possible. I've tried the following to no avail:
git show --name-only HEAD | grep "edge.json | apiproxy"
Any pointers?
UPATE:
So with some help from 0andriy I've figured out that I want to use git show --name-only "filename1" "filename2"
Now my remaining question is: How can I put an or condition in the git show
e.g. git show --name-only "apiproxy" || "edge.json"
?
Upvotes: 0
Views: 61
Reputation: 382
Although above answers were quite helpful in pointing me towards the right direction, the solution to my problem is as follows:
git show --name-only "filename1" "filename2"
This outputs the specified filenames to which changes have been made in the HEAD
state
The or statement is not helpful because it (obviously) stops at the first encounter of any match in the condition and I want to look for all matches.
Upvotes: 0
Reputation: 5618
git show HEAD --name-only --pretty="" |grep 'apiproxy\|edge.json'
UPDATED. Restrict to exact file names
git show HEAD --name-only --pretty="" |grep '^apiproxy$\|^edge.json$'
Upvotes: 1