Last active
December 30, 2015 23:59
-
-
Save ross-nordstrom/7904007 to your computer and use it in GitHub Desktop.
This goes in `.git/hooks/prepare-commit-msg`. Be sure to chmod +x it. It adds the user story id to every commit based on branch name. Intended for Pivotal tracker, but can be modified for other syntaxes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Automatically add branch name and branch description to every commit message except merge commit. | |
# Prefix commit messages with "[US1234]: "" | |
# | |
COMMIT_EDITMSG=$1 | |
addBranchName() { | |
branchPath=$(git symbolic-ref -q HEAD) | |
branchName=${branchPath##*/} | |
branchId=`expr match "$branchName" '\([a-zA-Z]*[0-9]*\)'` | |
# remove any existing entries of the branch id | |
COMMIT_EDITMSG=${COMMIT_EDITMSG##*]:} | |
echo "[$branchId]: $(cat $COMMIT_EDITMSG)" > $COMMIT_EDITMSG | |
} | |
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
What should the branch name look like then?