# "git describe" documentation and behavior mismatch

6 messages from 2017-11-30 to 2017-12-15. Participants: Daniel Knittl-Frank, Junio C Hamano.
Thread: https://gitlist.dev/t/47357

## Daniel Knittl-Frank, 2017-11-30 18:47

Subject: "git describe" documentation and behavior mismatch
Message-ID: <CACx-yZ10GiDT=dDeF1EUtM_K4nGd414SDfxLRqGWyXt0ub02Gg@mail.gmail.com>
URL: https://gitlist.dev/e/CACx-yZ10GiDT%3DdDeF1EUtM_K4nGd414SDfxLRqGWyXt0ub02Gg%40mail.gmail.com

```
Hi Git list,

the help page/manpage of the git describe command has an example with
the --all flag which should prepend the ref namespace (tags/ or
heads/):

> With --all, the command can use branch heads as references, so the output shows the reference path as well:
>
>          [torvalds@g5 git]$ git describe --all --abbrev=4 v1.0.5^2
>          tags/v1.0.0-21-g975b
>
>          [torvalds@g5 git]$ git describe --all --abbrev=4 HEAD^
>          heads/lt/describe-7-g975b

Running the above commands in the git.git repository yields a different result:

>     $ git describe --all --abbrev=4 v1.0.5^2
>     v1.0.0-21-g975b3

No "reference path" to see. It is however shown, when the output is a
branch name:

>     $ git describe --all --abbrev=4 origin/next
>     heads/next

Is this expected behavior? IOW is the documentation outdated or is the
git describe command misbehaving?

Thanks,
Daniel

-- 
typed with http://neo-layout.org

```

## Daniel Knittl-Frank, 2017-11-30 19:26

Subject: Re: "git describe" documentation and behavior mismatch
Message-ID: <CACx-yZ1dJuUj5mD6WE8yqZCPMK8q-yaJ0GKUSppZ7uDkqvJ5UA@mail.gmail.com>
URL: https://gitlist.dev/e/CACx-yZ1dJuUj5mD6WE8yqZCPMK8q-yaJ0GKUSppZ7uDkqvJ5UA%40mail.gmail.com
In-Reply-To: <CACx-yZ10GiDT=dDeF1EUtM_K4nGd414SDfxLRqGWyXt0ub02Gg@mail.gmail.com>

```
On Thu, Nov 30, 2017 at 7:47 PM, Daniel Knittl-Frank
<knittl89@googlemail.com> wrote:
> […]
>
> Running the above commands in the git.git repository yields a different result:
>
>>     $ git describe --all --abbrev=4 v1.0.5^2
>>     v1.0.0-21-g975b3
>
> No "reference path" to see. It is however shown, when the output is a
> branch name:
>
>>     $ git describe --all --abbrev=4 origin/next
>>     heads/next
>
> Is this expected behavior? IOW is the documentation outdated or is the
> git describe command misbehaving?

Bisecting history goes as far back as Feb 2008: commit
212945d4a85dfa172ea55ec73b1d830ef2d8582f

> Teach git-describe to verify annotated tag names before output

The warning mentioned in the commit message has since been gone. So I
guess the documentation is outdated? Nobody has complained for the
past 9 years, so we could call this a "feature" :)

An interesting fact (and intentional behavior?) is that describing a
commit with only a lightweight tag will properly display the tags/
prefix. I assume this is because the annotated tags only store the
tagname without any ref namespace, which is then picked up by git
describe and displayed.

I will try to come up with a patch for the man page.

Daniel

-- 
typed with http://neo-layout.org

```

## Junio C Hamano, 2017-12-03 05:39

Subject: Re: "git describe" documentation and behavior mismatch
Message-ID: <xmqqefocjrp2.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqefocjrp2.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <CACx-yZ1dJuUj5mD6WE8yqZCPMK8q-yaJ0GKUSppZ7uDkqvJ5UA@mail.gmail.com>

```
Daniel Knittl-Frank <knittl89@googlemail.com> writes:

> An interesting fact (and intentional behavior?) is that describing a
> commit with only a lightweight tag will properly display the tags/
> prefix. I assume this is because the annotated tags only store the
> tagname without any ref namespace, which is then picked up by git
> describe and displayed.

I suspect that "see if the name recorded in the tag object matches
the name of the ref that stores the tag after refs/tags/" code *is*
not just verifying what it claims to (which may be good) but also
unintentionally affecting the output (i.e. "--all" promises that the
prefix tags/ should be shown).  Perhaps the code needs to be fixed
if that is the case.



```

## Daniel Knittl-Frank, 2017-12-11 18:34

Subject: Re: "git describe" documentation and behavior mismatch
Message-ID: <CACx-yZ1DGz2z6qqAX=pzeExT689y0sON+wVDaocdWk75a5SOxA@mail.gmail.com>
URL: https://gitlist.dev/e/CACx-yZ1DGz2z6qqAX%3DpzeExT689y0sON%2BwVDaocdWk75a5SOxA%40mail.gmail.com
In-Reply-To: <xmqqefocjrp2.fsf@gitster.mtv.corp.google.com>

```
On Sun, Dec 3, 2017 at 6:39 AM, Junio C Hamano <gitster@pobox.com> wrote:
> I suspect that "see if the name recorded in the tag object matches
> the name of the ref that stores the tag after refs/tags/" code *is*
> not just verifying what it claims to (which may be good) but also
> unintentionally affecting the output (i.e. "--all" promises that the
> prefix tags/ should be shown).  Perhaps the code needs to be fixed
> if that is the case.

What is the course of action then? I wrote up a really dumb 2-line
patch which simply checks if --all was specified and prepends the
output with "tags/".

Good enough? Should we instead update the documentation? Still not
sure, what the behavior _should_ be in the case of annotated tags with
embedded names.

-- >8 --

From 7243d700aad280b11e647e04ade027c412dde54c Mon Sep 17 00:00:00 2001
From: Daniel Knittl-Frank <knittl89+git@googlemail.com>
Date: Mon, 11 Dec 2017 19:24:54 +0100
Subject: [PATCH] Prepend "tags/" when describing tags with embedded name

Signed-off-by: Daniel Knittl-Frank <knittl89+git@googlemail.com>
---
 builtin/describe.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/builtin/describe.c b/builtin/describe.c
index e14e162ef6..54aaf30562 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -272,6 +272,8 @@ static void display_name(struct commit_name *n)
     }

     if (n->tag)
+        if (all)
+            printf("tags/");
         printf("%s", n->tag->tag);
     else
         printf("%s", n->path);
-- 
2.15.GIT



-- 
typed with http://neo-layout.org

```

## Daniel Knittl-Frank, 2017-12-11 18:37

Subject: Re: "git describe" documentation and behavior mismatch
Message-ID: <CACx-yZ3FxqFvXgM-V0stODcyAdCoO83s=WwyZ2OLiJON6qqvkA@mail.gmail.com>
URL: https://gitlist.dev/e/CACx-yZ3FxqFvXgM-V0stODcyAdCoO83s%3DWwyZ2OLiJON6qqvkA%40mail.gmail.com
In-Reply-To: <CACx-yZ1DGz2z6qqAX=pzeExT689y0sON+wVDaocdWk75a5SOxA@mail.gmail.com>

```
Forget the above patch. I should compile my code after refactoring ...

Here is the fixed version.

-- >8 --

From 8203bd0ad5baab7024ebff597c9f35a0250d09ff Mon Sep 17 00:00:00 2001
From: Daniel Knittl-Frank <knittl89+git@googlemail.com>
Date: Mon, 11 Dec 2017 19:24:54 +0100
Subject: [PATCH] Prepend "tags/" when describing tags with embedded name

Signed-off-by: Daniel Knittl-Frank <knittl89+git@googlemail.com>
---
 builtin/describe.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/builtin/describe.c b/builtin/describe.c
index e14e162ef6..9da6d85ea3 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -271,10 +271,13 @@ static void display_name(struct commit_name *n)
         n->name_checked = 1;
     }

-    if (n->tag)
+    if (n->tag) {
+        if (all)
+            printf("tags/");
         printf("%s", n->tag->tag);
-    else
+    } else {
         printf("%s", n->path);
+    }
 }

 static void show_suffix(int depth, const struct object_id *oid)
-- 
2.15.GIT

-- 
typed with http://neo-layout.org

```

## Junio C Hamano, 2017-12-15 19:25

Subject: Re: "git describe" documentation and behavior mismatch
Message-ID: <xmqqwp1npzd8.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqwp1npzd8.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <CACx-yZ3FxqFvXgM-V0stODcyAdCoO83s=WwyZ2OLiJON6qqvkA@mail.gmail.com>

```
Daniel Knittl-Frank <knittl89@googlemail.com> writes:

> Forget the above patch. I should compile my code after refactoring ...
>
> Here is the fixed version.
>
> -- >8 --
>
> From 8203bd0ad5baab7024ebff597c9f35a0250d09ff Mon Sep 17 00:00:00 2001
> From: Daniel Knittl-Frank <knittl89+git@googlemail.com>
> Date: Mon, 11 Dec 2017 19:24:54 +0100
> Subject: [PATCH] Prepend "tags/" when describing tags with embedded name
>
> Signed-off-by: Daniel Knittl-Frank <knittl89+git@googlemail.com>
> ---
>  builtin/describe.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

I think the code makes sense, but it won't be understandable by
those who do not know what you discussed in the original thread.

A proper commit log message, with a new test or two in t6120, would
be an appropriate way to fix that.

Care to follow through, along the lines in
Documentation/SubmittingPatches?

Thanks.

> diff --git a/builtin/describe.c b/builtin/describe.c
> index e14e162ef6..9da6d85ea3 100644
> --- a/builtin/describe.c
> +++ b/builtin/describe.c
> @@ -271,10 +271,13 @@ static void display_name(struct commit_name *n)
>          n->name_checked = 1;
>      }
>
> -    if (n->tag)
> +    if (n->tag) {
> +        if (all)
> +            printf("tags/");
>          printf("%s", n->tag->tag);
> -    else
> +    } else {
>          printf("%s", n->path);
> +    }
>  }
>
>  static void show_suffix(int depth, const struct object_id *oid)
> -- 
> 2.15.GIT

```
