Git recommit hook for adding meta information to commit message

Hi,
I am repeatedly annoyed with the fact, that i have to remember the issue id for which i am making a commit, and add it as part of the commit message. To do something about it i wrote a small commit message hook to automate the process. So here is how it works.

Whenever i create a branch to work on something in Git, i create it with the issue number as follows (bugfix|feature) followed by '/' followed by 'bug id' and some description about the bug.So i thought i will use this information to automatically populate my git commit message with a valid ID. A valid ID here is the one that is actually an issue that exists in the issue database. (JIRA my case), and if it's valid commit the message. Else abort the commit process altogether. So here is the script to do it

#!/bin/sh

#List all branches, get the one that starts with * and pick it and display it
BRANCH=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/')
BUG='CCM-'$(echo $BRANCH | awk '{split($0,l,"-"); print l[2]}')
URL='https://workflow.advisory.com/browse/'$BUG
if $(curl --output /dev/null --verbose --head --fail $URL); then
  echo $BUG ':' $(cat "$1") > "$1"
else
  exit 1
fi

When you have wrote this script copy it to your repository's .git/hooks folder with the name prepare-commit-msg. The name is very important. Also if you have any previous files in this name delete them.

Have a good time with GIT.

soundararajan