# Should Git Tag trailer formatting work?

5 messages from 2024-09-05 to 2024-09-06. Participants: Brooke Kuhlmann, Jeff King.
Thread: https://gitlist.dev/t/62066

## Brooke Kuhlmann, 2024-09-05 16:05

Subject: Should Git Tag trailer formatting work?
Message-ID: <E46F3EFF-66D1-4B29-BCF3-6FFAB2504411@alchemists.io>
URL: https://gitlist.dev/e/E46F3EFF-66D1-4B29-BCF3-6FFAB2504411%40alchemists.io

```
Hello. 👋

With the recent release of Git 2.46.0, the ability to add trailers to tags was added which is great! However, when attempting to list and format trailer information, I don't see the trailer information display using the following Bash code:

ˋˋˋ 
git tag --list \
        --color \
        --format="%(color:yellow)%(refname:short)%(color:reset)|%(taggerdate:short)|%(color:blue)%(color:bold)%(taggername)%(color:reset)|%(subject)|%(trailers:key=Insertions)" \
        | column -s"|" -t
ˋˋˋ

Notice that I'm using the same syntax (`%(trailers:key=Insertions)`) as used in the git for-each-ref (https://git-scm.com/docs/git-for-each-ref#Documentation/git-for-each-ref.txt-rawsize) documentation. If it helps, I also create my Git tag using `git tag` and formatting my message as follows:

ˋˋˋ 
Version 0.0.0

An example.

Insertions: 10
ˋˋˋ

Shouldn't the formatting of my git tags pick up the "Insertions" trailer key and print it? Is this a bug or am I doing something wrong?

Thanks!
```

## Jeff King, 2024-09-06 04:04

Subject: Re: Should Git Tag trailer formatting work?
Message-ID: <20240906040434.GB4168449@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20240906040434.GB4168449%40coredump.intra.peff.net
In-Reply-To: <E46F3EFF-66D1-4B29-BCF3-6FFAB2504411@alchemists.io>

```
On Thu, Sep 05, 2024 at 10:05:24AM -0600, Brooke Kuhlmann wrote:

> With the recent release of Git 2.46.0, the ability to add trailers to tags was added which is great! However, when attempting to list and format trailer information, I don't see the trailer information display using the following Bash code:
> 
> ˋˋˋ 
> git tag --list \
>         --color \
>         --format="%(color:yellow)%(refname:short)%(color:reset)|%(taggerdate:short)|%(color:blue)%(color:bold)%(taggername)%(color:reset)|%(subject)|%(trailers:key=Insertions)" \
>         | column -s"|" -t
> ˋˋˋ

This seems to work fine for me. If I do:

  {
	echo "Version 0.0.0"
	echo
	echo "An example."
	echo
	echo "Insertions: 10"
  } >input
  git tag -F input foo

then your example above produces:

  foo  2024-09-06  Jeff King  Version 0.0.0  Insertions: 10

I wonder if the contents of the tag are not exactly as you expect, and
that is fooling the trailer parser (which relies on some heuristics to
find the right spot). Can you show us the output of "git cat-file tag
<some-tag>"? Mine looks like:

  $ git cat-file tag foo
  object af1c73c21ab34cfbdc86da838acacc6e45ccd264
  type commit
  tag foo
  tagger Jeff King <peff@peff.net> 1725595316 -0400
  
  Version 0.0.0
  
  An example.
  
  Insertions: 10

-Peff

```

## Brooke Kuhlmann, 2024-09-06 15:22

Subject: Re: Should Git Tag trailer formatting work?
Message-ID: <249C7637-0032-4D53-A8A0-83935764334E@alchemists.io>
URL: https://gitlist.dev/e/249C7637-0032-4D53-A8A0-83935764334E%40alchemists.io
In-Reply-To: <20240906040434.GB4168449@coredump.intra.peff.net>

```
Hey Jeff, thanks.

Yeah, I can render trailer information when using your examples but *only* if I disable signing my tags. Here's what my global Git configuration looks like:

[tag]
  gpgSign = true
  sort = version:refname

...and here's a better example to demonstrate:

mkdir demo
cd demo
git init

touch one.txt
git add .
git commit --message "Added one"
git tag 0.0.0 --message "Version 0.0.0" --trailer A:0

touch two.txt
git add .
git commit --message "Added two"
git tag 0.0.1 --message "Version 0.0.1" --no-sign --trailer A:1

Notice how Version 0.0.0 creates a signed tag but Version 0.0.1 forces the tag to not be signed. I can then run the following:

git tag --list \
        --format="%(refname:short)|%(taggerdate:short)|%(taggername)|%(subject)|%(trailers:key=A)" \
       | column -s "|" -t

...to produce this output:

0.0.0  2024-09-06  Brooke Kuhlmann  Version 0.0.0
0.0.1  2024-09-06  Brooke Kuhlmann  Version 0.0.1  A: 1

So I can see that Git tag trailers are working but only if my tags are *not* signed. Here's what each tag looks like when I cat them out:

git cat-file tag 0.0.0

object ad13b82ff41d5698cfb03a06b95e6e5a98386ed4
type commit
tag 0.0.0
tagger Brooke Kuhlmann <brooke@alchemists.io> 1725635799 -0600

Version 0.0.0

A: 0
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEE0UiFiNLe33PmLweh8rxJvE/7mkgFAmbbHNcACgkQ8rxJvE/7
mkiBFRAAlaFfRQK6fK4J9z49tF9OR0vMJRygtR4LZE1z2JmPUTTapKf8meIFIFxU
GeIAfcD8aofgV6WeGDCIaL0Kg0quInlWA19Y+Yqv5ZL3J6dEkWu8R9hmgKK8jCPo
U+EtaCSv0cM+ZmN4paCM9ZirdvnTQY5gaTJ9D+xreklaqZSryrAFfMH6UdsGnFtQ
KkR+G2B9RCuD2loV5KBIttYAhnGf54xJxfGFcZiIGD/qErWWgABIN6zDP5SHPMXz
NOjDDLh3ZUA0D1nXqxS7Aq4fe4wrRIGmtLs+Kh+fnHLuhfBh7vqrkUBydGjiGuc3
bQVOHCxe3kpfqS+P/12aGfc4yTWdL89qBWZGCEtTPw4wqLAOvzMzJ6ffc6TKdz6r
mNsV4ZWKwigS6KpCyJt1ecWq3jAZIPwx2ADsw/JQm82LfcTrn3d3nIV/0qpM0oVL
jOoZh+ozPq2bWZWqHk6PfaW2m0dKN8w9o9paJGUdyj5KjolLtak7sY067ATbIFXM
hdkpFAhvc6VhFNIcfYStLd1yJggCigpXbtx/+QG/PMMx6wMwcz0kko1KfWW4fxs0
SiEbHO3Ja0o1DG31QFb54MOi8I7n8xVgtckSj+dr+/b4hEv8b1BS5x61NJaTsxu4
PQcWEburYAPeFkbmT/ji52vCLOetQ4GPEc2+sDPvZioxQgUuhzk=
=v8eJ
-----END PGP SIGNATURE-----



git cat-file tag 0.0.1

object e10b4d0578a5b309aac31d036a2d33a7389eff2e
type commit
tag 0.0.1
tagger Brooke Kuhlmann <brooke@alchemists.io> 1725635858 -0600

Version 0.0.1

A: 1

So it seems like signing my tags is causing trailer information to be lost?


> On Sep 5, 2024, at 10:04 PM, Jeff King <peff@peff.net> wrote:
> 
> On Thu, Sep 05, 2024 at 10:05:24AM -0600, Brooke Kuhlmann wrote:
> 
>> With the recent release of Git 2.46.0, the ability to add trailers to tags was added which is great! However, when attempting to list and format trailer information, I don't see the trailer information display using the following Bash code:
>> 
>> ˋˋˋ 
>> git tag --list \
>>        --color \
>>        --format="%(color:yellow)%(refname:short)%(color:reset)|%(taggerdate:short)|%(color:blue)%(color:bold)%(taggername)%(color:reset)|%(subject)|%(trailers:key=Insertions)" \
>>        | column -s"|" -t
>> ˋˋˋ
> 
> This seems to work fine for me. If I do:
> 
>  {
> 	echo "Version 0.0.0"
> 	echo
> 	echo "An example."
> 	echo
> 	echo "Insertions: 10"
>  } >input
>  git tag -F input foo
> 
> then your example above produces:
> 
>  foo  2024-09-06  Jeff King  Version 0.0.0  Insertions: 10
> 
> I wonder if the contents of the tag are not exactly as you expect, and
> that is fooling the trailer parser (which relies on some heuristics to
> find the right spot). Can you show us the output of "git cat-file tag
> <some-tag>"? Mine looks like:
> 
>  $ git cat-file tag foo
>  object af1c73c21ab34cfbdc86da838acacc6e45ccd264
>  type commit
>  tag foo
>  tagger Jeff King <peff@peff.net> 1725595316 -0400
> 
>  Version 0.0.0
> 
>  An example.
> 
>  Insertions: 10
> 
> -Peff


```

## Jeff King, 2024-09-06 21:50

Subject: Re: Should Git Tag trailer formatting work?
Message-ID: <20240906215054.GA1149961@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20240906215054.GA1149961%40coredump.intra.peff.net
In-Reply-To: <249C7637-0032-4D53-A8A0-83935764334E@alchemists.io>

```
On Fri, Sep 06, 2024 at 09:22:33AM -0600, Brooke Kuhlmann wrote:

> Yeah, I can render trailer information when using your examples but
> *only* if I disable signing my tags. Here's what my global Git
> configuration looks like:

Ah, OK, that makes sense. We have to parse the trailers from the end,
and the parser is not prepared to handle tags' inline signatures (in
commits, the signatures are embedded in headers, so the trailer parser
doesn't have to worry about them).

I have a rough patch, but it requires making an extra copy of the tag
buffer, since the trailer API needs a NUL-terminated string. I'll see if
I can clean that up to let us parse it in place, and should send
something out in a day or so.

-Peff

```

## Brooke Kuhlmann, 2024-09-06 22:56

Subject: Re: Should Git Tag trailer formatting work?
Message-ID: <3A01E3C6-0AB5-4C0D-AA76-E5EE6A5AFA55@alchemists.io>
URL: https://gitlist.dev/e/3A01E3C6-0AB5-4C0D-AA76-E5EE6A5AFA55%40alchemists.io
In-Reply-To: <20240906215054.GA1149961@coredump.intra.peff.net>

```
Thanks! Yeah, that'd be great. Will look forward to checking out the changes.

> On Sep 6, 2024, at 3:50 PM, Jeff King <peff@peff.net> wrote:
> 
> On Fri, Sep 06, 2024 at 09:22:33AM -0600, Brooke Kuhlmann wrote:
> 
>> Yeah, I can render trailer information when using your examples but
>> *only* if I disable signing my tags. Here's what my global Git
>> configuration looks like:
> 
> Ah, OK, that makes sense. We have to parse the trailers from the end,
> and the parser is not prepared to handle tags' inline signatures (in
> commits, the signatures are embedded in headers, so the trailer parser
> doesn't have to worry about them).
> 
> I have a rough patch, but it requires making an extra copy of the tag
> buffer, since the trailer API needs a NUL-terminated string. I'll see if
> I can clean that up to let us parse it in place, and should send
> something out in a day or so.
> 
> -Peff


```
