Skip to content

Instantly share code, notes, and snippets.

@brew
Last active August 29, 2015 14:07
Show Gist options
  • Save brew/58765b650be600da3556 to your computer and use it in GitHub Desktop.
Save brew/58765b650be600da3556 to your computer and use it in GitHub Desktop.
Prepend issue number (from branch name) to commit message
#!/bin/sh
#
# Automatically add branch name and branch description to every commit message
# except merge commit.
#
COMMIT_EDITMSG=$1
addBranchName() {
BRANCH_NAME=$(git symbolic-ref --short HEAD)
STORY_NUMBER=$(echo $BRANCH_NAME | sed -n 's/^\([0-9]*\)-.*/\1/p')
if [ $STORY_NUMBER ] ; then
echo "[#$STORY_NUMBER] $(cat $COMMIT_EDITMSG)" > $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