Skip to content

Instantly share code, notes, and snippets.

@bozydar
Created June 30, 2021 21:03
Show Gist options
  • Save bozydar/75dc194b43eca3dcf7cac858ec8d5f89 to your computer and use it in GitHub Desktop.
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
#!/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
@bozydar
Copy link
Author

bozydar commented Jun 30, 2021

Put it into .git/hooks and make executable with chmod a+x .git/hooks/prepare-commit-msg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment