Created
October 26, 2016 12:41
-
-
Save syncrou/34b29577c3dfafc75207601b90e3e749 to your computer and use it in GitHub Desktop.
pre-commit.sh for RuboCop
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