All of lore.kernel.org
 help / color / mirror / Atom feed
* git describe is not returning the expected tag
@ 2022-07-07  5:59 Florian Pfaff
  2022-07-08  1:56 ` Elijah Newren
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Pfaff @ 2022-07-07  5:59 UTC (permalink / raw)
  To: git

I am experimenting with git describe as we want to use this in our CI system. However, I am not getting the expected results and neither the git describe documentation nor googling nor stackoverflow have helped me understand why.

The repository
==============

git log --oneline --graph

* 9a45651 (HEAD -> main) m c7
*   b7982a9 merged r3
|\  
| * 8c2adbe (tag: v3.0.0) r3 c1
|/  
* 273a50e m c6
*   6014487 merged r2
|\  
| * aa906b8 (tag: v2.0.0) r2 c2
| * 716c189 r2 c1
|/  
* f0e2c71 m c5
* d42bc37 m c4
*   9060516 merged r1
|\  
| * 619d331 (tag: v1.0.0) r1 c2
| * 75f90de r1 c1
* | 372f1fe m c3
|/  
* a27d5e4 m c2
* a66cb53 m c1


Expected result
===============

When running git describe on main I'd expect   v3.0.0-x-d???????

Actual result
=============

What I am getting instead is  v2.0.0-13-g9a45651


More information
================

git describe --debug
---------------------

        # git describe --debug
        describe HEAD
        No exact match on refs or tags, searching to describe
         annotated         13 v2.0.0
         annotated         13 v1.0.0
         annotated         14 v3.0.0
        traversed 15 commits
        v2.0.0-13-g9a45651


amount of commits between tag and HEAD
--------------------------------------

    $ git log --oneline v2.0.0..HEAD | wc -l
    5

    $ git log --oneline v3.0.0..HEAD | wc -l
    2

git version
-----------

    I have tested 2.36.1 and 2.37.0 both on Ubuntu 20.04.4 LTS both installed from # deb-src http://ppa.launchpad.net/git-core/ppa/ubuntu focal main


Script to recreate the repository
---------------------------------

    https://gist.github.com/twigs/bb0cbe29af55b8141c19d25de47e0eed

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: git describe is not returning the expected tag
  2022-07-07  5:59 git describe is not returning the expected tag Florian Pfaff
@ 2022-07-08  1:56 ` Elijah Newren
  0 siblings, 0 replies; 2+ messages in thread
From: Elijah Newren @ 2022-07-08  1:56 UTC (permalink / raw)
  To: Florian Pfaff; +Cc: git

Hi,

Thanks for the detailed report and simple reproduction steps.  Very cool.

On Wed, Jul 6, 2022 at 11:43 PM Florian Pfaff
<florian.pfaff@hitachivantara.com> wrote:
>
> I am experimenting with git describe as we want to use this in our CI system. However, I am not getting the expected results and neither the git describe documentation nor googling nor stackoverflow have helped me understand why.
>
> The repository
> ==============
>
> git log --oneline --graph
>
> * 9a45651 (HEAD -> main) m c7
> *   b7982a9 merged r3
> |\
> | * 8c2adbe (tag: v3.0.0) r3 c1
> |/
> * 273a50e m c6
> *   6014487 merged r2
> |\
> | * aa906b8 (tag: v2.0.0) r2 c2
> | * 716c189 r2 c1
> |/
> * f0e2c71 m c5
> * d42bc37 m c4
> *   9060516 merged r1
> |\
> | * 619d331 (tag: v1.0.0) r1 c2
> | * 75f90de r1 c1
> * | 372f1fe m c3
> |/
> * a27d5e4 m c2
> * a66cb53 m c1
>
>
> Expected result
> ===============
>
> When running git describe on main I'd expect   v3.0.0-x-d???????

In particular, according to the documentation, this should be named
v3.0.0-2-g9a45651

> Actual result
> =============
>
> What I am getting instead is  v2.0.0-13-g9a45651

Even if you were to delete the v3.0.0 tag, this wouldn't be the
correct answer.  The expected result in that case would be
v2.0.0-5-g9a45651.  So, it finds the wrong tag AND gets the count
wrong.

> More information
> ================
>
> git describe --debug
> ---------------------
>
>         # git describe --debug
>         describe HEAD
>         No exact match on refs or tags, searching to describe
>          annotated         13 v2.0.0
>          annotated         13 v1.0.0
>          annotated         14 v3.0.0

and indeed, here we see that the counts are off for all the tags.  Way
off, even in this simple repository.  The counts should be 5, 11, and
2 rather than 13, 13, and 14.

>         traversed 15 commits
>         v2.0.0-13-g9a45651
>
>
> amount of commits between tag and HEAD
> --------------------------------------
>
>     $ git log --oneline v2.0.0..HEAD | wc -l
>     5
>
>     $ git log --oneline v3.0.0..HEAD | wc -l
>     2

Here you show what the counts should be.

> git version
> -----------
>
>     I have tested 2.36.1 and 2.37.0 both on Ubuntu 20.04.4 LTS both installed from # deb-src http://ppa.launchpad.net/git-core/ppa/ubuntu focal main
>
>
> Script to recreate the repository
> ---------------------------------
>
>     https://gist.github.com/twigs/bb0cbe29af55b8141c19d25de47e0eed

Thanks for the script.  If you add a "sleep 1" after every commit or
merge command, `git describe` happens to return the right output.
Basically, `git describe` is broken.  This appears to have been
discussed previously, see here:
https://lore.kernel.org/git/20191008123156.GG11529@szeder.dev/, but
looks like there was never quite as simple of a testcase as this one.

If anyone's reading this and wants to dig in, and try to fix, feel
free.  I don't have time to dig further.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-08  1:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-07  5:59 git describe is not returning the expected tag Florian Pfaff
2022-07-08  1:56 ` Elijah Newren

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.