diff --git a/home/work_config/hooks/prepare-commit-msg b/home/work_config/hooks/prepare-commit-msg new file mode 100755 index 0000000..7e07df0 --- /dev/null +++ b/home/work_config/hooks/prepare-commit-msg @@ -0,0 +1,18 @@ +#!/bin/bash + +# 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 + echo -e "#$issueId ""$(cat $1)" > "$1" + # echo -e "[$issueId]\n""$(cat $1)" > "$1" + # sed -i.bak -e "1s/^/$TRIMMED /" $1 +fi