Skip to content

Instantly share code, notes, and snippets.

@stephaneliu
Last active December 24, 2015 03:09
Show Gist options
  • Save stephaneliu/6735433 to your computer and use it in GitHub Desktop.
Save stephaneliu/6735433 to your computer and use it in GitHub Desktop.
Git pre-commit hook to alert committer that spec file contains focus
#!/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