Created
June 30, 2021 21:03
-
-
Save bozydar/75dc194b43eca3dcf7cac858ec8d5f89 to your computer and use it in GitHub Desktop.
Git hook parsing a branch name to get jira number and putting into message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MSG_FILE=$1 | |
branch_name=`git rev-parse --abbrev-ref HEAD` | |
issue_id=`echo ${branch_name} | grep -o "[0-9]\{4\}"` | |
# message=`echo ${branch_name} | sed -e 's/[-_]/ /g' -e 's/[0-9]\{4\}//g' -e 's/^[ \t]*//;s/[ \t]*$//'` | |
# remove all the strings between square brackets | |
sed -e "s/\[[^]]*]//g" -e 's/^[ \t]*//;s/[ \t]*$//' -i '' $MSG_FILE | |
if ! [[ -z ${issue_id} ]]; then | |
sed -e "1s/./[${issue_id}] &/" -i '' $MSG_FILE | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put it into
.git/hooks
and make executable withchmod a+x .git/hooks/prepare-commit-msg