Skip to content

Commit 59eb604

Browse files
committed
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 <[email protected]>
1 parent e333175 commit 59eb604

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

Documentation/git-merge.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SYNOPSIS
1212
'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
1313
[-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
1414
[--[no-]allow-unrelated-histories]
15-
[--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]
15+
[--[no-]rerere-autoupdate] [-m <msg>] [-F <file>] [<commit>...]
1616
'git merge' --abort
1717
'git merge' --continue
1818

@@ -75,6 +75,14 @@ The 'git fmt-merge-msg' command can be
7575
used to give a good default for automated 'git merge'
7676
invocations. The automated message can include the branch description.
7777

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+
7886
--[no-]rerere-autoupdate::
7987
Allow the rerere mechanism to update the index with the
8088
result of auto-conflict resolution if possible.

builtin/merge.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,38 @@ static int option_parse_message(const struct option *opt,
111111
return 0;
112112
}
113113

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("--no-file?!?");
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_complete_line(buf);
134+
strbuf_addch(buf, '\n');
135+
}
136+
if (ctx->prefix && !is_absolute_path(arg))
137+
arg = prefix_filename(ctx->prefix, arg);
138+
if (strbuf_read_file(buf, arg, 0) < 0)
139+
return error(_("could not read file '%s'"), arg);
140+
strbuf_complete_line(buf);
141+
have_message = 1;
142+
143+
return 0;
144+
}
145+
114146
static struct strategy *get_strategy(const char *name)
115147
{
116148
int i;
@@ -228,6 +260,9 @@ static struct option builtin_merge_options[] = {
228260
OPT_CALLBACK('m', "message", &merge_msg, N_("message"),
229261
N_("merge commit message (for a non-fast-forward merge)"),
230262
option_parse_message),
263+
{ OPTION_LOWLEVEL_CALLBACK, 'F', "file", &merge_msg, N_("path"),
264+
N_("read message from file"), PARSE_OPT_NONEG,
265+
(parse_opt_cb *) option_read_message },
231266
OPT__VERBOSITY(&verbosity),
232267
OPT_BOOL(0, "abort", &abort_current_merge,
233268
N_("abort the current in-progress merge")),

0 commit comments

Comments
 (0)