Skip to content

Instantly share code, notes, and snippets.

@serhalp
Last active March 26, 2018 19:20
Show Gist options
  • Save serhalp/4426b317cbe39b456c12 to your computer and use it in GitHub Desktop.
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
#!/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
@hazeledmands
Copy link

So awesome! Thanks Phil =)

@bogado
Copy link

bogado commented Mar 26, 2018

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.

@bogado
Copy link

bogado commented Mar 26, 2018

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