Skip to content

Instantly share code, notes, and snippets.

@efuquen
Last active December 21, 2015 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efuquen/6235987 to your computer and use it in GitHub Desktop.
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…
#!/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
@efuquen
Copy link
Author

efuquen commented Aug 14, 2013

Installation:

Copy and paste the below snippet into the following git hook file:

.git/hooks/prepare-commit-msg

@efuquen
Copy link
Author

efuquen commented Sep 12, 2013

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