From 95508ad284ddcddb7430107fb4e19161ba4d903a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Fri, 12 Jun 2020 19:47:58 +0200 Subject: [PATCH] MAPG-129 add prepare-commit-msg hook template --- scripts/gitHooks/prepare-commit-msg | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 scripts/gitHooks/prepare-commit-msg diff --git a/scripts/gitHooks/prepare-commit-msg b/scripts/gitHooks/prepare-commit-msg new file mode 100755 index 0000000..6d109a7 --- /dev/null +++ b/scripts/gitHooks/prepare-commit-msg @@ -0,0 +1,15 @@ +#!/bin/bash + +BRANCH_NAME=$(git symbolic-ref --short HEAD) +BRANCH_PATTERN="^(bugfix|feature|hotfix)\/([A-Z]+-[0-9]+).*" + +if [[ "${BRANCH_NAME}" =~ $BRANCH_PATTERN ]]; then + TICKET_ID=$(echo $BRANCH_NAME | sed -E "s@$BRANCH_PATTERN@\\2@") + + COMMIT_MESSAGE=$(head -n 1 $1) + COMMIT_MESSAGE_REGEX="^$TICKET_ID .*" + + if [[ ! "${COMMIT_MESSAGE}" =~ $COMMIT_MESSAGE_REGEX ]]; then + sed -i.bak -e "1s/^/$TICKET_ID /" $1 + fi +fi