merge-tree.c: allow specifying the merge-base when --stdin is passed
The previous commit added a `--merge-base` option in order to allow
using a specified merge-base for the merge. Extend the input accepted
by `--stdin` to also allow a specified merge-base with each merge
requested. For example:
printf "<b3> -- <b1> <b2>" | git merge-tree --stdin
does a merge of b1 and b2, and uses b3 as the merge-base.
Signed-off-by: Kyle Zhao <kylezhao@tencent.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
This commit is contained in:
@@ -557,12 +557,29 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix)
|
||||
while (strbuf_getline_lf(&buf, stdin) != EOF) {
|
||||
struct strbuf **split;
|
||||
int result;
|
||||
const char *input_merge_base = NULL;
|
||||
|
||||
split = strbuf_split(&buf, ' ');
|
||||
if (!split[0] || !split[1] || split[2])
|
||||
if (!split[0] || !split[1])
|
||||
die(_("malformed input line: '%s'."), buf.buf);
|
||||
strbuf_rtrim(split[0]);
|
||||
result = real_merge(&o, merge_base, split[0]->buf, split[1]->buf, prefix);
|
||||
strbuf_rtrim(split[1]);
|
||||
|
||||
/* parse the merge-base */
|
||||
if (!strcmp(split[1]->buf, "--")) {
|
||||
input_merge_base = split[0]->buf;
|
||||
}
|
||||
|
||||
if (input_merge_base && split[2] && split[3] && !split[4]) {
|
||||
strbuf_rtrim(split[2]);
|
||||
strbuf_rtrim(split[3]);
|
||||
result = real_merge(&o, input_merge_base, split[2]->buf, split[3]->buf, prefix);
|
||||
} else if (!input_merge_base && !split[2]) {
|
||||
result = real_merge(&o, NULL, split[0]->buf, split[1]->buf, prefix);
|
||||
} else {
|
||||
die(_("malformed input line: '%s'."), buf.buf);
|
||||
}
|
||||
|
||||
if (result < 0)
|
||||
die(_("merging cannot continue; got unclean result of %d"), result);
|
||||
strbuf_list_free(split);
|
||||
|
||||
Reference in New Issue
Block a user