Skip to content

Instantly share code, notes, and snippets.

@bradparker
Last active May 31, 2019 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradparker/d8ad5c1554a600109e9ccc3318b912b7 to your computer and use it in GitHub Desktop.
Save bradparker/d8ad5c1554a600109e9ccc3318b912b7 to your computer and use it in GitHub Desktop.
Git Hook to prepend a commit message with the Jira ticket id at the start of the current branch's name
#!/usr/bin/env bash
branchname=$(git branch | grep ^* | sed 's/\* //g')
regex="([A-Z]*-[0-9]*)"
if [[ $branchname =~ $regex ]]
then
ticket_id="${BASH_REMATCH[1]}"
message=`cat $1`
if [[ $message == $ticket_id* ]] || [[ $message == "fixup! "* ]]
then
exit
fi
echo "$ticket_id $message" > $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment