@matheusbsbs / matheus-bagliano / commits / f0ecac2b70
Fork 0

merge: --log appends shortlog to message if specified

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed May 11, 2010 at 01:17 UTC f0ecac2b70bf6b44b89dfa493abd2f544010b1eb
4 files changed +21 -9
Documentation/git-merge.txt
+6 -1
@@ -58,7 +58,12 @@ include::merge-options.txt[]
58
59 -m <msg>::
60 Set the commit message to be used for the merge commit (in
61 - case one is created). The 'git fmt-merge-msg' command can be
61 + case one is created).
62 +
63 + If `--log` is specified, a shortlog of the commits being merged
64 + will be appended to the specified message.
65 +
66 + The 'git fmt-merge-msg' command can be
67 used to give a good default for automated 'git merge'
68 invocations.
69
builtin/fmt-merge-msg.c
+3
@@ -298,6 +298,9 @@ static int do_fmt_merge_msg(int merge_title, int merge_summary,
298 rev.ignore_merges = 1;
299 rev.limited = 1;
300
301 + if (suffixcmp(out->buf, "\n"))
302 + strbuf_addch(out, '\n');
303 +
304 for (i = 0; i < origins.nr; i++)
305 shortlog(origins.items[i].string, origins.items[i].util,
306 head, &rev, limit, out);
builtin/merge.c
+11 -7
@@ -981,18 +981,22 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
981 /*
982 * All the rest are the commits being merged;
983 * prepare the standard merge summary message to
984 - * used as the merge message. If remote
984 + * be appended to the given message. If remote
985 * is invalid we will die later in the common
986 * codepath so we discard the error in this
987 * loop.
988 */
989 - if (!have_message) {
990 - for (i = 0; i < argc; i++)
991 - merge_name(argv[i], &merge_names);
989 + for (i = 0; i < argc; i++)
990 + merge_name(argv[i], &merge_names);
991 +
992 + if (have_message && option_log)
993 + fmt_merge_msg_shortlog(&merge_names, &merge_msg);
994 + else if (!have_message)
995 fmt_merge_msg(option_log, &merge_names, &merge_msg);
993 - if (merge_msg.len)
994 - strbuf_setlen(&merge_msg, merge_msg.len-1);
995 - }
996 +
997 +
998 + if (!(have_message && !option_log) && merge_msg.len)
999 + strbuf_setlen(&merge_msg, merge_msg.len-1);
1000 }
1001
1002 if (head_invalid || !argc)
t/t7604-merge-custom-message.sh
+1 -1
@@ -40,7 +40,7 @@ test_expect_success 'merge c2 with a custom message' '
40 test_cmp exp.subject actual
41 '
42
43 -test_expect_failure 'merge --log appends to custom message' '
43 +test_expect_success 'merge --log appends to custom message' '
44 git reset --hard c1 &&
45 git merge --log -m "$(cat exp.subject)" c2 &&
46 git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&