Created
November 14, 2022 23:30
-
-
Save cdeutsch/67c927ac10b764453a815d8055faa4b8 to your computer and use it in GitHub Desktop.
Git pre-commit that checks for swearing
This file contains hidden or 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
####################################################################################################################################### | |
# Check for swearing and other words | |
# https://gist.github.com/SkyM/1641459 | |
####################################################################################################################################### | |
"`dirname $0`"/pre-commit-swearing | |
if [ $? -ne 0 ] | |
then | |
exit 1; | |
fi |
This file contains hidden or 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 | |
# fix some stupid bug with sourcetree | |
Encoding.default_external = Encoding::UTF_8 | |
Encoding.default_internal = Encoding::UTF_8 | |
####################################################################################################################################### | |
# Check for swearing and other words | |
# https://gist.github.com/SkyM/1641459 | |
####################################################################################################################################### | |
FORBIDDEN = [ | |
/\bfuck\b/, | |
/\bshit\b/, | |
/\bbitch\b/, | |
/\bwtf\b/, | |
/\bdo not commit\b/i | |
] | |
full_diff = `git diff --cached --` | |
full_diff.downcase.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