On Fri, Mar 13, 2020 at 07:39:49AM +0100, Tassilo Horn wrote:

> I'm frequently asked the question in the subject.  ABCD-12919 is some
> ticked number (yes, we use JIRA, thanks for your compassion), and
> technically the question boils down to:
> 
>   What's the first (oldest) tag on branch B from which the last commit
>   (assuming the possibility that a fix might have require multiple
>   commits) containing ABCD-12919 is reachable?
> 
> Right now, I just fire up
> 
>   git log --graph origin/B
> 
> and search in the less-paged output for ABCD-12919 and then look up
> until I find the next tag in the decorations but I guess there's some
> better approach.

The closest thing I can think of is to have a shell script reading along
these lines:

--------------------------------8<--------------------------------
  #!/bin/sh

  set -e -u

  if [ $# -ne 1 ]; then
    printf 'Usage: %s JIRA_TICKET\n' `basename "$0"` >&2
        exit 1
  fi

  sha=`git rev-list --grep="$1" --max-count=1 origin/B`
  if test [ "x$sha" = "x" ]; then
        printf 'No commit found for: %s\n' "$1" >&2
        exit 2
  fi

  git name-rev --tags "$sha"
--------------------------------8<--------------------------------

And then have a Git alias to call it conveniently.

You might want to add more stuff to the `git name-rev` call — like
passing it the "--no-undefined" command-line option.

If `git name-rev` won't cut it for you, you might resort to a bit more
programming: the call `git tag --contains <commit-ish>` will return you
a list of all the tags from which the given commit-ish (any encantation
which is resolvable to a commit) is reachable.  You can now iterate
through all those tags, reach for the immediate commits they point to,
extract commit dates from then and then sort them in the reverse
chronological order and pick the latest one.

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/git-users/20200313091258.hb5prmhdcg7mgeyv%40carbon.

Reply via email to