Last active
September 18, 2024 09:27
-
-
Save gelin/36a6eb9f0001ded501cabe29ff61a1be to your computer and use it in GitHub Desktop.
Git hook to put Jira issue ID from branch name to commit 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 | |
# Hook automatically adds Jira issue ID to the commit message | |
# from the branch name. | |
# For example, if you're working in a branch `JIRA-123_something`, | |
# each commit message will be prepended with `JIRA-123 `. | |
# Copy this file as `$YOUR_GIT_REPO/.git/hooks/commit-msg` and make it executable. | |
TICKETS=$(git rev-parse --abbrev-ref HEAD | grep -Eo '[A-Z]+-[0-9]+' | tac) | |
#echo "$TICKETS" | |
for TICKET in $TICKETS | |
do | |
#echo $TICKET | |
sed -i "1s/^/$TICKET /" $1 | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment