Skip to content

Instantly share code, notes, and snippets.

@jasondscott
Last active June 6, 2017 20:05
Show Gist options
  • Save jasondscott/e86e69e1501a401bf4a9ff43b401f76f to your computer and use it in GitHub Desktop.
Save jasondscott/e86e69e1501a401bf4a9ff43b401f76f to your computer and use it in GitHub Desktop.
pre-commit hook
echo "Running debugger check"
FILES=$(git diff --cached --name-only HEAD)
RED='\x1B[0;31m';
DEBUG_COMMANDS='debugger|console\.log|binding\.pry'
# Adding /dev/null so that grep reports file name when only one file is given
ERRORS=$(grep -E --line-number $DEBUG_COMMANDS $FILES /dev/null)
if [ -n "$ERRORS" ]; then
echo "${ERRORS}"
echo "${RED}Commit was rejected because it contains debug statements."
exit 1
fi
exit
@jasondscott
Copy link
Author

  • Add to .git/hooks/
  • chmod +x pre-commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment