Skip to content

Instantly share code, notes, and snippets.

@yuhonas
Created December 18, 2012 03:48
Show Gist options
  • Save yuhonas/4324830 to your computer and use it in GitHub Desktop.
Save yuhonas/4324830 to your computer and use it in GitHub Desktop.
GIT Pre-Commit hook to prevent silly commits of binding.pry/debugger
#!/bin/sh
# GIT Pre-Commit hook to prevent silly commits of binding.pry/debugger
# Based off http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes
if git rev-parse --verify HEAD >/dev/null 2>&1
then
AGAINST=HEAD
else
# Initial commit: diff AGAINST an empty tree object
AGAINST=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# Redirect output to stderr.
exec 1>&2
DEBUGGERS_REGEX="binding\.pry|debugger"
DIFF_SEARCH=$(git diff-index --name-only --cached $AGAINST -G $DEBUGGERS_REGEX --exit-code)
if [ "$DIFF_SEARCH" ]; then
echo
echo "The following files match the debuggers regex /$DEBUGGERS_REGEX/ [$0]"
echo "------------------------------------------------------"
echo
printf "$DIFF_SEARCH"
echo
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment