Kenneth Lynne
Kenneth Lynne

Reputation: 15579

How to perform a command only if there is a change in a subdirectory with git?

I want to run a command lazily on my CI server if and only if there is a change in a subdirectory (between the two latest commits), preferably using git diff.

Upvotes: 0

Views: 57

Answers (2)

asenovm
asenovm

Reputation: 6517

You can use some kind of a file system watcher (like, for example inotifywait) to do the trick.

Upvotes: 1

Kenneth Lynne
Kenneth Lynne

Reputation: 15579

[[ -z "$(git diff --numstat your-sub-folder)" ]] || echo "Changes"

Will run git diff in a subshell, comparing content in "your-sub-folder", and echo Changes if there are any changes detected.

Upvotes: 0

Related Questions