Read more

Bash script to list commits by Pivotal Tracker ID

Michael Leimstädtner
September 18, 2019Software engineer at makandra GmbH

The main benefit of our convention to prefix commits by their corresponding Pivotal Tracker ID is that we can easily detect commits that belong to the same story. You can either do that manually or use the bash script below by copying it somewhere to your .bashrc.

# Usage: ptcommits 123456
function ptcommits {
  if test "$1"
  then
    local PTID=$(echo "$1" | grep "[0-9]*" -o) # Allow URLs
    git log --oneline | grep "$PTID" | grep "^[a-z0-9]*" -o | xargs --no-run-if-empty git show $2 $3 $4
  else
    echo "Please specify a Pivotal Tracker story ID"
  fi
}

alias ptcommit='ptcommits'
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

Now you can use use the command like this: ptcommits 165086636 --stat. Up to three arguments are passed to git show. Example output:

commit 048054b1df87576f7c59cc0161cc331c44d2ea6b
Author: Foo Bar <foo@bar.com>
Date:   Fri Apr 5 14:24:24 2019 +0200

    [#165086636] My Pivotal Tracker Title

 app/assets/javascripts/test.js.coffee | 22 ++++++++++++++++++++++
 app/models/test.rb                    | 30 ++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)

Caveats

  • ptcommits #<STORY_ID> does not work, since your shell with ignore STORY_ID (it is marked as a comment). Use ptcommits '#<STORY_ID>' instead.

See also

Posted by Michael Leimstädtner to makandra dev (2019-09-18 11:06)