{"thread":{"id":"56076","subject":"git interpret-trailers: behavior with input without trailing newline","startedAt":"2021-07-08T10:43:03Z","lastAt":"2021-07-13T00:35:29Z","messageCount":2,"participants":["Luca Weiss","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"429482","messageId":"CCNOOVFJVMLC.7L79PCH59K1C@arch-vps","threadId":"56076","inReplyTo":null,"subject":"git interpret-trailers: behavior with input without trailing newline","fromName":"Luca Weiss","fromEmail":"luca@z3ntu.xyz","sentAt":"2021-07-08T10:33:46Z","receivedAt":"2021-07-08T10:43:03Z","isPatch":false,"sender":{"key":"luca@z3ntu.xyz","avatar":null},"body":"Hi all,\n\nI'm investigating a behavior with git interpret-trailers where when the input does not end with a newline, git appends the trailer directly without a newline; and on running the same command again it doesn't detect the previous trailer anymore. \n\nI've whipped up a quick PoC in form of a new test case in the existing test cases of git.\n\nAppending the patch here (sorry if it does get corrupted from my editor, but I hope you get the gist of it).\n\ndiff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh\nindex 04885d0a5e..602725f939 100755\n--- a/t/t7513-interpret-trailers.sh\n+++ b/t/t7513-interpret-trailers.sh\n@@ -17,6 +17,7 @@ test_expect_success 'setup' '\n \n \t\tbody\n \tEOF\n+\tprintf \"subject\\n\\nbody\" > basic_message_no_eol &&\n \tcat >complex_message_body <<-\\EOF &&\n \t\tmy subject\n \n@@ -676,6 +677,12 @@ test_expect_success 'with message that has an old style conflict block' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'bla blub' '\n+\tgit interpret-trailers --trailer \"Cc: Peff\" basic_message_no_eol > intermediary &&\n+\tgit interpret-trailers --trailer \"Cc: Peff\" intermediary > actual9 &&\n+\ttest_cmp intermediary actual9\n+'\n+\n test_expect_success 'with commit complex message and trailer args' '\n \tcat complex_message_body >expected &&\n \tsed -e \"s/ Z\\$/ /\" >>expected <<-\\EOF &&\n\n\nIt doesn't feel like an expected behavior but if it is, please tell me.\n\nRegards\nLuca"},{"id":"429859","messageId":"YOzfzQsuDOeL8VY9@coredump.intra.peff.net","threadId":"56076","inReplyTo":"CCNOOVFJVMLC.7L79PCH59K1C@arch-vps","subject":"Re: git interpret-trailers: behavior with input without trailing newline","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-07-13T00:35:25Z","receivedAt":"2021-07-13T00:35:29Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jul 08, 2021 at 10:33:46AM +0000, Luca Weiss wrote:\n\n> I'm investigating a behavior with git interpret-trailers where when\n> the input does not end with a newline, git appends the trailer\n> directly without a newline; and on running the same command again it\n> doesn't detect the previous trailer anymore.\n> \n> I've whipped up a quick PoC in form of a new test case in the existing\n> test cases of git.\n\nIn general, I think commit message inputs should have trailing newlines,\nas they'd generally be coming from actual commits, or piped through\ngit-stripspace to clean things up.\n\nThat said, the behavior you're seeing does seem like a bug to me. I\ndon't think it was intended, and it would be nice to fix it, if you're\nup for it. It might be as simple as conditionally adding a newline after\nwe read the input in trailers.c:read_input_file(). (IMHO even if we do\nnot end up adding a trailer, normalizing the whitespace in this way\nwould be a fine behavior for the command).\n\n-Peff\n"}]}