Last active
June 28, 2017 06:57
-
-
Save xealgo/6ed8b2760a672af01644e9e58b2c1c4e to your computer and use it in GitHub Desktop.
git pre-commit
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 | |
FORBIDDEN = [ | |
/debugger/i, | |
/fuck/i, | |
/shit/i, | |
/bitch/i, | |
/wtf/i, | |
/fmt.Println/i, | |
/fmt.Printf/i, | |
/console\.debug/i, | |
/Lorem\.ipsum\.dolor\.sit\.amet/i, | |
/do not commit/i, | |
/balls/i, | |
/omfg/i, | |
/fucking/i, | |
/blah/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 "%{uh, you have debug shit in your code... '#{$1 || $&}' to #{file}}" | |
puts "YOLO? Use --no-verify" | |
puts "==============================================================================" | |
exit 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment