Created
May 27, 2011 20:52
-
-
Save slindberg/996141 to your computer and use it in GitHub Desktop.
Git Pre-commit Hook
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 | |
# | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sweet. Thanks!