Keeping Pry Breakpoints out of Git

My Ruby workflow as of late has almost always contained Git for version control, and Pry for debugging.

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.

# 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

This file just needs to be saved to /path/to/source/.git/hooks/pre-commit and made executable.

1
2
3
HOOK_URL="https://gist.githubusercontent.com/alexbevi/3436040/raw/pre-commit.sh"
curl $HOOK_URL > /path/to/source/.git/hooks/pre-commit
chmod +x /path/to/source/.git/hooks/pre-commit

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.

Comments