Last active
August 2, 2025 12:49
-
-
Save devtrillo/04cf1b8e5360a1ac88c176ae0abbb03e to your computer and use it in GitHub Desktop.
Custom git commit messages based on pivotal tracker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
COMMIT_MSG_FILE=$1 | |
COMMIT_SOURCE=$2 | |
SHA1=$3 | |
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE") | |
if [ -z "$BRANCHES_TO_SKIP" ]; then | |
BRANCHES_TO_SKIP=(master develop main) | |
fi | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
TICKET_NAME=$(echo $BRANCH_NAME | grep -Eo "\d{1,10}") | |
echo $TICKET_NAME | |
if [[ -z "$TICKET_NAME" ]]; then | |
echo "There is no ticket number in the branch, keeping the default one" | |
exit 0 | |
fi | |
if [[ -z "$COMMIT_SOURCE" ]]; then | |
# There is NO message in the commit | |
echo "[#${TICKET_NAME}] "> "$COMMIT_MSG_FILE" | |
echo "$COMMIT_MSG" >> "$COMMIT_MSG_FILE" | |
exit 0 | |
else | |
# There is a message in the commit | |
if echo "$COMMIG_MSG" | grep -q "[#\w{9}]";then | |
echo "There is a ticket number in the commit message" | |
echo "Proceeding without modifying the commit message..." | |
exit 0 | |
else | |
echo "The commit does not have a ticket number" | |
echo "Adding it based on the branch name" | |
echo "[#${TICKET_NAME}] ${COMMIT_MSG}" > "$COMMIT_MSG_FILE" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment