#!/bin/sh
#
# git prepare-commit-msg hook for automatically prepending an issue key
# from the start of the current branch name to commit messages.
# check if commit is new commit
if [ "x$2" != "x" ]; then
exit
fi
ISSUE_KEY_PATTERN="[A-Z][a-zA-Z0-9_]\{1,\}-[0-9]\+"
ISSUE_KEY=`git branch --no-color | grep -o "\* \(.*/\)*${ISSUE_KEY_PATTERN}" | grep -o "${ISSUE_KEY_PATTERN}"`
if [ $? -ne 0 ]; then
# no issue key in branch, use the default message
exit
fi
# issue key matched from branch prefix, prepend to commit message
TEMP=`mktemp /tmp/commitmsg-XXXXX`
(echo "$ISSUE_KEY: "; cat $1) > $TEMP
cat $TEMP > $1
rm $TEMP
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.