Skip to content

Instantly share code, notes, and snippets.

@tisho
Created October 3, 2012 18:27
Show Gist options
  • Save tisho/3828821 to your computer and use it in GitHub Desktop.
Save tisho/3828821 to your computer and use it in GitHub Desktop.
Forbidden code pre-commit hook
#!/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