Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check/list all files changed in PR with multiple commits

I want to check the files changed in a PR which might have multiple commits.I have seen multiple answers on how to see the files changed between two commits but that is not my use case. I have a folder called "test-proxy" in my repo. I'm triggering test-proxy deploy stage in the pipeline only if there is a change to the test-proxy folder. Say, I open a PR

commit 1 - no changes in test-proxy folder -> test-proxy deploy stage does not trigger (expected)

commit 2 - changes in test-proxy folder -> test-proxy deploy stage triggers (expected)

commit 3 - no changes in test-proxy folder -> test-proxy deploy stage does not trigger - (not expected)!

This is not ideal because test-proxy test cases might have failed in commit 2 which will get overlooked if the stage does not run again. We cannot leave it on the discretion of the developer to ensure that the stage passes. It should be handled by the pipeline. Now in order to run the test-proxy deploy stage for this PR, the developer will have to make dummy commit to the folder.

Please help in resolving the above concern.

I have tried most of the git commands I found in other answers for testing. These two are the ones I had in my pipeline even though they don't give the exact result -

  1. git diff-tree --name-only HEAD^ HEAD | grep test-proxy

  2. git show --no-commit-id --name-only -r $(git log --pretty=format:'%h' -n 1) | grep test-proxy

Expected -

test-proxy deploy stage should always trigger when any commit in the PR has a change to the test-proxy folder.

like image 364
heretolearn Avatar asked Dec 06 '25 16:12

heretolearn


1 Answers

You want to detect any difference between the tip of the PR and the point where the PR branched off of your current branch (call it master):

git diff-tree --name-only $(git merge-base master HEAD) HEAD -- test-proxy

If you are just interested in whether there was a change, throw in --quiet and --exit-code:

git diff-tree --quiet --exit-code $(git merge-base master HEAD) HEAD -- test-proxy

Note that this will report success if there are no changes in test-proxy.

like image 67
j6t Avatar answered Dec 08 '25 07:12

j6t



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!