Skip to content

Instantly share code, notes, and snippets.

@jcamenisch
Last active August 29, 2015 14:04
Show Gist options
  • Save jcamenisch/0133576a7496a4644383 to your computer and use it in GitHub Desktop.
Save jcamenisch/0133576a7496a4644383 to your computer and use it in GitHub Desktop.
# Git pre-commit hook to block forbidden code
#
# Installation
#
# ln -s /path/to/pre-commit.sh /path/to/project/.git/hooks/pre-commit
#
# Based on
#
# http://codeinthehole.com/writing/tips-for-using-a-git-pre-commit-hook/
# http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes
# https://gist.github.com/3266940
#
FORBIDDEN='binding\.pry|console\.log'
git diff --cached --quiet || (\
git diff --cached --name-only | \
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $FORBIDDEN && \
echo 'COMMIT REJECTED' && \
exit 1)
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment