Skip to content

Instantly share code, notes, and snippets.

@JanBe
Created November 6, 2013 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanBe/7337120 to your computer and use it in GitHub Desktop.
Save JanBe/7337120 to your computer and use it in GitHub Desktop.
Git pre-commit hook to prevent pry stuff from getting into the codebase
# Git pre-commit hook to check all staged files for pry references
#
# Installation
#
# ln -s /path/to/pre-commit.sh /path/to/project/.git/hooks/pre-commit
#
# Based on
#
# http://www.alexbevi.com/blog/2012/08/23/keeping-pry-breakpoints-out-of-git/
#
PRY_PATTERN="require.+[\'\"]pry[\'\"]|binding\.pry"
# Redirect output to stderr.
exec 1>&2
if git diff --cached | grep '^\+' | grep -q -E $PRY_PATTERN; then
echo "ERROR: There is left over pry stuff in this commit"
git diff --cached --name-only | xargs grep -n -H -E $PRY_PATTERN
exit 1 # reject
fi
exit 0
@djmaze
Copy link

djmaze commented Nov 7, 2013

Adding console.log and debugger would be useful as well.

And :focus respectively focus: true, of course.

@johannesboyne
Copy link

I've done something similar with eslint

#!/bin/zsh

function lintit () {
  OUTPUT=$(git diff --name-only | grep -E '(.js)$')
  a=("${(f)OUTPUT}")
  e=$(eslint -c eslint.json $a)
  echo $e
  if [[ "$e" != *"0 problems"* ]]; then
    echo "ERROR: Check eslint hints."
    exit 1 # reject
  fi
}
lintit

useful for the console stuff and to check your code style etc.

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