Thankfully git has a tool to help you get these things consistent. Its called the "prepare-commit-msg hook"
I wrote a little python script to make a default commit message. Its not perfect but it should help... It takes the branch name, searches for a version tag and removes it, then searches for anything that might be a ticket id and adds it to the message. Finally it adds some boilerplate.
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
import sys | |
import subprocess | |
import re | |
# A normal commit will just have two arguments, this filename and the filename | |
# of the commit message we want to change. Any other kind of commit we'll be | |
# cowardly about and just leave as is. | |
if len(sys.argv)!=2 : | |
sys.exit(0) | |
f = open( sys.argv[1], "r" ) | |
lines = f.readlines(); | |
f.close() | |
# get the branch name | |
proc = subprocess.Popen(["git", "symbolic-ref", "HEAD"], stdout=subprocess.PIPE) | |
(branch_name,err) = proc.communicate() | |
branch_name = branch_name.strip() | |
#strip out version tags | |
branch_name = re.sub(r'v\d+\.\d+','', branch_name) | |
tickets= ",".join( [ ("#"+x) for x in re.split(r'\D+',branch_name) if x != '' ] ) | |
if tickets == "" : | |
tickets= "#xxx" | |
f = open( sys.argv[1], "w" ) | |
f.write("[%s] short message\n" %tickets) | |
f.write("\n") | |
f.write("longer message.\n") | |
f.write(" - bullet 1\n") | |
f.write(" - bullet 2\n") | |
f.writelines(lines) | |
sys.exit(0) |