Skip to content

Instantly share code, notes, and snippets.

@rberrelleza
Created December 9, 2014 21:49
Show Gist options
  • Save rberrelleza/1fafc9acd7f226e779eb to your computer and use it in GitHub Desktop.
Save rberrelleza/1fafc9acd7f226e779eb to your computer and use it in GitHub Desktop.
Git hook to append issue name to a commit
#!/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 merge commit
if [ $2 = "merge" ]; then
exit
fi
ISSUE_KEY=`git branch | grep -o "\* \(.*/\)*[A-Z]\{2,\}-[0-9]\+" | grep -o "[A-Z]\{2,\}-[0-9]\+"`
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment