Last active
December 10, 2021 16:35
-
-
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 …
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 | |
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