Git pre-commit hook script for Ruby on Rails projects

If you have ever worked on a Ruby on Rails project that uses Git for version control, odds are that you have run into a scenario where you (or other developers on your team) have accidentally committed a debugger statement or a binding.pry and checked it into the Git repo.

One of the developers on our team at Attribytes recently shared a really cool script that he found which checks for common debugger statements in your code every time someone commits code to Git, and halts the commit if an offending line is found.

The script worked pretty well, but it was throwing a lot of false positives and it was lacking some features I wanted (such as an ignore list), so I modified it to fit our needs.

Here’s the resulting script:

For bonus points, place this script into the root of your project itself as a file named “pre-commit” and check it into the git repo. You could also include a little shell script to make it easy for everyone who works on the project to quickly install the hook!

install-git-pre-commit-hooks.sh:

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you a real person? *