Created
March 28, 2016 19:07
-
-
Save reidransom/44d45e0a1e94dd8d26e9 to your computer and use it in GitHub Desktop.
Pre-commit hook to check for debug statements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
GREP_COLOR='4;5;37;41' | |
EXIT_STATUS=0 | |
cd "$( dirname "$( dirname "$( dirname ${BASH_SOURCE[0]} )" )" )" | |
commitcheck () { | |
FILES=$1 | |
FORBIDDEN=$2 | |
if [[ $(git diff --cached --name-only | grep -E $FILES) ]]; then | |
git diff --cached --name-only | grep -E $FILES | \ | |
xargs grep --color --with-filename -n -E $FORBIDDEN && \ | |
EXIT_STATUS=1 | |
fi | |
} | |
commitcheck 'py' 'pdb\.set_trace' | |
commitcheck 'js' '(console\.log|console\.debug)' | |
cd - > /dev/null | |
if [[ $EXIT_STATUS == 1 ]]; then | |
echo "Please fix your diff, or run 'git commit --no-verify'." | |
fi | |
exit $EXIT_STATUS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment