Created
March 13, 2013 22:50
-
-
Save zgohr/5157172 to your computer and use it in GitHub Desktop.
Pre commit hook to grep through modified files for forbidden words and reject if found. A better hook would grunt your repo with things like jshint and follow a set of static analysis project standards.
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/bash | |
# Grep through modified files for forbidden words and reject commit if found | |
FILE_PATTERN='\.(js)(\..+)?$' # Separate more file types with pipes here | |
FORBIDDEN=( debugger ) # Separate more forbidden strings with spaces here | |
for i in "${FORBIDDEN[@]}" | |
do | |
git diff --cached --name-only | \ | |
grep -E $FILE_PATTERN | \ | |
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $i && \ | |
echo 'COMMIT REJECTED Found' $i 'references. Please remove them before commiting' && exit 1 | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment