Skip to content

Instantly share code, notes, and snippets.

@zgohr
Created March 13, 2013 22:50
Show Gist options
  • Save zgohr/5157172 to your computer and use it in GitHub Desktop.
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.
#!/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