Created
September 2, 2025 17:45
-
-
Save tcurvelo/6714efb31cc4acd1cc974a61be33bd53 to your computer and use it in GitHub Desktop.
.git/hooks/prepare-commit-msg
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/bash | |
| # Adds the JIRA issue ID to the beginning of the commit message | |
| # if it is present in the branch name. | |
| JIRA_ISSUE_REGEX='[A-Z]{2,}-[0-9]+' | |
| BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) | |
| if [[ $BRANCH_NAME =~ $JIRA_ISSUE_REGEX ]]; then | |
| JIRA_ISSUE="${BASH_REMATCH[0]}" | |
| COMMIT_MSG_FILE=$1 | |
| if ! grep -q "$JIRA_ISSUE" "$COMMIT_MSG_FILE"; then | |
| sed -i.bak "1s/^/$JIRA_ISSUE: /" "$COMMIT_MSG_FILE" | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment