Last active
March 26, 2018 19:20
-
-
Save serhalp/4426b317cbe39b456c12 to your computer and use it in GitHub Desktop.
Pre-populate Git commit message with current branch's Pivotal Tracker story ID
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 | |
TMP=`git rev-parse --abbrev-ref HEAD | grep -o '[-_]\d\+$'` | |
STORY_ID=${TMP:1} | |
if [[ ! -z $STORY_ID ]] | |
then | |
ORIG_MSG_FILE="$1" | |
ORIG_MSG=`cat $1` | |
(echo "[#$STORY_ID]") > "$ORIG_MSG_FILE" | |
(echo "$ORIG_MSG") >> "$ORIG_MSG_FILE" | |
fi |
This does not work on several account, I suggest using the second parameter to not clobber other commit messages like merge and etc.
Also there's another thing that I do not yet have a solution, if you do not edit the message git will not detect that it has not changed. It will simply use your edited version.
task="$CURRENT_TASK"
url="$CURRENT_TASK_URL"
if [[ "$task" != "" && ( "$2" == "" || "$2" == "template" ) ]]; then
printf "%s:\n\nissue: %s\n\n%s" "${task}" "${url}" "$(cat - "$1")" > "$1"
fi
That is my version
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So awesome! Thanks Phil =)