Last active
December 24, 2015 03:09
-
-
Save stephaneliu/6735433 to your computer and use it in GitHub Desktop.
Git pre-commit hook to alert committer that spec file contains focus
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 | |
spec_hits = [] | |
# Find the names of all the 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' | |
results = `git diff --cached #{filename} | grep \^+\[\^+\] | grep focus` | |
spec_hits.push filename if $? == 0 # $? - status of last external process run | |
end | |
end | |
if spec_hits.any? | |
puts "\e[1;37m\e[41m>>> Please remove `focus` from the following specs before committing\e[0m" | |
puts spec_hits.join("\n") | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment