Last active
August 29, 2015 14:05
-
-
Save axxapy/2062b1faea3c1db93d0b to your computer and use it in GitHub Desktop.
Git hook which adds ticket number extracted from branch name (like TICKET-123_comment) to every 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/bash | |
# | |
# This hook adds ticket number from branch name to every commit message | |
# | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
MSG=$(head -n 1 $1) | |
[[ -z "$BRANCH_NAME" ]] && exit 0 | |
if [ "$BRANCH_NAME" = "master" ]; then | |
APPEND="[master] " | |
else | |
TICKET=`echo "$BRANCH_NAME" | sed 's/\([A-Z]\+-[0-9]\+\|build\).*/\1/'` | |
[ -z "$TICKET" -o "$TICKET" = "$BRANCH_NAME" ] && exit 0 | |
APPEND="[$TICKET] " | |
fi | |
[[ "${MSG:0:${#APPEND}}" == "$APPEND" ]] && exit 0 | |
sed -i.bak -e "1s/^/${APPEND}/" $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment