Created
February 24, 2013 13:26
-
-
Save omribahumi/5023839 to your computer and use it in GitHub Desktop.
pre-commit git hook to make sure developers don't accidentally commit code they didn't mean to commit :)
This file contains 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 | |
# 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
This is awesome! can you make it unstage hunks surrounded with NOCOMMIT? something like:
[some code] will not be commited.