Last active
February 28, 2024 11:11
-
-
Save skwashd/8732878 to your computer and use it in GitHub Desktop.
Git pre-commit hook that blocks commits for files that contain swear words.
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
#!/bin/bash -e | |
# | |
# Git pre-commit hook that blocks commits for files that contain swear words. | |
# | |
# Created by Dave Hall - http://davehall.com.au | |
# Distributed under the terms of the WTFPL - http://www.wtfpl.net/ | |
# | |
# Please don't use this fucking script, it is shit! | |
# | |
# If you want to commit something with swearing use FUCK_IT=1 git commit ... | |
if [ ! -z "$FUCK_IT" ]; then | |
exit 0 | |
fi | |
ROOT_DIR=$(git rev-parse --show-toplevel) | |
EXIT=0 | |
# Definitely NSFW | |
WORD_FILE_URL="http://www.bannedwordlist.com/lists/swearWords.csv" | |
WORD_FILE_PATH=~/.swearwords.csv | |
if [ ! -f $WORD_FILE_PATH ]; then | |
wget -q --header="User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11" --header="Referer: https://google/" -O - "$WORD_FILE_URL" | tr , '|' > $WORD_FILE_PATH | |
fi | |
PATTERN="$(cat $WORD_FILE_PATH)" | |
for file in $(git diff --cached --name-only --diff-filter=ACM); do | |
if egrep -Hin "$PATTERN" $file; then | |
EXIT=1 | |
fi | |
done | |
exit $EXIT |
@zilahir I wrote this almost 6 years ago. I have no idea why I did it. It probably didn't work with the default wget user agent.
@skwashd haha no worries! I came across this thingy on twitter, and this question raised. :) good work though!
@zilahir now I'm curious how it ended up in a twitter discussion. Can you please link me to the thread?
thanks you @skwashd it helped me a lot ! https://gist.github.com/62mkv/394357262058b75c71c9a31c75a08d2b#file-stop-word-for-commits-md
I added multi-language support and example to use with https://pre-commit.com/ here https://gist.github.com/pmoranga/c6997d08fa1e7b51625bf532ca1c603e
Helpful to make sure that debug print statements don't end up in commits.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why are you passing
User-Agent
?