Execute git pre-commit hook only if files in certain directory modified
try,
git diff --cached --name-only | if grep --quiet "$SRC_PATTERN"
then
...
Happy hacking
Try it like this:
SRC_PATTERN="site/assets/js/"
if git diff --cached --name-only | grep --quiet "$SRC_PATTERN"
then
echo "none"
exit 0
fi
This looks a lot like the accepted answer, but that one is wrong. In bash/sh each command in a pipeline is executed in a separate subshell, so an exit in the then part will only exit the subshell, any code that follows the fi will still be executed!