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

[PATCH] merge: add instructions to the commit message when editing

From
Thomas Rast <trast@student.ethz.ch>
Date
Jan 30, 2012, 20:25 UTC
Message-ID
<0c9a880c7dca27520f957446c6b0e72e93609b03.1327954927.git.trast@student.ethz.ch>
In-Reply-To
<7vd3a1caxb.fsf@alter.siamese.dyndns.org>

Before f824628 (merge: use editor by default in interactive sessions, 2012-01-10), git-merge only started an editor if the user explicitly asked for it with --edit. Thus it seemed unlikely that the user would need extra guidance.

After f824628 the _normal_ thing is to start an editor. Give at least an indication of why we are doing it.

The sentence about justification is one of the few things about standard git that are not agnostic to the workflow that the user chose. However, f824628 was proposed by Linus specifically to discourage users from merging unrelated upstream progress into topic branches. So we may as well take another step in the same direction.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 builtin/merge.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index bfb7547..ed628b8 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -885,11 +885,22 @@ static void abort_commit(const char *err_msg)
 	exit(1);
 }
 
+static const char merge_editor_comment[] =
+N_("Please enter the commit message for your merge commit.  You should\n"
+"justify it especially if it merges an updated upstream into a topic\n"
+"branch.\n"
+"\n"
+"Lines starting with '#' will be ignored, and an empty message aborts\n"
+"the commit.\n");
+
 static void prepare_to_commit(void)
 {
 	struct strbuf msg = STRBUF_INIT;
+	const char *comment = _(merge_editor_comment);
 	strbuf_addbuf(&msg, &merge_msg);
 	strbuf_addch(&msg, '\n');
+	if (0 < option_edit)
+		strbuf_add_lines(&msg, "# ", comment, strlen(comment));
 	write_merge_msg(&msg);
 	run_hook(get_index_file(), "prepare-commit-msg",
 		 git_path("MERGE_MSG"), "merge", NULL, NULL);
-- 
1.7.9.350.ga960f
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 14 in “merge: use editor by default in interactive sessions”
  1. merge: use editor by default in interactive sessionsJunio C Hamano, Jan 23, 2012
  2. Michael HaggertyJan 23, 2012
  3. Junio C HamanoJan 23, 2012
  4. Thomas RastJan 30, 2012
  5. Junio C HamanoJan 30, 2012
  6. merge: add instructions to the commit message when editingThomas Rast, Jan 30, 2012
  7. Junio C HamanoJan 30, 2012
  8. Thomas RastJan 30, 2012
  9. Junio C HamanoJan 30, 2012
  10. Thomas RastJan 31, 2012
  11. Erik Faye-LundFeb 23, 2012
  12. Junio C HamanoFeb 23, 2012
  13. Junio C HamanoFeb 23, 2012
  14. Erik Faye-LundFeb 23, 2012

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.