Skip to content

Instantly share code, notes, and snippets.

@slindberg
Created May 27, 2011 20:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slindberg/996141 to your computer and use it in GitHub Desktop.
Save slindberg/996141 to your computer and use it in GitHub Desktop.
Git Pre-commit Hook
#!/bin/sh
#
# Pre-commit Hook
#
# Searches for black-listed strings in the commit and exits with an
# error if found, printing a diff of the location of the offending string
#
STATUS=0;
BLACKLIST="error_log
console.log";
echo "Running pre-commit hook..."
# look for blacklisted strings in the commit
for string in $BLACKLIST; do
output=`git diff-index -u --cached --color -S$string HEAD`
if [ -n "$output" ]; then
echo "\nError: commit contains blacklisted pattern '$string':\n\n$output\n"
STATUS=1
fi
done
echo "done."
exit $STATUS
@cyk
Copy link

cyk commented Jun 21, 2011

Sweet. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment