I'm aborting git commit if a certain condition is met.
check if my commit has 'import pdb' in emacs/git?
#!/bin/sh
git diff --cached --no-renames --name-status --diff-filter=AM |
while read st file; do
case "$file" in
*.py)
if git show ":$file" |
grep -E "^[^#]*\bimport[[:space:]]+pdb\b"; then
echo "$file: has import pdb"
exit 1
fi;;
esac
done
git diff --cached --name-status --diff-filter=ACM | while read st file; do
if grep "#[[:space:]]*@test" "$file"; then
echo "$file: has @test"
exit 1
fi
done
The code runs fine and I can see the log "... has import pdb"
But the next line exit 1
won't abort the git commit.
It used to work fine, but it stopped working at some point. I'm on git 1.9.1
output
$ GIT_TRACE=2 git commit
trace: built-in: git 'commit'
trace: run_command: '.git/hooks/pre-commit'
trace: built-in: git 'diff' '--cached' '--no-renames' '--name-status' '--diff-filter=AM'
trace: built-in: git 'show' ':momsite/apps/custom_push_notifications/utils.py'
import pdb; pdb.set_trace()
momsite/apps/custom_push_notifications/utils.py: has import pdb
trace: built-in: git 'diff' '--cached' '--name-status' '--diff-filter=ACM'
trace: run_command: 'emacs' '/home/eugenekim/Documents/zibann/.git/COMMIT_EDITMSG'
trace: exec: 'emacs' '/home/eugenekim/Documents/zibann/.git/COMMIT_EDITMSG'