merge: allow reading the merge commit message from a file
This is consistent with `git commit` which, like `git merge`, supports passing the commit message via `-m <msg>` and, unlike `git merge` before this patch, via `-F <file>`. It is useful to allow this for scripted use, or for the upcoming patch to allow (re-)creating octopus merges in `git rebase --rebase-merges`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Dec 22, 2017 at 15:10 UTC
920f22e6bc2ddc28b1d70eb8167fe17f0f1601eb
2 files changed
+41
-1
Documentation/git-merge.txt
+9
-1
@@ -12,7 +12,7 @@ SYNOPSIS
12
'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
13
[-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
14
[--[no-]allow-unrelated-histories]
15
- [--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]
15
+ [--[no-]rerere-autoupdate] [-m <msg>] [-F <file>] [<commit>...]
16
'git merge' --abort
17
'git merge' --continue
18
@@ -75,6 +75,14 @@ The 'git fmt-merge-msg' command can be
75
used to give a good default for automated 'git merge'
76
invocations. The automated message can include the branch description.
77
78
+-F <file>::
79
+--file=<file>::
80
+ Read the commit message to be used for the merge commit (in
81
+ case one is created).
82
++
83
+If `--log` is specified, a shortlog of the commits being merged
84
+will be appended to the specified message.
85
+
86
--[no-]rerere-autoupdate::
87
Allow the rerere mechanism to update the index with the
88
result of auto-conflict resolution if possible.
builtin/merge.c
+32
@@ -111,6 +111,35 @@ static int option_parse_message(const struct option *opt,
111
return 0;
112
}
113
114
+static int option_read_message(struct parse_opt_ctx_t *ctx,
115
+ const struct option *opt, int unset)
116
+{
117
+ struct strbuf *buf = opt->value;
118
+ const char *arg;
119
+
120
+ if (unset)
121
+ BUG("-F cannot be negated");
122
+
123
+ if (ctx->opt) {
124
+ arg = ctx->opt;
125
+ ctx->opt = NULL;
126
+ } else if (ctx->argc > 1) {
127
+ ctx->argc--;
128
+ arg = *++ctx->argv;
129
+ } else
130
+ return opterror(opt, "requires a value", 0);
131
+
132
+ if (buf->len)
133
+ strbuf_addch(buf, '\n');
134
+ if (ctx->prefix && !is_absolute_path(arg))
135
+ arg = prefix_filename(ctx->prefix, arg);
136
+ if (strbuf_read_file(buf, arg, 0) < 0)
137
+ return error(_("could not read file '%s'"), arg);
138
+ have_message = 1;
139
+
140
+ return 0;
141
+}
142
+
143
static struct strategy *get_strategy(const char *name)
144
{
145
int i;
@@ -228,6 +257,9 @@ static struct option builtin_merge_options[] = {
257
OPT_CALLBACK('m', "message", &merge_msg, N_("message"),
258
N_("merge commit message (for a non-fast-forward merge)"),
259
option_parse_message),
260
+ { OPTION_LOWLEVEL_CALLBACK, 'F', "file", &merge_msg, N_("path"),
261
+ N_("read message from file"), PARSE_OPT_NONEG,
262
+ (parse_opt_cb *) option_read_message },
263
OPT__VERBOSITY(&verbosity),
264
OPT_BOOL(0, "abort", &abort_current_merge,
265
N_("abort the current in-progress merge")),