rebase -r: support merge strategies other than `recursive`

We already support merge strategies in the sequencer, but only for `pick` commands. With this commit, we now also support them in `merge` commands. The approach is simple: if any merge strategy option is specified, or if any merge strategy other than `recursive` is specified, we simply spawn the `git merge` command. Otherwise, we handle the merge in-process just as before. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 31, 2019 at 08:18 UTC e145d993478befd0db6999822aa31d422b283a3b
5 files changed +33 -23
Documentation/git-rebase.txt
-2
@@ -543,8 +543,6 @@ In addition, the following pairs of options are incompatible:
543 * --preserve-merges and --interactive
544 * --preserve-merges and --signoff
545 * --preserve-merges and --rebase-merges
546 - * --rebase-merges and --strategy
547 - * --rebase-merges and --strategy-option
546
547 BEHAVIORAL DIFFERENCES
548 -----------------------
builtin/rebase.c
-9
@@ -1811,15 +1811,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1811 "'--reschedule-failed-exec'"));
1812 }
1813
1814 - if (options.rebase_merges) {
1815 - if (strategy_options.nr)
1816 - die(_("cannot combine '--rebase-merges' with "
1817 - "'--strategy-option'"));
1818 - if (options.strategy)
1819 - die(_("cannot combine '--rebase-merges' with "
1820 - "'--strategy'"));
1821 - }
1822 -
1814 if (!options.root) {
1815 if (argc < 1) {
1816 struct branch *branch;
sequencer.c
+12 -2
@@ -3256,6 +3256,9 @@ static int do_merge(struct repository *r,
3256 struct commit *head_commit, *merge_commit, *i;
3257 struct commit_list *bases, *j, *reversed = NULL;
3258 struct commit_list *to_merge = NULL, **tail = &to_merge;
3259 + const char *strategy = !opts->xopts_nr &&
3260 + (!opts->strategy || !strcmp(opts->strategy, "recursive")) ?
3261 + NULL : opts->strategy;
3262 struct merge_options o;
3263 int merge_arg_len, oneline_offset, can_fast_forward, ret, k;
3264 static struct lock_file lock;
@@ -3404,7 +3407,7 @@ static int do_merge(struct repository *r,
3407 goto leave_merge;
3408 }
3409
3407 - if (to_merge->next) {
3410 + if (strategy || to_merge->next) {
3411 /* Octopus merge */
3412 struct child_process cmd = CHILD_PROCESS_INIT;
3413
@@ -3418,7 +3421,14 @@ static int do_merge(struct repository *r,
3421 cmd.git_cmd = 1;
3422 argv_array_push(&cmd.args, "merge");
3423 argv_array_push(&cmd.args, "-s");
3421 - argv_array_push(&cmd.args, "octopus");
3424 + if (!strategy)
3425 + argv_array_push(&cmd.args, "octopus");
3426 + else {
3427 + argv_array_push(&cmd.args, strategy);
3428 + for (k = 0; k < opts->xopts_nr; k++)
3429 + argv_array_pushf(&cmd.args,
3430 + "-X%s", opts->xopts[k]);
3431 + }
3432 argv_array_push(&cmd.args, "--no-edit");
3433 argv_array_push(&cmd.args, "--no-ff");
3434 argv_array_push(&cmd.args, "--no-log");
t/t3422-rebase-incompatible-options.sh
-10
@@ -76,14 +76,4 @@ test_expect_success REBASE_P \
76 test_must_fail git rebase --preserve-merges --rebase-merges A
77 '
78
79 -test_expect_success '--rebase-merges incompatible with --strategy' '
80 - git checkout B^0 &&
81 - test_must_fail git rebase --rebase-merges -s resolve A
82 -'
83 -
84 -test_expect_success '--rebase-merges incompatible with --strategy-option' '
85 - git checkout B^0 &&
86 - test_must_fail git rebase --rebase-merges -Xignore-space-change A
87 -'
88 -
79 test_done
t/t3430-rebase-merges.sh
+21
@@ -412,4 +412,25 @@ test_expect_success '--continue after resolving conflicts after a merge' '
412 test_path_is_missing .git/MERGE_HEAD
413 '
414
415 +test_expect_success '--rebase-merges with strategies' '
416 + git checkout -b with-a-strategy F &&
417 + test_tick &&
418 + git merge -m "Merge conflicting-G" conflicting-G &&
419 +
420 + : first, test with a merge strategy option &&
421 + git rebase -ir -Xtheirs G &&
422 + echo conflicting-G >expect &&
423 + test_cmp expect G.t &&
424 +
425 + : now, try with a merge strategy other than recursive &&
426 + git reset --hard @{1} &&
427 + write_script git-merge-override <<-\EOF &&
428 + echo overridden$1 >>G.t
429 + git add G.t
430 + EOF
431 + PATH="$PWD:$PATH" git rebase -ir -s override -Xxopt G &&
432 + test_write_lines G overridden--xopt >expect &&
433 + test_cmp expect G.t
434 +'
435 +
436 test_done