Format git commit to include the JIRA ticket

PHOTO EMBED

Tue Aug 24 2021 06:38:20 GMT+0000 (Coordinated Universal Time)

Saved by @codeplay

#!/bin/sh

# Save this snipped in both: .git/hooks/prepare-commit-msg and .git/hooks/commit-msg
# Make it executable: chmod u+x .git/hooks/prepare-commit-msg .git/hooks/commit-msg

COMMIT_MSG_FILE=$1

if ! grep -v "^\s*[#;]" $COMMIT_MSG_FILE | grep -Eq 'PP-[0-9]{4,5}\b'; then
    BRANCH=$(git branch | grep '*' | sed 's/* //')
    TICKET="$(echo ${BRANCH} | cut -d'-' -f1)-$(echo ${BRANCH} | cut -d'-' -f2)"
    echo "[$TICKET] $(cat $COMMIT_MSG_FILE)" > $COMMIT_MSG_FILE
fi
content_copyCOPY