Created
July 21, 2016 19:49
-
-
Save eviltrout/aec918d09c19deca245fe39dc7677aec to your computer and use it in GitHub Desktop.
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 | |
# This pre-commit hook will prompt for every file that contains a `console.log`, `debugger` | |
# or `puts` statement. This should avoid stupidly commiting debugging information :) | |
exec < /dev/tty | |
confirm() { | |
echo "${1:-Are you sure? [y/N]}" | |
read -r response | |
case $response in | |
[yY][eE][sS]|[yY]) | |
true | |
;; | |
*) | |
exit 1 | |
;; | |
esac | |
} | |
if git rev-parse --verify HEAD >/dev/null 2>&1; then | |
against=HEAD | |
else | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
for FILE in `git diff-index --name-status $against -- | cut -c3-` ; do | |
if grep -q 'debugger' "$FILE" | |
then | |
echo $FILE ' contains debugger!' | |
confirm | |
fi | |
if grep -q 'console.log' "$FILE" | |
then | |
echo $FILE ' contains console.log!' | |
confirm | |
fi | |
if grep -q 'puts' "$FILE" | |
then | |
echo $FILE ' contains puts!' | |
confirm | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment