raarts
raarts

Reputation: 2961

command to find if anything below a given directory was changed in the last commit

To speed up running tests during CI, I need to know for a given directory if anything in or below that directory was changed in the last commit, so I can skip the tests for that directory.

Does such a command exist? I am not looking for the specific files that changed, just for a command that exits 1 if anything was changed, and 0 otherwise.

Upvotes: 1

Views: 93

Answers (1)

j6t
j6t

Reputation: 13377

Since you mention CI, I assume you are writing a script. Then you should use the "plumbing" (low-level) commands. This would do:

if git diff-tree --quiet --exit-code HEAD^:"$subdir" HEAD:"$subdir"
then
    # no change
else
    # there was a change
fi

Upvotes: 2

Related Questions