Created
December 20, 2021 19:18
-
-
Save stephaneliu/278bd103886b641135148b9d3ae3e603 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
run_check = ENV['SAFE_COMMIT'].nil? | |
if run_check | |
focus_hits = [] | |
binding_hits = [] | |
# Find all filenames in spec directory that have been (A)dded (C)opied or (M)odified | |
filenames = `git diff --cached --name-only --diff-filter=ACM`.split("\n") | |
filenames.each do |filename| | |
if filename.end_with? '_spec.rb' | |
`git diff --cached #{filename} | grep \^+\[\^+\] | grep -E 'focus|fit\s|fspecify|fcontext|fdescribe'` | |
focus_hits.push filename if $? == 0 | |
end | |
`git diff --cached #{filename} | grep \^+\[\^+\] | grep binding.pry` | |
binding_hits.push filename if $? == 0 | |
end | |
if focus_hits.any? || binding_hits.any? | |
puts "\e[1;37m\e[41m>>> Commit Aborted! <<<\e[0m" | |
if focus_hits.any? | |
puts "\e[1;31mRemove `focus` from the following specs \e[0m" | |
puts focus_hits.join("\n") | |
end | |
if binding_hits.any? | |
puts "\e[1;31mRemove `binding.pry` from the following files \e[0m" | |
puts binding_hits.join("\n") | |
end | |
puts '' | |
puts 'SAFE_COMMIT=1 if you REALLY want to bypass this.' | |
exit 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment