Skip to content

Instantly share code, notes, and snippets.

@jbueza
Created March 4, 2014 18:30
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 jbueza/9352607 to your computer and use it in GitHub Desktop.
Save jbueza/9352607 to your computer and use it in GitHub Desktop.
Automatically add branch name and branch description to every commit message except merge commit.
#!/bin/sh
#
# Automatically add branch name and branch description to every commit message except merge commit.
#
COMMIT_EDITMSG=$1
addBranchName() {
NAME=$(git branch | grep '*' | sed 's/* //')
DESCRIPTION=$(git config branch."$NAME".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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment