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

Fix issue with formatting multiple trailer keys

From
Brooke Kuhlmann <brooke@alchemists.io>
Date
Sep 6, 2024, 19:55 UTC
Message-ID
<EF5AE27D-B7CE-4337-B928-6073837218CA@alchemists.io>
Hello. đź‘‹
I'm seeing strange issues with log/listing trailer information for commits and tags and I think I'm experiencing a bug where when I attempt to list commits and tags with specific trailer keys, I get new lines showing up in my output.
Here's my steps to recreate using a simple Bash script:

``` mkdir demo cd demo git init

touch one.txt git add . git commit --message "Added one" --trailer Milestone=patch --trailer Issue=111 git tag 0.0.0 --message "Version 0.0.0" --no-sign --trailer Files:1 --trailer Duration:1

touch two.txt git add . git commit --message "Added two" --trailer Milestone=patch --trailer Issue=222 git tag 0.0.1 --message "Version 0.0.1" --no-sign --trailer Files:1 --trailer Duration:1 ```

Notice that I'm using trailers for my commits *and* tags. Here's what my git log looks like:

``` git log --pretty=format:"%h %an% %s %d %cr. %(trailers:key=Milestone) %(trailers:key=Issue)" ```

The above produces this output:
08a07b717bef Brooke KuhlmannAdded two  (HEAD -> main, tag: 0.0.1) 5 minutes ago. Milestone: patch
 Issue: 222
01c4c182c85e Brooke KuhlmannAdded one  (tag: 0.0.0) 5 minutes ago. Milestone: patch
 Issue: 111
...and if I list my tags using this command:
``` 
git tag --list \
        --format="%(refname:short) %(taggerdate:short) %(taggername) %(subject) %(trailers:key=Files) %(trailers:key=Duration)"
```
...I get this output:
0.0.0 2024-09-06 Brooke Kuhlmann Version 0.0.0 Files: 1
Duration: 1
 Files: 1
Duration: 1
0.0.1 2024-09-06 Brooke Kuhlmann Version 0.0.1 Files: 1
Duration: 1
 Files: 1
Duration: 1
Notice, when logging trailer information for commits and tags, I get unexpected new line characters showing up in the output. I expect to see all information printed on the same line without any new lines showing up.
Also, I want to point out that when listing tag trailers, I get the "Duration" key showing up twice. I'm not sure if that's related or not but seems like very weird behavior.
Next: Jeff King
Message 1 of 5 in “Fix issue with formatting multiple trailer keys”
  1. Brooke KuhlmannSep 6, 2024
  2. Jeff KingSep 6, 2024
  3. Brooke KuhlmannSep 6, 2024
  4. Jeff KingSep 9, 2024
  5. Brooke KuhlmannSep 10, 2024

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.