Last active
May 14, 2020 05:02
-
-
Save konstantindenerz/9c0cd960f9dd86fd6a1decdf6b98631b to your computer and use it in GitHub Desktop.
Use git hook to assign issue 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 | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
ISSUE_ID=$(echo $BRANCH_NAME | grep -o '[M|m][F\|f]-[0-9]*') | |
if [ -n "$ISSUE_ID" ]; then | |
sed -i.bak -e "1s/$/ [$ISSUE_ID]/" $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Place the file in
/myproject/.git/hooks
folder and make it executablechmod +x /myproject/.git/hooks/prepare-commit-msg
.Sample
branch name:
feature/MF-42-bubu
commit message (before):
foobar
commit message (after):
foobar [MF-42]