Skip to content

Instantly share code, notes, and snippets.

@isRuslan
Last active March 20, 2017 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isRuslan/8deabca8d41d14fbcae4837fb802e635 to your computer and use it in GitHub Desktop.
Save isRuslan/8deabca8d41d14fbcae4837fb802e635 to your computer and use it in GitHub Desktop.
.git/hooks/commit-msg
#!/bin/sh
#
# Automatically add branch name and branch description to every commit message except merge commit.
#
COMMIT_EDITMSG=$1
addBranchName() {
BRANCH=$(git branch | grep '*' | sed 's/* //')
NAME=$(echo "$BRANCH" | sed -E 's/([A-Z]+-[0-9]+(--[A-Z]+-[0-9]+)?).*/\1/')
DESCRIPTION=$(git config branch."$BRANCH".description)
echo "$NAME: $(cat $COMMIT_EDITMSG)" > $COMMIT_EDITMSG
if [ -n "$DESCRIPTION" ]
then
echo "" >> $COMMIT_EDITMSG
echo $DESCRIPTION >> $COMMIT_EDITMSG
fi
}
MERGE=$(cat $COMMIT_EDITMSG|grep -i 'merge'|wc -l)
if [ $MERGE -eq 0 ] ; then
addBranchName
fi
echo "v4" >> $COMMIT_EDITMSG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment