Last active
March 2, 2022 16:29
-
-
Save trylix/38e43750deedf3d83f13e6392904aed1 to your computer and use it in GitHub Desktop.
git prepare-commit-msg hook for automatically prepending an issue key from the start of the current branch name to commit messages.
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 | |
| # check if commit is merge commit or a commit ammend | |
| if [ $2 = "merge" ] || [ $2 = "commit" ]; then | |
| exit | |
| fi | |
| ISSUE_KEY=`git branch | grep -o "\* \(.*/\)*[A-Z]\{2,\}-[0-9]\+" | grep -o "[A-Z]\{2,\}-[0-9]\+"` | |
| if [ $? -ne 0 ]; then | |
| # no issue key in branch, use the default message | |
| exit | |
| fi | |
| # issue key matched from branch prefix, prepend to commit message | |
| sed -i -e "1s/^/$ISSUE_KEY /" $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment