Skip to content

Instantly share code, notes, and snippets.

@eviltrout
Created July 21, 2016 19:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eviltrout/aec918d09c19deca245fe39dc7677aec to your computer and use it in GitHub Desktop.
Save eviltrout/aec918d09c19deca245fe39dc7677aec to your computer and use it in GitHub Desktop.
#!/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