2021-12-08 09:47:04 +01:00
|
|
|
#!/usr/bin/env bash
|
2021-11-16 15:31:36 +01:00
|
|
|
|
|
|
|
# This hook works for branches named such as "123-description" and will add "[#123]" to the commit message.
|
|
|
|
|
|
|
|
# get current branch
|
|
|
|
branchName=`git rev-parse --abbrev-ref HEAD`
|
|
|
|
|
|
|
|
# search issue id in the branch name, such a "123-description" or "XXX-123-description"
|
|
|
|
issueId=$(echo $branchName | sed -nE 's,([A-Z]?-?[0-9]+)-.+,\1,p')
|
|
|
|
|
|
|
|
# only prepare commit message if pattern matched and issue id was found
|
|
|
|
if [[ ! -z $issueId ]]; then
|
|
|
|
# $1 is the name of the file containing the commit message
|
|
|
|
# sed -i.bak -e "1s/^/\n\n[$issueId]\n/" $1
|
2022-11-09 11:50:37 +01:00
|
|
|
echo -e "[#$issueId] ""$(cat $1)" > "$1"
|
2021-11-16 15:31:36 +01:00
|
|
|
# echo -e "[$issueId]\n""$(cat $1)" > "$1"
|
|
|
|
# sed -i.bak -e "1s/^/$TRIMMED /" $1
|
|
|
|
fi
|