Skip to content

Instantly share code, notes, and snippets.

@amirnissim
Forked from omribahumi/pre-commit
Created July 14, 2013 06:46
Show Gist options
  • Save amirnissim/5993433 to your computer and use it in GitHub Desktop.
Save amirnissim/5993433 to your computer and use it in GitHub Desktop.
#git
#!/bin/sh
# pre-commit git hook to make sure developers don't accidentally commit code they didn't mean to commit :)
REMOVEME_STRING="REMOVEME"
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)" != "" ]
then
echo "Error: Attempt to add a line containing the forbidden string $REMOVEME_STRING"
echo
echo "If you know what you are doing you can disable this check using:"
echo
echo " git config hooks.allowcommittingremoveme true"
echo
echo "After you're done, set it back using:"
echo
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