Bash script to list commits by Pivotal Tracker ID

Updated . Posted . Visible to the public. Deprecated.

New script for Linear: https://makandracards.com/makandra/621150-bash-script-to-list-commits-by-linear-id

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'

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

Michael Leimstädtner
Last edit
Michael Leimstädtner
Keywords
bookmarklet
License
Source code in this card is licensed under the MIT License.
Posted by Michael Leimstädtner to makandra dev (2019-09-18 09:06)