Skip to content

Instantly share code, notes, and snippets.

@SkyM
Created January 19, 2012 17:57
Show Gist options
  • Save SkyM/1641459 to your computer and use it in GitHub Desktop.
Save SkyM/1641459 to your computer and use it in GitHub Desktop.
git pre-commit hook to stop bad words
#!/usr/bin/env ruby
FORBIDDEN = [
/\bdebugger\b/,
/\bfuck\b/,
/\bshit\b/,
/\bbitch\b/,
/\bwtf\b/,
/\bconsole\.debug\b/,
/\bLorem\.ipsum\.dolor\.sit\.amet\b/,
/\bdo not commit\b/i
]
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