Last active
December 21, 2015 02:38
-
-
Save efuquen/6235987 to your computer and use it in GitHub Desktop.
Will prepend a git commit with a user story number, which conforms to the regex "US[0-9][0-9]*", *if* the currently checked out branch ends in the user story. For example, a branch called "some-branch-name-US1234" will have all git commits starting with "US1234 - Some git commit message here". If you are in a branch that does not end in User Sto…
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/bash | |
CURRENT_BRANCH="$(git symbolic-ref HEAD | awk -F '\/' '{ print $NF }')" | |
if [[ $CURRENT_BRANCH =~ ^.*US[0-9][0-9]*$ ]]; then | |
STORY_ID="$(echo $CURRENT_BRANCH | sed 's/^.*\(US[0-9][0-9]*\)$/\1/')" | |
cat $1 | awk '{if(NR == 1) { print "'${STORY_ID}' -",$0 } else { print $0 } }' > $1.tmp | |
mv $1.tmp $1 | |
fi |
Clarification:
Make sure the file is executable
chmod 755 .git/hooks/prepare-commit-msg
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation:
Copy and paste the below snippet into the following git hook file:
.git/hooks/prepare-commit-msg