Last active
November 6, 2018 18:15
-
-
Save erikvdwal/e04153bc5682d287a2c47c4d02979de7 to your computer and use it in GitHub Desktop.
Git hook to automatically prepend Jira ticket id to commit
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 | |
COMMIT_FILE=$1 | |
COMMIT_MSG=$(cat $1) | |
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
JIRA_ID=$(echo "$CURRENT_BRANCH" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+") | |
IN_COMMIT=$(grep -c "$JIRA_ID:" $1) | |
if ! [[ $IN_COMMIT -ge 1 ]] && [ ! -z "$JIRA_ID" ]; then | |
echo "$JIRA_ID: $COMMIT_MSG" > $COMMIT_FILE | |
echo "JIRA ID '$JIRA_ID' matched in current branch name, prepended to commit message. (Use --no-verify to skip)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions on how to enable this globally can be found here: https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook