Created
February 11, 2021 20:23
-
-
Save minamaged113/31e8dff7f66785f8d4ee36c587aae8d1 to your computer and use it in GitHub Desktop.
git hook to edit commit message
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/bash | |
# git hook to add ticket number from branch name | |
# branch names should have the following naming | |
# convention for this to work: | |
# <type>/<ticket-handle-without-hashes>-<ticket-title> | |
BRANCH_NAME="$(git rev-parse --abbrev-ref HEAD)" | |
COMMIT_MSG=$(cat "$1") | |
TICKET_NO_FROM_BRANCH_NAME=$(echo $BRANCH_NAME | cut -d "/" -f 2 | cut -d "-" -f 1) | |
grep -qs "^$TICKET_NO_FROM_BRANCH_NAME" "$1" || echo "[$TICKET_NO_FROM_BRANCH_NAME] $(cat "$1")" > "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment