Git multiline trailer with empty lines (is this a bug?)

Viewed 192

So, git trailers (https://git-scm.com/docs/git-interpret-trailers) supports multi-line trailers by "folding" them, meaning that subsequent lines start with one space to indicate that they still belong to the current trailer.

The documentation says:

When reading trailers, there can be whitespaces after the token, the separator and the value. There can also be whitespaces inside the token and the value. The value may be split over multiple lines with each subsequent line starting with whitespace, like the "folding" in RFC 822.

My problem is that git interpret-trailers --parse fails if such a multi-line trailer contains an empty line.

I'm trying to add a trailer that contains one or more empty lines. These empty lines are properly folded however, they contain one space (so this is equivalent to the PGP signature that is added to the commit header, which also contains an empty line, that is folded however)

But if I do that, git interpret-trailers --parse just outputs nothing.

$ echo "Test" > test.txt
$ git interpret-trailers --where end --if-exists addIfDifferent --trailer "SingleLineTrailer: This is a single line trailer" --in-place test.txt
$ git interpret-trailers --where end --if-exists addIfDifferent --trailer "MultiLineTrailer: This is"$'\n a folded multi-line\n trailer' --in-place test.txt

contents of test.txt is now:

$ cat test.txt
Test

SingleLineTrailer: This is a single line trailer
MultiLineTrailer: This is
 a folded multi-line
 trailer

and parsing works (it parses multiple lines to a single line, which is unexpected, but at least does something):

$ git interpret-trailers --parse test.txt
SingleLineTrailer: This is a single line trailer
MultiLineTrailer: This is a folded multi-line trailer

However, now I'm adding a multi-line trailer that contains a free line (properly folded using a space however):

$ git interpret-trailers --where end --if-exists addIfDifferent --trailer "MultiLineTrailer: This is"$'\n a folded multi-line\n trailer which\n \n contains an\n empty line' --in-place test.txt

which results, as expected, in the following content:

$ cat test.txt
Test

SingleLineTrailer: This is a single line trailer
MultiLineTrailer: This is
 a folded multi-line
 trailer
MultiLineTrailer: This is
 a folded multi-line
 trailer which

 contains an
 empty line

however, running git interpret-trailers --parse results in no output (but exit code is 0):

$ git interpret-trailers --parse test.txt
$ echo $?
0

git version is git version 2.30.0.windows.2

So, is this a bug in git or is this behaviour expected?

0 Answers
Related