Skip to content

Instantly share code, notes, and snippets.

@adillera
Created February 2, 2017 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adillera/b51b0668abb8a97c04ab485a2d71973a to your computer and use it in GitHub Desktop.
Save adillera/b51b0668abb8a97c04ab485a2d71973a to your computer and use it in GitHub Desktop.
Pre-commit hook. Add this to your .git/hooks to be reminded if you placed a debugger somewhere. Add file types in FILES variable and the forbidden texts in FORBIDDEN
#!/bin/sh
FILES='(js|css|rb)'
FORBIDDEN='(binding.pry|console.log|debugger|byebug|\!important)'
GREP_COLOR='4;5;37;41'
if [[ $(git diff --cached --name-only | grep -E $FILES) ]]; then
git diff --cached --name-only | grep -E $FILES | \
xargs grep --color --with-filename -n -E $FORBIDDEN && \
echo "Looks like you are trying to commit something you shouldn't. Please fix your diff, or run 'git commit --no-verify' to skip this check, if you must." && \
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment