Skip to content

Instantly share code, notes, and snippets.

@jvatic
Created May 16, 2012 16:00
Show Gist options
  • Save jvatic/2711625 to your computer and use it in GitHub Desktop.
Save jvatic/2711625 to your computer and use it in GitHub Desktop.
Git pre-commit hook to block committing Spec files with :focus => true on test blocks
#!/usr/bin/env ruby
# vim: set syntax=ruby
flag = false
files = `git diff --cached --name-only --diff-filter=ACM | grep "_spec\.rb$"`.split("\n")
files.each do |file|
results = `git diff --cached #{file} | grep "^\+[^+]" | grep ":focus => true"`.split("\n").map { |r| r.sub(/^\+[\s\t]*/, '') }
if $? == 0
puts file
puts results.map { |r|
`grep -n "#{r}" #{file}`
}.join("")
puts "Please remove :focus => true from your tests before committing"
flag = true
end
end
exit 1 if flag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment