git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git describe is not returning the expected tag

From
Elijah Newren <newren@gmail.com>
Date
Jul 8, 2022, 01:56 UTC
Message-ID
<CABPp-BH2zuYe87xhjdp5v7M7i+EfEgLHAZgwfzJUAxGk1CFgfA@mail.gmail.com>
In-Reply-To
<PH0PR08MB773203CE3206B8DEFB172B2F94839@PH0PR08MB7732.namprd08.prod.outlook.com>
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:

Show 35 quoted lines
>
> 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.

Show 12 quoted lines
> 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.

Show 12 quoted lines
>         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.
Show 10 quoted lines
> 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.

Previous: Florian Pfaff
Message 2 of 2 in “git describe is not returning the expected tag”
  1. Florian PfaffJul 7, 2022
  2. Elijah NewrenJul 8, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.