Skip to content

Instantly share code, notes, and snippets.

@david-pm
Created December 10, 2018 05:16
Show Gist options
  • Save david-pm/571ec03c0ad9e3eee40ccc98dcbb18d6 to your computer and use it in GitHub Desktop.
Save david-pm/571ec03c0ad9e3eee40ccc98dcbb18d6 to your computer and use it in GitHub Desktop.
pre-push git hook that runs rubocop on latest commit
#!/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