Last Updated: Apr 19, 2016
Although it’s extremely convenient during development to add a quick breakpoint using
binding.pry, it can be a bit frustrating to clients if you accidentally deploy with these breakpoints still intact.
After hunting around for a bit, I decided to write a pre-commit hook that would check the files I was about to check in to ensure that I didn’t accidentally still have breakpoints enabled.
for Pry binding references
ln -s /path/to/pre-commit.sh /path/to/project/.git/hooks/pre-commit
# 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
This file just needs to be saved to
/path/to/source/.git/hooks/pre-commit and made executable.
1 2 3
If you happen to leave a breakpoint intact, the next time you try to commit your changes, the commit will fail and indicate where these breakpoints are, and what files need to be updated to allow the commit to succeed.