So, here is a simple script to create a Git commit message template, just place it in .git/hooks/prepare-commit-msg
and make sure it is executable.
This file contains hidden or 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
#!/usr/bin/env bash | |
commit_message=$1 | |
commit_type=$2 | |
commit_hash=$3 | |
prefix="[commit prefix]" | |
heading=$(head -1 ${commit_message}) | |
if [ -z "${heading}" ] | |
then | |
sed -i "1s/^/${prefix}: <insert heading here>\n/" ${commit_message} | |
elif [[ ${heading} != "${prefix}"* ]] | |
then | |
sed -i "1s/^.*/${prefix}: ${heading}/" ${commit_message} | |
fi | |
line_count=$(egrep -v "ChangeId|^#|^$" -c ${commit_message}) | |
if [ ${line_count} -lt 3 ] | |
then | |
sed -i '2 a<insert description here>\n' ${commit_message} | |
fi |