Created
November 25, 2020 01:06
-
-
Save tlightsky/6c541c48f31f45c46764836e21c9418c to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Get the current branch name | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
# Get the JIRA number | |
JIRA=$(echo $BRANCH_NAME | grep -o -E '[0-9A-Z]+-[0-9]+') | |
#Check if this a normal commit, or an amend | |
IS_NORMAL_COMMIT=$(grep -c "$JIRA" $1) | |
# Prepend the JIRA number to the commit message | |
if [ -n "$JIRA" ] && [ "$IS_NORMAL_COMMIT" -eq 0 ]; then | |
sed -i.bak -e "1s/^/$JIRA /" $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment