Skip to content

Instantly share code, notes, and snippets.

@the-glima
Forked from bartoszmajsak/prepare-commit-msg.sh
Last active July 17, 2020 15:09
Show Gist options
  • Save the-glima/ccca711a04e5e9951b1a to your computer and use it in GitHub Desktop.
Save the-glima/ccca711a04e5e9951b1a to your computer and use it in GitHub Desktop.
Prepend branch name into commit message
#!/bin/bash
FILE=$1
MESSAGE=$(cat $FILE)
TICKET=$(git rev-parse --abbrev-ref HEAD | grep -Eo '^(\w+\/)?(\w+[-_])?[0-9]+' | grep -Eo '(\w+[-])?[0-9]+' | tr "[:lower:]" "[:upper:]")
if [[ $TICKET == "" || "$MESSAGE" == "$TICKET"* ]];then
exit 0;
fi
echo "$TICKET: $MESSAGE" > $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment