Skip to content

Instantly share code, notes, and snippets.

@onnimonni
Last active April 6, 2017 13:53
Show Gist options
  • Save onnimonni/b485479c202b082c032e to your computer and use it in GitHub Desktop.
Save onnimonni/b485479c202b082c032e to your computer and use it in GitHub Desktop.
Git prepare commit message hook
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
#
##
# Installation on OSX:
# $ brew install aspell
# Then add Your custom word list to home folder
# The first line needs to be personal_ws-1.1 en 0
# $ nano ~/.aspell.en.pws
#
# For example:
#
# personal_ws-1.1 en 0
# json
# wordpress
# Facebook
# vagrant
# vagrantfile
# ansible
#
##
# aspell has no idea of git hashes so remove them from spellchecking
MESSAGE=$(cat "$1")
HASHES=$(git rev-list --all)
while read -r line; do
MESSAGE=$(echo $MESSAGE | sed "s/$line//g")
done <<< "$HASHES"
# Spell check commit message
TYPOS=$(echo $MESSAGE | aspell list -d en_US)
if [ -n "$TYPOS" ]; then
echo -e "ERROR: spell check failed on words: \n$TYPOS"
echo "Edit ~/.aspell.en.pws to accept more words"
echo "SKIP THIS: git commit -nm '$(cat "$1")'"
exit 1
fi
# Get commit message
commit_msg=$(cat "$1")
# Capitalize first letter
commit_msg_capitalize="$(tr '[:lower:]' '[:upper:]' <<< ${commit_msg:0:1})${commit_msg:1}"
echo "$commit_msg_capitalize" > "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment