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

[PATCH 8/8] merge: --log appends shortlog to message if specified

From
Tay Ray Chuan <rctay89@gmail.com>
Date
May 10, 2010, 17:17 UTC
Message-ID
<1273511872-4924-9-git-send-email-rctay89@gmail.com>
In-Reply-To
<1273511872-4924-1-git-send-email-rctay89@gmail.com>

When the user specifies a message, use fmt_merge_msg_shortlog() to append the shortlog.

Previously, when a message was specified, we ignored the merge title ("Merge <foo> into <bar>") and shortlog from fmt_merge_msg().

Update the documentation for -m to reflect this too.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
 Documentation/git-merge.txt     |    7 ++++++-
 builtin/fmt-merge-msg.c         |    3 +++
 builtin/merge.c                 |   18 +++++++++++-------
 t/t7604-merge-custom-message.sh |    2 +-
 4 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index c2325ef..84043cc 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -58,7 +58,12 @@ include::merge-options.txt[]
 
 -m <msg>::
 	Set the commit message to be used for the merge commit (in
-	case one is created). The 'git fmt-merge-msg' command can be
+	case one is created).
+
+	If `--log` is specified, a shortlog of the commits being merged
+	will be appended to the specified message.
+
+	The 'git fmt-merge-msg' command can be
 	used to give a good default for automated 'git merge'
 	invocations.
 
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 48548cf..4420425 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -298,6 +298,9 @@ static int do_fmt_merge_msg(int merge_title, int merge_summary,
 		rev.ignore_merges = 1;
 		rev.limited = 1;
 
+		if (suffixcmp(out->buf, "\n"))
+			strbuf_addch(out, '\n');
+
 		for (i = 0; i < origins.nr; i++)
 			shortlog(origins.items[i].string, origins.items[i].util,
 					head, &rev, limit, out);
diff --git a/builtin/merge.c b/builtin/merge.c
index bc7e5e7..37ce4f5 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -990,18 +990,22 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		/*
 		 * All the rest are the commits being merged;
 		 * prepare the standard merge summary message to
-		 * used as the merge message.  If remote
+		 * be appended to the given message.  If remote
 		 * is invalid we will die later in the common
 		 * codepath so we discard the error in this
 		 * loop.
 		 */
-		if (!have_message) {
-			for (i = 0; i < argc; i++)
-				merge_name(argv[i], &merge_names);
+		for (i = 0; i < argc; i++)
+			merge_name(argv[i], &merge_names);
+
+		if (have_message && option_log)
+			fmt_merge_msg_shortlog(&merge_names, &merge_msg);
+		else if (!have_message)
 			fmt_merge_msg(option_log, &merge_names, &merge_msg);
-			if (merge_msg.len)
-				strbuf_setlen(&merge_msg, merge_msg.len-1);
-		}
+
+
+		if (!(have_message && !option_log) && merge_msg.len)
+			strbuf_setlen(&merge_msg, merge_msg.len-1);
 	}
 
 	if (head_invalid || !argc)
diff --git a/t/t7604-merge-custom-message.sh b/t/t7604-merge-custom-message.sh
index af53df1..9114785 100755
--- a/t/t7604-merge-custom-message.sh
+++ b/t/t7604-merge-custom-message.sh
@@ -40,7 +40,7 @@ test_expect_success 'merge c2 with a custom message' '
 	test_cmp exp.subject actual
 '
 
-test_expect_failure 'merge --log appends to custom message' '
+test_expect_success 'merge --log appends to custom message' '
 	git reset --hard c1 &&
 	git merge --log -m "$(cat exp.subject)" c2 &&
 	git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
-- 
1.7.1.189.g07419
Previous: Tay Ray Chuan
Message 9 of 9 in “merge: allow --log to append shortlog to -m”
  1. 0/8 merge: allow --log to append shortlog to -mTay Ray Chuan, May 10, 2010
  2. 1/8 t7604-merge-custom-message: shift expected output creationTay Ray Chuan, May 10, 2010
  3. 2/8 t7604-merge-custom-message: show that --log doesn't append to -mTay Ray Chuan, May 10, 2010
  4. 3/8 merge: update commentTay Ray Chuan, May 10, 2010
  5. 4/8 merge: rename variableTay Ray Chuan, May 10, 2010
  6. 5/8 fmt-merge-msg: minor refactor of fmt_merge_msg()Tay Ray Chuan, May 10, 2010
  7. 6/8 fmt-merge-msg: refactor merge title formattingTay Ray Chuan, May 10, 2010
  8. 7/8 fmt-merge-msg: add function to append shortlog onlyTay Ray Chuan, May 10, 2010
  9. 8/8 merge: --log appends shortlog to message if specifiedTay Ray Chuan, May 10, 2010

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.