Like other Git commands, `git notes` takes care to call `stripspace` on the user-supplied note content, thereby ensuring that it has no trailing whitespace, among other cleanups. However, when notes are inserted into a patch via `git format-patch --notes`, all lines of the note are indented unconditionally, including empty lines, which leaves trailing whitespace on lines which previously were empty, thus negating the normalization done earlier. Fix this shortcoming. Signed-off-by: Eric Sunshine <sunshine@xxxxxxxxxxxxxx> --- notes.c | 2 +- t/t4014-format-patch.sh | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/notes.c b/notes.c index f87dac4068..25e0a59899 100644 --- a/notes.c +++ b/notes.c @@ -1295,7 +1295,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) { linelen = strchrnul(msg_p, '\n') - msg_p; - if (!raw) + if (!raw && linelen) strbuf_addstr(sb, " "); strbuf_add(sb, msg_p, linelen); strbuf_addch(sb, '\n'); diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 712d4b5ddf..7406e5fe99 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -906,6 +906,23 @@ test_expect_success 'format-patch with multiple notes refs in config' ' grep "this is note 2" out ' +test_expect_success 'format-patch --notes does not indent empty lines' ' + git notes add --file=- HEAD <<-\EOF && + paragraph 1 + + paragraph 2 + EOF + test_when_finished "git notes remove HEAD" && + git format-patch -1 --stdout --notes >out && + sed -n "/^[ ]*paragraph 1$/,/^[ ]*paragraph 2$/{s/^[ ][ ]*/[indent]/;p;}" out >actual && + cat >expect <<-\EOF && + [indent]paragraph 1 + + [indent]paragraph 2 + EOF + test_cmp expect actual +' + echo "fatal: --name-only does not make sense" >expect.name-only echo "fatal: --name-status does not make sense" >expect.name-status echo "fatal: --check does not make sense" >expect.check -- 2.33.0.153.gba50c8fa24