At our company we are moving from svn to git. For issue tracking we use JIRA from Atlassian.
Now we want to enforce that every commit message contains an issue number (just like we did with svn).
We have found the commit-msg hook which we use to reject a commit if it does not contain an issue number.
JIRA uses Fisheye to scan the git repo. If a commit message contains an issue number then the changes are shown under that issue.
The problem is that a hook is not copied when a git repository is cloned. So issue numbers in the commit messages are not enforced. That means that when a new commit is pushed upstream Jira may not list the changes under an issue.
The question is; are we using Git somehow in the wrong way and is there any way to really enforce an issue number in the commit message? Or does any one have simply have a script/hook (other than the commit-msg hook) that accomplishes this?
I used git-jira-hook and modified it to my needs, which should also work for you. For your needs, just remove the parts where it logs into Jira to check if the jira issue number regexed from the commit message is valid. If you don't like python (git-jira-hook is written in python) and prefer bash, you should be able to adapt the example scripts in each repo's .git/hooks dir to your needs.
As to implementing something that will work for everyone, you want to use git-jira-hook as the 'update' hook on your upstream repos. This will block pushes that contain commit messages that lack proper jira issue references. Since it is more convenient to get feedback about missing issue references at commit time (rather than at push time), you'll need to get your developers to install git-jira-hook as their commit-msg hook. I'll explain later how this can be done globally.
Here is how I have solved this issue:
Private repo commit-msg hook: I modified git-jira-hook to check for jira issue references in the notation that we use. Then, I emailed out the hook with instructions to everyone explaining how to install the hook globally, as is explained in this SO question. If you install the hook globally then it will be used in all future clones, and can be easily applied to already cloned repos using git init.
Upstream repo update hook: I used the already modified git-jira-hook script and installed it in each of our repos. I couldn't get the interactive authentication bits working on the upstream repo (symlinked it), so I instead created a restricted permissions Jira user and hard coded their authentication into the script.