Skip to content

Instantly share code, notes, and snippets.

@ranbena
Forked from omribahumi/pre-commit
Last active December 14, 2015 23:09
Show Gist options
  • Save ranbena/5163272 to your computer and use it in GitHub Desktop.
Save ranbena/5163272 to your computer and use it in GitHub Desktop.
#!/bin/sh
# pre-commit git hook to make sure developers don't accidentally commit code they didn't mean to commit :)
REMOVEME_STRING="REMOVEME"
DEBUGGER_STRING="debugger"
ALLOW_COMMITTING_REMOVEME=`git config hooks.allowcommittingremoveme`
# redirect stdout to stderr
exec 1>&2
if [ "$ALLOW_COMMITTING_REMOVEME" != "true" ] &&
([ "$(git diff --cached | egrep '^\+[^\+]+' | grep $REMOVEME_STRING)" != "" ] ||
[ "$(git diff --cached | egrep '^\+[^\+]+' | grep $DEBUGGER_STRING)" != "" ])
then
echo "Error: Uh oh, you forgot a $REMOVEME_STRING or $DEBUGGER_STRING in your code."
echo
echo "If you want to disable this check use:"
echo " git config hooks.allowcommittingremoveme true"
echo "When you're done, set it back using:"
echo " git config --unset hooks.allowcommittingremoveme"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment