Skip to content

Instantly share code, notes, and snippets.

@eduardo-matos
Last active October 5, 2020 13:58
Show Gist options
  • Save eduardo-matos/8555eb3d6511dff5eed9 to your computer and use it in GitHub Desktop.
Save eduardo-matos/8555eb3d6511dff5eed9 to your computer and use it in GitHub Desktop.
Don't commit ipdb, debugger, console, and print statements.
#!/usr/bin/env ruby
FORBIDDEN = [
/\bdebugger\b/,
/\bprint\b/,
/\bconsole\.*\b/,
/\bipdb\b/,
/\b\.only\b/,
]
full_diff = `git diff --cached --`
full_diff.scan(%r{^\+\+\+ b/(.+)\n@@.*\n([\s\S]*?)(?:^diff|\z)}).each do |file, diff|
added = diff.split("\n").select { |x| x.start_with?("+") }.join("\n")
if FORBIDDEN.any? { |re| added.match(re) }
puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
puts %{WHAT ARE YOU THINKING YOU ASSHOLE! You cannnot commit "#{$1 || $&}" to #{file}}
puts "To commit anyway, use --no-verify (which you fucking shouldn't do!)"
puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment