Created
August 23, 2012 12:05
-
-
Save alexbevi/3436040 to your computer and use it in GitHub Desktop.
Git pre-commit hook that checks ruby source files for Pry breakpoints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# | |
FILES_PATTERN='\.(rb|haml|coffee)(\..+)?$' | |
FORBIDDEN='binding.pry' | |
git diff --cached --name-only | \ | |
grep -E $FILES_PATTERN | \ | |
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $FORBIDDEN && \ | |
echo 'COMMIT REJECTED' && \ | |
exit 1 | |
exit 0 |
How to do the same operation in ruby?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem with the above solution is that it only allows you to support .rb files. If you'd like your pre-commit hook to run on multiple file types (ie: JS + CSS as well) you can do something like:
That's what I am currently using and it seems to work well.