git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] notes: remove trailing whitespace from editor template
@ 2025-05-24 21:35 kristofferhaugsbakk
  2025-05-25 20:46 ` Kristoffer Haugsbakk
  2025-05-26 14:01 ` Phillip Wood
  0 siblings, 2 replies; 17+ messages in thread
From: kristofferhaugsbakk @ 2025-05-24 21:35 UTC (permalink / raw)
  To: git; +Cc: Kristoffer Haugsbakk

From: Kristoffer Haugsbakk <code@khaugsbakk.name>

The editor template for editing a note consists of the commented block:

    git show --stat --no-notes <object>

The indented commit message will introduce trailing whitespace for
paragraph breaks (blank lines).  Some editors will highlight those lines
as an error immediately when you open the editor.

Let’s strip all unnecessary whitespace from the template to avoid that
very small problem.

Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
---
 builtin/notes.c  | 2 ++
 t/t3301-notes.sh | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/builtin/notes.c b/builtin/notes.c
index a3f433ca4c0..ca4782eca19 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -180,6 +180,8 @@ static void write_commented_object(int fd, const struct object_id *object)
 	if (strbuf_read(&buf, show.out, 0) < 0)
 		die_errno(_("could not read 'show' output"));
 	strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_str);
+	/* strip trailing whitespace introduced by blank lines */
+	strbuf_stripspace(&cbuf, NULL);
 	write_or_die(fd, cbuf.buf, cbuf.len);
 
 	strbuf_release(&cbuf);
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index d6c50460d08..70a21be54fc 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -1629,4 +1629,10 @@ test_expect_success 'git notes append aborts when editor fails with -e' '
 	test_must_fail git notes show
 '
 
+test_expect_success 'git notes add has no trailing whitespace in the editor template' '
+	test_commit --signoff 23rd &&
+	GIT_EDITOR="cat >actual" git notes add &&
+	test_grep ! " $" actual
+'
+
 test_done

base-commit: 8613c2bb6cd16ef530dc5dd74d3b818a1ccbf1c0
-- 
2.49.0.780.g892193c3f50


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-06-10 22:56 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-24 21:35 [PATCH] notes: remove trailing whitespace from editor template kristofferhaugsbakk
2025-05-25 20:46 ` Kristoffer Haugsbakk
2025-05-26 14:01 ` Phillip Wood
2025-05-26 19:44   ` Kristoffer Haugsbakk
2025-05-27  8:24     ` Phillip Wood
2025-05-27 16:11       ` Kristoffer Haugsbakk
2025-05-27 17:18   ` Junio C Hamano
2025-05-27 17:28     ` Eric Sunshine
2025-05-27 21:21     ` Kristoffer Haugsbakk
2025-05-27 22:22     ` Junio C Hamano
2025-06-02 13:52     ` Phillip Wood
2025-06-03 20:37     ` D. Ben Knoble
2025-06-03 20:46       ` Eric Sunshine
2025-06-09 21:10         ` Kristoffer Haugsbakk
2025-06-09 21:12       ` Kristoffer Haugsbakk
2025-06-10 21:11         ` D. Ben Knoble
2025-06-10 22:55           ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).