Created
December 10, 2018 05:16
-
-
Save david-pm/571ec03c0ad9e3eee40ccc98dcbb18d6 to your computer and use it in GitHub Desktop.
pre-push git hook that runs rubocop on latest commit
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 | |
changed_files = `git diff-tree --no-commit-id --name-only --diff-filter=AM -r HEAD`.lines.map(&:chomp) | |
return if changed_files.empty? | |
results = `bundle exec rubocop --color #{changed_files.join(" ")}` | |
no_offenses_detected = results.include?("\e[32mno offenses\e[0m detected") | |
return if no_offenses_detected | |
results.each_line { |line| puts line } | |
puts | |
puts "\e[31m -- WARNING: cannot push to remote repos due to lingering style violations! -- \e[0m" | |
puts | |
exit! 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment