Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 53 lines (41 sloc) 1.32 KB
#!/usr/bin/bash
# De minimus non curat lex.
# Script to check that every time you blog, you use
# one of the words that certain people don't want to
# see. This does not require that all files contain
# a forbidden word, just that each commit that
# modifies a blog entry touches at least one file
# containing a forbidden word.
# Runs as a Git pre-commit hook. Install as:
# .git/hooks/pre-commit
# Make sure to make it executable.
# list of forbidden words
forbidden=(vulnerable entitlement diversity transgender fetus evidence-based science-based)
# File extension for blog entries. Change if you use a
# different one. Don't include the "."
blog_extension='md'
# More info: https://blog.zgp.org/forbidden-words/
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# return success by default if no blog entries changed
result=0
for filename in $(git diff-index --name-only --cached $against --); do
basename=$(basename "$filename")
extension="${basename##*.}"
if [[ $extension != $blog_extension ]] ; then
continue
fi
result=1
for word in ${forbidden[@]}; do
grep -wq $word $filename && exit 0
done
done
if [ $result ]; then
echo "Use more forbidden words."
fi
exit $result