{"thread":{"id":"58116","subject":"git describe is not returning the expected tag","startedAt":"2022-07-07T05:59:25Z","lastAt":"2022-07-08T01:56:34Z","messageCount":2,"participants":["Florian Pfaff","Elijah Newren"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"458554","messageId":"PH0PR08MB773203CE3206B8DEFB172B2F94839@PH0PR08MB7732.namprd08.prod.outlook.com","threadId":"58116","inReplyTo":null,"subject":"git describe is not returning the expected tag","fromName":"Florian Pfaff","fromEmail":"florian.pfaff@hitachivantara.com","sentAt":"2022-07-07T05:59:15Z","receivedAt":"2022-07-07T05:59:25Z","isPatch":false,"sender":{"key":"florian.pfaff@hitachivantara.com","avatar":null},"body":"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.\n\nThe repository\n==============\n\ngit log --oneline --graph\n\n* 9a45651 (HEAD -> main) m c7\n*   b7982a9 merged r3\n|\\  \n| * 8c2adbe (tag: v3.0.0) r3 c1\n|/  \n* 273a50e m c6\n*   6014487 merged r2\n|\\  \n| * aa906b8 (tag: v2.0.0) r2 c2\n| * 716c189 r2 c1\n|/  \n* f0e2c71 m c5\n* d42bc37 m c4\n*   9060516 merged r1\n|\\  \n| * 619d331 (tag: v1.0.0) r1 c2\n| * 75f90de r1 c1\n* | 372f1fe m c3\n|/  \n* a27d5e4 m c2\n* a66cb53 m c1\n\n\nExpected result\n===============\n\nWhen running git describe on main I'd expect   v3.0.0-x-d???????\n\nActual result\n=============\n\nWhat I am getting instead is  v2.0.0-13-g9a45651\n\n\nMore information\n================\n\ngit describe --debug\n---------------------\n\n        # git describe --debug\n        describe HEAD\n        No exact match on refs or tags, searching to describe\n         annotated         13 v2.0.0\n         annotated         13 v1.0.0\n         annotated         14 v3.0.0\n        traversed 15 commits\n        v2.0.0-13-g9a45651\n\n\namount of commits between tag and HEAD\n--------------------------------------\n\n    $ git log --oneline v2.0.0..HEAD | wc -l\n    5\n\n    $ git log --oneline v3.0.0..HEAD | wc -l\n    2\n\ngit version\n-----------\n\n    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\n\n\nScript to recreate the repository\n---------------------------------\n\n    https://gist.github.com/twigs/bb0cbe29af55b8141c19d25de47e0eed\n"},{"id":"458622","messageId":"CABPp-BH2zuYe87xhjdp5v7M7i+EfEgLHAZgwfzJUAxGk1CFgfA@mail.gmail.com","threadId":"58116","inReplyTo":"PH0PR08MB773203CE3206B8DEFB172B2F94839@PH0PR08MB7732.namprd08.prod.outlook.com","subject":"Re: git describe is not returning the expected tag","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2022-07-08T01:56:19Z","receivedAt":"2022-07-08T01:56:34Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"Hi,\n\nThanks for the detailed report and simple reproduction steps.  Very cool.\n\nOn Wed, Jul 6, 2022 at 11:43 PM Florian Pfaff\n<florian.pfaff@hitachivantara.com> wrote:\n>\n> 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.\n>\n> The repository\n> ==============\n>\n> git log --oneline --graph\n>\n> * 9a45651 (HEAD -> main) m c7\n> *   b7982a9 merged r3\n> |\\\n> | * 8c2adbe (tag: v3.0.0) r3 c1\n> |/\n> * 273a50e m c6\n> *   6014487 merged r2\n> |\\\n> | * aa906b8 (tag: v2.0.0) r2 c2\n> | * 716c189 r2 c1\n> |/\n> * f0e2c71 m c5\n> * d42bc37 m c4\n> *   9060516 merged r1\n> |\\\n> | * 619d331 (tag: v1.0.0) r1 c2\n> | * 75f90de r1 c1\n> * | 372f1fe m c3\n> |/\n> * a27d5e4 m c2\n> * a66cb53 m c1\n>\n>\n> Expected result\n> ===============\n>\n> When running git describe on main I'd expect   v3.0.0-x-d???????\n\nIn particular, according to the documentation, this should be named\nv3.0.0-2-g9a45651\n\n> Actual result\n> =============\n>\n> What I am getting instead is  v2.0.0-13-g9a45651\n\nEven if you were to delete the v3.0.0 tag, this wouldn't be the\ncorrect answer.  The expected result in that case would be\nv2.0.0-5-g9a45651.  So, it finds the wrong tag AND gets the count\nwrong.\n\n> More information\n> ================\n>\n> git describe --debug\n> ---------------------\n>\n>         # git describe --debug\n>         describe HEAD\n>         No exact match on refs or tags, searching to describe\n>          annotated         13 v2.0.0\n>          annotated         13 v1.0.0\n>          annotated         14 v3.0.0\n\nand indeed, here we see that the counts are off for all the tags.  Way\noff, even in this simple repository.  The counts should be 5, 11, and\n2 rather than 13, 13, and 14.\n\n>         traversed 15 commits\n>         v2.0.0-13-g9a45651\n>\n>\n> amount of commits between tag and HEAD\n> --------------------------------------\n>\n>     $ git log --oneline v2.0.0..HEAD | wc -l\n>     5\n>\n>     $ git log --oneline v3.0.0..HEAD | wc -l\n>     2\n\nHere you show what the counts should be.\n\n> git version\n> -----------\n>\n>     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\n>\n>\n> Script to recreate the repository\n> ---------------------------------\n>\n>     https://gist.github.com/twigs/bb0cbe29af55b8141c19d25de47e0eed\n\nThanks for the script.  If you add a \"sleep 1\" after every commit or\nmerge command, `git describe` happens to return the right output.\nBasically, `git describe` is broken.  This appears to have been\ndiscussed previously, see here:\nhttps://lore.kernel.org/git/20191008123156.GG11529@szeder.dev/, but\nlooks like there was never quite as simple of a testcase as this one.\n\nIf anyone's reading this and wants to dig in, and try to fix, feel\nfree.  I don't have time to dig further.\n"}]}