Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cciollaro
Forked from alexbevi/pre-commit.sh
Last active December 19, 2015 00:28
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 cciollaro/5868595 to your computer and use it in GitHub Desktop.
Save cciollaro/5868595 to your computer and use it in GitHub Desktop.
# Git pre-commit hook to check all staged Ruby (*.rb/haml/coffee) files
# for Pry binding references
#
# 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
#
#!/bin/sh
echo 'RUNNING PRE-COMMIT'
FILES_PATTERN='\.(rb|haml|erb)(\..+)?$'
FORBIDDEN='binding\.pry'
git diff --cached --name-only | \
grep -E $FILES_PATTERN | \
GREP_COLOR='37;41' xargs grep --color --with-filename -n $FORBIDDEN && \
echo 'COMMIT REJECTED' && \
exit 1
echo 'PRE-COMMIT TESTS PASSED'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment