From 501e3bab99da75eada3e2d6ef5257a3c44dd1ae4 Mon Sep 17 00:00:00 2001 From: Kyle Zhao Date: Fri, 11 Nov 2022 23:45:14 +0000 Subject: 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 " -- " | git merge-tree --stdin does a merge of b1 and b2, and uses b3 as the merge-base. Signed-off-by: Kyle Zhao Signed-off-by: Taylor Blau --- builtin/merge-tree.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'builtin/merge-tree.c') diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 62c6d43cdb..330f779e8b 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -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); -- cgit v1.2.3