Skip to content

Instantly share code, notes, and snippets.

@bps
Created February 1, 2010 16:28
Show Gist options
  • Save bps/291796 to your computer and use it in GitHub Desktop.
Save bps/291796 to your computer and use it in GitHub Desktop.
A git pre-commit hook to stop you from committing scratch code.
#!/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
@Grandmother
Copy link

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