Skip to content

Instantly share code, notes, and snippets.

@annacruz
Created March 23, 2022 06:44
Show Gist options
  • Save annacruz/7172dc5a356167b76199602933f36767 to your computer and use it in GitHub Desktop.
Save annacruz/7172dc5a356167b76199602933f36767 to your computer and use it in GitHub Desktop.
git hook to put the ticket number in the commit messages automatically
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