This git hook extracts the number from a branch and adds it to the commit message as refs. i.e.:
From a branch named whatever-branch-name-5234 will create a commit message like this:
refs #5234
# git COMMIT_MSG commentsThis git hook extracts the number from a branch and adds it to the commit message as refs. i.e.:
From a branch named whatever-branch-name-5234 will create a commit message like this:
refs #5234
# git COMMIT_MSG comments| #!/bin/bash | |
| BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
| BRANCH_NAME="${BRANCH_NAME##*/}" | |
| ISSUE_ID=$(echo $BRANCH_NAME | sed 's/^[a-z\-]*-//I') | |
| IS_NUMBER='^[0-9]+$' | |
| if [ -n "$BRANCH_NAME" ] && [[ $ISSUE_ID =~ $IS_NUMBER ]]; then | |
| sed -i.bak -e "1s/^/\n\nrefs #$ISSUE_ID /" $1 | |
| fi |