Skip to content

Instantly share code, notes, and snippets.

@tlightsky
Created November 25, 2020 01:06
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 tlightsky/6c541c48f31f45c46764836e21c9418c to your computer and use it in GitHub Desktop.
Save tlightsky/6c541c48f31f45c46764836e21c9418c to your computer and use it in GitHub Desktop.
prepare-commit-msg
#!/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