Skip to content

Instantly share code, notes, and snippets.

@eviltrout eviltrout/pre-commit
Created Jul 21, 2016

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.