Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. hits = []
  3.  
  4. checks = {
  5. #'_spec\.rb$' => ['focus:[:space:]*true'],
  6. '\.rb$' => ['binding\.pry', 'debugger']
  7. }
  8.  
  9. # Find the names of all the filenames that have been (A)dded (C)opied or (M)odified
  10. filenames = `git diff --cached --name-only --diff-filter=ACM`.split("\n")
  11.  
  12. filenames.each do |filename|
  13. # Perform special checks for _spec filenames (rspec tests)
  14. checks.each do |filename_pattern, patterns|
  15. if filename.match filename_pattern
  16. patterns.each do |contents_pattern|
  17. results = `git diff --cached #{filename} | grep "^\+[^+]" | grep "#{contents_pattern}"`.split("\n").map { |r| r.sub(/^\+[\s\t]*/, '') }
  18. if $? == 0
  19. # Add the relevant change with line number to the hits array
  20. results.each{ |r|
  21. hits.push "#{filename}:" + `grep -n '#{r}' #{filename}`.sub(/:\s+/, ' ').chomp
  22. }
  23. end
  24. end
  25. end
  26. end
  27. end
  28.  
  29. if hits.any?
  30. puts "\e[33m>>> Please remove the following problems from these files before committing\e[0m"
  31. puts hits.join("\n")
  32. end
  33.  
  34. exit 1 if hits.any?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement