JIRA code validation commit hook for 'git'

Andrew picture Andrew · Oct 1, 2009 · Viewed 11.2k times · Source

Does anyone have a git commit hook I can use that will ensure a JIRA issue number appears in the checkin message? I've got no experience driving JIRA from a git commit hook so any help would be appreciated -- working source even more so!

Answer

Nicolas picture Nicolas · Dec 11, 2009

First, make the hook executable:

chmod a+x .git/hooks/commit-msg

Append the following lines, substituting PROJECT with your project's code.

test "" != "$(grep 'PROJECT-' "$1")" || {
        echo >&2 "ERROR: Commit message is missing Jira issue number."
        exit 1
}