add git hooks

This commit is contained in:
Andreas Zweili 2021-11-16 15:31:36 +01:00
parent 218d12deb7
commit fbabc9a415
1 changed files with 18 additions and 0 deletions

View File

@ -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