Skip to content

Instantly share code, notes, and snippets.

@john-humi
Created December 14, 2020 19:26
Show Gist options
  • Select an option

  • Save john-humi/f1479514e7ced759ea95a478abb2911e to your computer and use it in GitHub Desktop.

Select an option

Save john-humi/f1479514e7ced759ea95a478abb2911e to your computer and use it in GitHub Desktop.
#!/bin/sh
# Checks if current branch matches JIRA pattern (ABC-1234-anything), then adds ABC-1234 to start of commit message.
BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *')
REGEX='^([a-zA-Z]{3}-[0-9]+)-*'
if [ -n "$BRANCH_NAME" ]; then
[[ $BRANCH_NAME =~ $REGEX ]]
if [ -n "$BASH_REMATCH" ]; then
echo "${BASH_REMATCH[1]} $(cat $1)" > $1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment