Reputation: 33
My project has client code and server code in one project
I want to run the test code through the pre-commit hook only when the client code has been modified.
Is there a way to run a pre-commit hook only when a file is modified under a specific folder?
Upvotes: 3
Views: 3450
Reputation: 2434
The hook cannot be prevented from executing, but you can prevent the bulk of the script from running using a conditional.
git diff --cached --name-only --diff-filter=ACM src/
will return the list of files added, copied or modified in the src/
folder.
In your hook script, check the number of lines that are output from the git diff
command using wc -l
, and exit the hook early if the output is "0".
Upvotes: 2