-
-
Save cben/b6f4a53fac485f75afb9150d03efb2f6 to your computer and use it in GitHub Desktop.
git pre-commit hook that runs rubocop on staged files
This file contains 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
#!/usr/bin/env ruby | |
# make sure you have gem 'rubocop-git' in your Gemfile | |
require 'readline' | |
def input(prompt="", newline=false) | |
prompt += "\n" if newline | |
Readline.readline(prompt, true).squeeze(" ").strip | |
end | |
# http://stackoverflow.com/questions/3417896/how-do-i-prompt-the-user-from-within-a-commit-msg-hook#comment24746595_10015707 | |
STDIN.reopen('/dev/tty') | |
system("cd #{File.expand_path(__dir__+'/../../')} ; bundle exec rubocop-git --cached") | |
exit 0 if $?.success? | |
exit 0 if input("Commit anyway? [y/N] ") == ?y | |
puts "\nConsider running \e[1mrubocop -a\e[22m on the offensive files" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment