#!/bin/bash

# Link https://confluentinc.atlassian.net/wiki/spaces/CPFundamentals/pages/3242428764/Commit+Format
# This commit msg hook would rename your commit msg to include the jira id present in branch post "-"
# The suffix of the branch name must be -<Jira Ticket Number>
BRANCH_NAME=`git symbolic-ref --short HEAD`

if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then
        PREFIX=`echo $BRANCH_NAME | sed  -e 's:.*-\([^-]*-\(.*\)\)$:\1:'`
        sed -i.bak -e "1s/^/[$PREFIX] \| /" $1
fi
