Skip to content

Instantly share code, notes, and snippets.

@gitaarik
Last active December 10, 2021 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gitaarik/5990889 to your computer and use it in GitHub Desktop.
Save gitaarik/5990889 to your computer and use it in GitHub Desktop.
Pre-commit git-hook that looks for misspelled words and if found notifies the committer about them and aborts the commit. I made it because some developers in my team misspelled classnames/methodnames/variables, and the misspellings kept coming back after they were fixed. This will prevent some misspellings from entering the repository. You can …
#!/bin/bash
declare -a words=(resourse initialise construkt)
declare -a misspellings
i=0
for word in ${words[@]}
do
if [[ $(git diff --cached -S "$word" | grep -i "$word" | wc -l | sed 's/[^0-9]//g') > 0 ]]
then
misspellings[i]=$word
i=`echo $i+1 | bc`
fi
done
if [[ "$i" > 0 ]]
then
echo "You misspelled some words:"
for word in ${misspellings[@]}
do
echo " $word"
done
echo "Please correct them before you commit."
echo "You can run 'git diff' to find out where the misspellings are located."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment