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

[PATCH 1/5] commit -C: skip blank lines at the beginning of the message

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 29, 2016, 14:14 UTC
Message-ID
<043eafd7ad4128d3a887c224ec6576d96872d1df.1467209576.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1467209576.git.johannes.schindelin@gmx.de>

Consistent with the pretty-printing machinery, we skip leading blank lines (if any) of existing commit messages.

While Git itself only produces commit objects with a single empty line between commit header and commit message, it is legal to have more than one blank line (i.e. lines containing only white space, or no characters) at the beginning of the commit message, and the pretty-printing code already handles that.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/commit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 3f18942..1f6dbcd 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -715,7 +715,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		char *buffer;
 		buffer = strstr(use_message_buffer, "\n\n");
 		if (buffer)
-			strbuf_addstr(&sb, buffer + 2);
+			strbuf_addstr(&sb, skip_blank_lines(buffer + 2));
 		hook_arg1 = "commit";
 		hook_arg2 = use_message;
 	} else if (fixup_message) {
-- 
2.9.0.270.g810e421
Previous: Johannes SchindelinNext: Junio C Hamano
Message 2 of 11 in “Use skip_blank_lines() for more commit messages”
  1. 0/5 Use skip_blank_lines() for more commit messagesJohannes Schindelin, Jun 29, 2016
  2. 1/5 commit -C: skip blank lines at the beginning of the messageJohannes Schindelin, Jun 29, 2016
  3. Junio C HamanoJun 29, 2016
  4. 2/5 sequencer: use skip_blank_lines() to find the commit subjectJohannes Schindelin, Jun 29, 2016
  5. Junio C HamanoJun 29, 2016
  6. 3/5 reset --hard: skip blank lines when reporting the commit subjectJohannes Schindelin, Jun 29, 2016
  7. 4/5 commit -S: avoid invalid pointer with empty messageJohannes Schindelin, Jun 29, 2016
  8. 5/5 Skip blank lines when matching <commit>^{/foo}Johannes Schindelin, Jun 29, 2016
  9. Junio C HamanoJun 29, 2016
  10. Johannes SchindelinJul 2, 2016
  11. Junio C HamanoJun 29, 2016

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.