Skip to content

Instantly share code, notes, and snippets.

@chriswl
Created January 10, 2013 16:08
Show Gist options
  • Save chriswl/4503248 to your computer and use it in GitHub Desktop.
Save chriswl/4503248 to your computer and use it in GitHub Desktop.
git pre-commit hook to check all staged python files for mentioning pdb
# Git pre-commit hook to check all staged python files for mentioning pdb
#
# Installation
#
# ln -s /path/to/pre-commit_breakpoints.sh /path/to/project/.git/hooks/pre-commit
#
# Based on
#
# http://codeinthehole.com/writing/tips-for-using-a-git-pre-commit-hook/
# http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes
# https://gist.github.com/3266940
# https://gist.github.com/3436040
FILES_PATTERN='\.(py)(\..+)?$'
FORBIDDEN="^[#].*pdb"
git diff --cached --name-only --diff-filter=ACM | \
grep -E $FILES_PATTERN | \
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $FORBIDDEN && \
echo 'COMMIT REJECTED bc of breakpoints' && \
exit 1
exit 0
@chriswl
Copy link
Author

chriswl commented Jan 21, 2013

Fails if there are no python files in the commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment