Skip to content

Instantly share code, notes, and snippets.

@excalq
Created December 19, 2012 17:48
Show Gist options
  • Save excalq/4338714 to your computer and use it in GitHub Desktop.
Save excalq/4338714 to your computer and use it in GitHub Desktop.
Adding a Git Hook to prevent console.log() from appearing in your code

Place the code below into this file: (Inside your local project repo)

  .git/hooks/pre-commit
#!/bin/sh
 
if git rev-parse --verify HEAD >/dev/null 2>&1; then
    against=HEAD
else
    against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
 
for FILE in `git diff-index --name-status $against -- | cut -c3-` ; do
    # Check if javascript contains console.log()
    if grep --quiet 'console\.log' "$FILE"
    then
        echo "***$FILE*** contains console.log() in this commit! Please remove it or IE users will die!"
        exit 0
    fi
done
exit 

And run this command:

  chmod +x .git/hooks/pre-commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment