fmt-merge-msg -m to override merge title
Since v1.7.1.1~23^2 (merge: --log appends shortlog to message if specified, 2010-05-11), the fmt-merge-msg backend supports custom text to override the merge title "Merge <foo> into <bar>". Expose this functionality for scripted callers. Example: git fmt-merge-msg --log -m \ "$(printf '%s\n' \ "Merge branch 'api-cleanup' into feature" \ '' \ 'This is to use a few functions refactored for this purpose.' )" <.git/FETCH_HEAD Cc: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Aug 17, 2010 at 18:00 UTC
2102440c17f990fcb5c9269459c39c6312e80d1c
3 files changed
+55
-4
Documentation/git-fmt-merge-msg.txt
+7
-2
@@ -9,8 +9,8 @@ git-fmt-merge-msg - Produce a merge commit message
9
SYNOPSIS
10
--------
11
[verse]
12
-'git fmt-merge-msg' [--log | --no-log] <$GIT_DIR/FETCH_HEAD
13
-'git fmt-merge-msg' [--log | --no-log] -F <file>
12
+'git fmt-merge-msg' [-m <message>] [--log | --no-log] <$GIT_DIR/FETCH_HEAD
13
+'git fmt-merge-msg' [-m <message>] [--log | --no-log] -F <file>
14
15
DESCRIPTION
16
-----------
@@ -38,6 +38,11 @@ OPTIONS
38
Synonyms to --log and --no-log; these are deprecated and will be
39
removed in the future.
40
41
+-m <message>::
42
+--message <message>::
43
+ Use <message> instead of the branch names for the first line
44
+ of the log message. For use with `--log`.
45
+
46
-F <file>::
47
--file <file>::
48
Take the list of merged objects from <file> instead of
builtin/fmt-merge-msg.c
+16
-2
@@ -7,7 +7,7 @@
7
#include "string-list.h"
8
9
static const char * const fmt_merge_msg_usage[] = {
10
- "git fmt-merge-msg [--log|--no-log] [--file <file>]",
10
+ "git fmt-merge-msg [-m <message>] [--log|--no-log] [--file <file>]",
11
NULL
12
};
13
@@ -319,11 +319,14 @@ int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out) {
319
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
320
{
321
const char *inpath = NULL;
322
+ const char *message = NULL;
323
struct option options[] = {
324
OPT_BOOLEAN(0, "log", &merge_summary, "populate log with the shortlog"),
325
{ OPTION_BOOLEAN, 0, "summary", &merge_summary, NULL,
326
"alias for --log (deprecated)",
327
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
328
+ OPT_STRING('m', "message", &message, "text",
329
+ "use <text> as start of message"),
330
OPT_FILENAME('F', "file", &inpath, "file to read from"),
331
OPT_END()
332
};
@@ -337,6 +340,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
340
0);
341
if (argc > 0)
342
usage_with_options(fmt_merge_msg_usage, options);
343
+ if (message && !merge_summary) {
344
+ char nl = '\n';
345
+ write_in_full(STDOUT_FILENO, message, strlen(message));
346
+ write_in_full(STDOUT_FILENO, &nl, 1);
347
+ return 0;
348
+ }
349
350
if (inpath && strcmp(inpath, "-")) {
351
in = fopen(inpath, "r");
@@ -346,7 +355,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
355
356
if (strbuf_read(&input, fileno(in), 0) < 0)
357
die_errno("could not read input file");
349
- ret = fmt_merge_msg(merge_summary, &input, &output);
358
+ if (message) {
359
+ strbuf_addstr(&output, message);
360
+ ret = fmt_merge_msg_shortlog(&input, &output);
361
+ } else {
362
+ ret = fmt_merge_msg(merge_summary, &input, &output);
363
+ }
364
if (ret)
365
return ret;
366
write_in_full(STDOUT_FILENO, output.buf, output.len);
t/t6200-fmt-merge-msg.sh
+32
@@ -129,6 +129,38 @@ test_expect_success '[merge] summary/log configuration' '
129
test_cmp expected actual2
130
'
131
132
+test_expect_success 'fmt-merge-msg -m' '
133
+ echo "Sync with left" >expected &&
134
+ cat >expected.log <<-EOF &&
135
+ Sync with left
136
+
137
+ * ${apos}left${apos} of $(pwd):
138
+ Left #5
139
+ Left #4
140
+ Left #3
141
+ Common #2
142
+ Common #1
143
+ EOF
144
+
145
+ test_might_fail git config --unset merge.log &&
146
+ test_might_fail git config --unset merge.summary &&
147
+ git checkout master &&
148
+ git fetch "$(pwd)" left &&
149
+ git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
150
+ git fmt-merge-msg --log -m "Sync with left" \
151
+ <.git/FETCH_HEAD >actual.log &&
152
+ git config merge.log true &&
153
+ git fmt-merge-msg -m "Sync with left" \
154
+ <.git/FETCH_HEAD >actual.log-config &&
155
+ git fmt-merge-msg --no-log -m "Sync with left" \
156
+ <.git/FETCH_HEAD >actual.nolog &&
157
+
158
+ test_cmp expected actual &&
159
+ test_cmp expected.log actual.log &&
160
+ test_cmp expected.log actual.log-config &&
161
+ test_cmp expected actual.nolog
162
+'
163
+
164
test_expect_success 'setup: expected shortlog for two branches' '
165
cat >expected <<-EOF
166
Merge branches ${apos}left${apos} and ${apos}right${apos}