Created
October 3, 2012 18:27
-
-
Save tisho/3828821 to your computer and use it in GitHub Desktop.
Forbidden code pre-commit hook
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 | |
# Pre commit hook that prevents FORBIDDEN code from being commited. | |
# Add unwanted code to the FORBIDDEN array as necessary | |
FILES_PATTERN='\.(js|coffee)(\..+)?$' | |
FORBIDDEN=( debugger console.log ) | |
for FILE in `git diff --cached --name-only | grep -E $FILES_PATTERN`; do | |
for i in "${FORBIDDEN[@]}" | |
do | |
grep -n --color "^[ ]*$i" $FILE && echo "ERROR: The file \"$FILE\" contains \"$i\"" && exit 1 | |
done | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment