- Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprepare-commit-msg.sample
More file actions
Latest commit
13 lines (11 loc) · 526 Bytes
/
Copy pathprepare-commit-msg.sample
File metadata and controls
13 lines (11 loc) · 526 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
# Reference :https://medium.com/better-programming/how-to-automatically-add-the-ticket-number-in-git-commit-message-bda5426ded05
# Reference :https://gist.github.com/bartoszmajsak/1396344
#!/bin/bash
FILE=$1
MESSAGE=$(cat $FILE)
#BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')
TICKET=[$(git rev-parse --abbrev-ref HEAD | grep -Eo '^(\w+/)?(\w+[-_])?[0-9]+' | grep -Eo '(\w+[-])?[0-9]+' | tr "[:lower:]" "[:upper:]")]
if [[ $TICKET == "[]" || "$MESSAGE" == "$TICKET"* ]];then
exit 0;
fi
echo "$TICKET $MESSAGE" > $FILE