Created
March 1, 2018 15:20
-
-
Save noahp/25b1a2a8d13f3a071d9cc3ed4d634295 to your computer and use it in GitHub Desktop.
Grab jira ticket from current branch and prefix commit message with it; .git/hooks/prepare-commit-msg
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
#!/usr/bin/env bash | |
# Try to yank the JIRA ticket number from the current branch and prefix the commit message with it | |
EXISTING_PREFIX=$(rg -e "[a-zA-Z]+-[0-9]+" $1) | |
if [[ ! -z $EXISTING_PREFIX ]]; then | |
exit | |
fi | |
JIRA_TICKET=$(git symbolic-ref --short HEAD | rg -o -e "[a-zA-Z]+-[0-9]+" | awk '{print toupper($0)": "}') | |
sed -i.bak -e "1s/^/$JIRA_TICKET/" $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment