Last active
July 1, 2016 08:50
-
-
Save NGMarmaduke/0f2d32871bbf3c7ee974473ccdfaf1d6 to your computer and use it in GitHub Desktop.
Git hooks
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 | |
DEBUG_PATTERS = [ | |
'^\s*fit', # RSPEC focus it | |
'^\s*fdescribe', # RSPEC focus describe | |
'^\s*fexample', # RSPEC focus example | |
'^\s*fspecify', # RSPEC focus specify | |
'^\s*fcontext', # RSPEC focus context | |
'^\s*fscenario', | |
'^\s*ffeature', | |
'console.log', | |
'puts', | |
'Rails.logger.info', | |
'byebug', | |
'save_page_and_debug', | |
'binding.pry', | |
'^\s*<<<<<<< ', # git conflict | |
] | |
Z40 = '0000000000000000000000000000000000000000' | |
def any_debug?(range) | |
regex = DEBUG_PATTERS.join('|') | |
offending_commits = `git log -G'#{regex}' #{range}` | |
if offending_commits != '' | |
puts "FOUND DEBUGGING IN:" | |
puts "#{offending_commits}" | |
puts "\n\nCannot push until debugging has been remove\nAdd --no-verify to skip this check\n\n" | |
return true | |
end | |
false | |
end | |
while info = STDIN.gets | |
local_ref, local_sha, remote_ref, remote_sha = info.split(' ') | |
next if local_sha == Z40 # deleted | |
if remote_sha == Z40 # New branch | |
exit 0 | |
range = local_sha #FIXME | |
else | |
range = "#{remote_sha}..#{local_sha}" | |
end | |
exit 1 if any_debug?(range) | |
end | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment