git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] notes: remove trailing whitespace from editor template

From
Kkristofferhaugsbakk@fastmail.com <kristofferhaugsbakk@fastmail.com>
Date
May 24, 2025, 21:35 UTC
Message-ID
<c59ae2c0c7c8420ec1c5bedb87f28c7f5b573a60.1748122397.git.code@khaugsbakk.name>
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
Next: Kristoffer Haugsbakk
Message 1 of 17 in “notes: remove trailing whitespace from editor template”
  1. notes: remove trailing whitespace from editor templatekristofferhaugsbakk@fastmail.com, May 24, 2025
  2. Kristoffer HaugsbakkMay 25, 2025
  3. Phillip WoodMay 26, 2025
  4. Kristoffer HaugsbakkMay 26, 2025
  5. Phillip WoodMay 27, 2025
  6. Kristoffer HaugsbakkMay 27, 2025
  7. Junio C HamanoMay 27, 2025
  8. Eric SunshineMay 27, 2025
  9. Kristoffer HaugsbakkMay 27, 2025
  10. Junio C HamanoMay 27, 2025
  11. Phillip WoodJun 2, 2025
  12. D. Ben KnobleJun 3, 2025
  13. Eric SunshineJun 3, 2025
  14. Kristoffer HaugsbakkJun 9, 2025
  15. Kristoffer HaugsbakkJun 9, 2025
  16. D. Ben KnobleJun 10, 2025
  17. Junio C HamanoJun 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.