Created
February 1, 2010 16:28
-
-
Save bps/291796 to your computer and use it in GitHub Desktop.
A git pre-commit hook to stop you from committing scratch code.
This file contains hidden or 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 | |
# A hook to abort a commit if your diff adds XXX or FIXME. | |
# Set this config variable if you want to allow it anyway. | |
allowfixmes=$(git config hooks.allowfixmes) | |
disallow_list="XXX FIXME" | |
if [ "$allowfixmes" != "true" ] | |
then | |
for disallow in $disallow_list | |
do | |
if [ "$(git diff --cached | egrep "^\+.*${disallow}" > /dev/null; echo $?)" -eq "0" ] # egrep exits with 0 if it finds at least one match | |
then | |
echo "Error: Your diff will commit ${disallow}:" | |
echo | |
git diff --cached -S"${disallow}" | |
echo | |
echo "To commit anyway, use \`git config --bool hooks.allowfixmes true\`" | |
echo "to set the config variable that skips this check." | |
exit 1 | |
fi | |
done | |
fi | |
# Nothing disallowed added. Allow commit. | |
exit 0 |
And now changed color configuration in .gitconfig from "always" to "auto" and it works even without --color=never
in pre-commit hook.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm sorry. It's definitely not because of quotes. Now I tested it little bit more accurate and found that it works when I switch off color in diff.
So now I have this line in my pre-commit hook: