Skip to content

Instantly share code, notes, and snippets.

@nicogaldamez
Created December 30, 2021 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicogaldamez/c3197dccb155a688f365f90902628fea to your computer and use it in GitHub Desktop.
Save nicogaldamez/c3197dccb155a688f365f90902628fea to your computer and use it in GitHub Desktop.
#!/bin/sh
# Git pre-commit hook to check all staged Ruby (*.rb/js) files
# for Pry binding or debugger references
#
# Installation
#
# ln -s /path/to/pre-commit.sh /path/to/project/.git/hooks/pre-commit
#
FILES='(js|rb)'
FORBIDDEN='(binding.pry|debugger)'
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 "Did you really think I wouldn't notice that? 🙄"
echo "Please fix your diff, or run 'git commit --no-verify' to skip this check." && \
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment