Skip to content

Instantly share code, notes, and snippets.

@NGMarmaduke
Last active July 1, 2016 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NGMarmaduke/0f2d32871bbf3c7ee974473ccdfaf1d6 to your computer and use it in GitHub Desktop.
Save NGMarmaduke/0f2d32871bbf3c7ee974473ccdfaf1d6 to your computer and use it in GitHub Desktop.
Git hooks
#!/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