Auto prepend a JIRA ticket number to your commit messages

To ensure commit messages contain the JIRA ticket, in the following format:

ABC-1234 : [your commit message here]

You can have this prepended automatically by creating `.git/hooks/prewpare-commit-msg`, with the following code:

#!/bin/sh
COMMIT_MSG_FILE=$1
branch=$(git branch --show-current)
issue=$(sed -e 's/.*\/\([A-Z]\{3\}-[0-9]\{4\}\)\/.*/\1/' <<< $branch)

if [[ $issue =~ [A-Z]{3}-[0-9]{4} ]]; then
originalText=$(cat "$COMMIT_MSG_FILE")
echo "$issue : " > "$COMMIT_MSG_FILE"
echo "$originalText" >> "$COMMIT_MSG_FILE"
fi

After creating the file, run `chmod +x .git/hooks/prepare-commit-msg` to make it executable.

You should also have a `commit-msg` hook to check with regex that the first line contains more than just the ticket
[A-Z]{3}-[0-9]{4}\s:\s(.*). Exit with a non zero status if the regex fails

In my case I am using GrumPHP to manage the commit-msg hook. GrumPHP has a JIRA ticket task, which we can set up in the yaml file like so:

  tasks:
    git_commit_message:
      matchers:
        Must contain JIRA issue number: '/[A-Z]{3}-[0-9]{4} : (.+)/'