threads / discuss / 56076

git interpret-trailers: behavior with input without trailing newline

Subject: git interpret-trailers: behavior with input without trailing newline

## tl;dr

2 messages between Jul 8, 2021 and Jul 13, 2021.

replies: 1people: 2as markdown or json

Luca Weiss· Jul 8, 2021, 10:33 UTC · lore
Hi all,
I'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. 
I've whipped up a quick PoC in form of a new test case in the existing test cases of git.
Appending the patch here (sorry if it does get corrupted from my editor, but I hope you get the gist of it).
diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh
index 04885d0a5e..602725f939 100755
--- a/t/t7513-interpret-trailers.sh
+++ b/t/t7513-interpret-trailers.sh
@@ -17,6 +17,7 @@ test_expect_success 'setup' '
 
 		body
 	EOF
+	printf "subject\n\nbody" > basic_message_no_eol &&
 	cat >complex_message_body <<-\EOF &&
 		my subject
 
@@ -676,6 +677,12 @@ test_expect_success 'with message that has an old style conflict block' '
 	test_cmp expected actual
 '
 
+test_expect_success 'bla blub' '
+	git interpret-trailers --trailer "Cc: Peff" basic_message_no_eol > intermediary &&
+	git interpret-trailers --trailer "Cc: Peff" intermediary > actual9 &&
+	test_cmp intermediary actual9
+'
+
 test_expect_success 'with commit complex message and trailer args' '
 	cat complex_message_body >expected &&
 	sed -e "s/ Z\$/ /" >>expected <<-\EOF &&


It doesn't feel like an expected behavior but if it is, please tell me.

Regards
Luca
Jeff King· Jul 13, 2021, 00:35 UTC · re: Luca Weiss · lore

Re: git interpret-trailers: behavior with input without trailing newline

On Thu, Jul 08, 2021 at 10:33:46AM +0000, Luca Weiss wrote:
Show 7 quoted lines
> I'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.
> 
> I've whipped up a quick PoC in form of a new test case in the existing
> test cases of git.

In general, I think commit message inputs should have trailing newlines, as they'd generally be coming from actual commits, or piped through git-stripspace to clean things up.

That said, the behavior you're seeing does seem like a bug to me. I don't think it was intended, and it would be nice to fix it, if you're up for it. It might be as simple as conditionally adding a newline after we read the input in trailers.c:read_input_file(). (IMHO even if we do not end up adding a trailer, normalizing the whitespace in this way would be a fine behavior for the command).

-Peff

← back to recent threads