[PATCH 1/2] trailer: handle input without trailing newline
From: Luca Weiss <luca@z3ntu.xyz>
Add a corresponding test case for this as well
Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
---
t/t7513-interpret-trailers.sh | 7 +++++++
trailer.c | 3 +++
2 files changed, 10 insertions(+)
diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh
index 04885d0a5e5..ff5f1724ad0 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 'with message without trailing newline twice' '
+ git interpret-trailers --trailer "Cc: Peff" basic_message_no_eol > intermediary &&
+ git interpret-trailers --trailer "Cc: Peff" intermediary > actual &&
+ test_cmp intermediary actual
+'
+
test_expect_success 'with commit complex message and trailer args' '
cat complex_message_body >expected &&
sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
diff --git a/trailer.c b/trailer.c
index 7c7cb61a945..f53cf7d07d4 100644
--- a/trailer.c
+++ b/trailer.c
@@ -765,6 +765,9 @@ static void read_input_file(struct strbuf *sb, const char *file)
if (strbuf_read(sb, fileno(stdin), 0) < 0)
die_errno(_("could not read from stdin"));
}
+
+ /* Make sure the input ends with a newline */
+ strbuf_complete_line(sb);
}
static const char *next_line(const char *str)
--
gitgitgadget