Last active
September 7, 2015 02:41
-
-
Save anton-matosov/2135acb3427feb4a4f23 to your computer and use it in GitHub Desktop.
git commit-msg hook to put JIRA ticket ID (or other ID matching pattern) in front of the message
This file contains 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 | |
# | |
# Automatically adds JIRA ticket ID based on branch name to every commit message. | |
# | |
set -x | |
MESSAGE=$(cat "$1") | |
BASEREGEX="([A-Z]{1,10}-[0-9]*)" | |
MSG_REGEX=$BASEREGEX | |
if [[ $MESSAGE =~ $MSG_REGEX ]] | |
then | |
echo branch is already in the message | |
exit | |
fi | |
BRANCH_REGEX="//?$BASEREGEX" | |
BRANCHNAME=$(git symbolic-ref -q HEAD) | |
[[ $BRANCHNAME =~ $BRANCH_REGEX ]] | |
TICKET="${BASH_REMATCH[1]}" | |
if [[ -n $TICKET ]] | |
then | |
echo "$TICKET "$(cat "$1") > "$1" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment