Created
August 8, 2013 23:02
-
-
Save bracke/6189633 to your computer and use it in GitHub Desktop.
Git hook: pre-commit
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 | |
red='\x1B[0;31m' | |
green='\x1B[0;32m' | |
NC='\x1B[0m' # No Color | |
underline='\033[4m' | |
git stash -q --keep-index | |
# Test | |
grunt test | |
RESULT=$? | |
[[ $? -ne 0 ]] && echo "${red}Test failed, can't commit${NC}" | |
echo | |
if git rev-parse --verify HEAD >/dev/null 2>&1; then | |
against=HEAD | |
else | |
# put the first changeset hash value in your project here (I think) | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
echo "${underline}Searching for debug statements" | |
# Search for debug statements | |
for FILE in `git diff-index --name-status $against -- | cut -c3-` ; do | |
# Check if the file contains 'debugger' | |
if grep -q 'debugger' "$FILE" | |
then | |
echo "${red}$FILE contains debugger${NC}" | |
RESULT=1 | |
fi | |
# Check if the file contains 'console.log' | |
if grep -q 'console.log' "$FILE" | |
then | |
echo "${red}$FILE contains console.log${NC}" | |
RESULT=1 | |
fi | |
done | |
git stash pop -q | |
[ $RESULT -ne 0 ] && exit 1 | |
echo "${green}Done, none found." | |
echo | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment