Skip to content

Instantly share code, notes, and snippets.

@monkseal
Created May 6, 2015 17:51
Show Gist options
  • Save monkseal/970b981570fc5b72da41 to your computer and use it in GitHub Desktop.
Save monkseal/970b981570fc5b72da41 to your computer and use it in GitHub Desktop.
'commit-msg' hook that pulls your Jira issue number from your branch name
#!/bin/sh
# Add git branch if relevant
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# Extact tracker abbreviation and ticket number (e.g. DS-123)
parse_git_tracker_and_ticket() {
parse_git_branch | grep -e '[A-Z]\+-[0-9]\+' -o
}
MESSAGE="$(cat $1)"
TICKET=`parse_git_tracker_and_ticket`
if [ -n "$TICKET" ]
then
echo "New commit message: [$TICKET] $MESSAGE"
echo "[$TICKET] $MESSAGE" > $1
fi
@bitti
Copy link

bitti commented Jan 10, 2017

For this purpose the prepare-commit-msg hook should be used. 1. It allows editing of the ID if necessary. 2. Also avoids the problems with amend etc.

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