]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase -r: support merge strategies other than `recursive`
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 31 Jul 2019 15:18:47 +0000 (08:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 31 Jul 2019 19:24:07 +0000 (12:24 -0700)
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>
Documentation/git-rebase.txt
builtin/rebase.c
sequencer.c
t/t3422-rebase-incompatible-options.sh
t/t3430-rebase-merges.sh

index 5e4e9276479c94e8a73ea4cd72819d50ec7b5e91..bc620c44e93916cc48d9154ab344a0050e62e125 100644 (file)
@@ -543,8 +543,6 @@ In addition, the following pairs of options are incompatible:
  * --preserve-merges and --interactive
  * --preserve-merges and --signoff
  * --preserve-merges and --rebase-merges
- * --rebase-merges and --strategy
- * --rebase-merges and --strategy-option
 
 BEHAVIORAL DIFFERENCES
 -----------------------
index 74a60e8c83f7b2bc9433eb853bada2ecb090400b..625f50c63779afb39cf78ba82dd43a155c86ecd6 100644 (file)
@@ -1811,15 +1811,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                              "'--reschedule-failed-exec'"));
        }
 
-       if (options.rebase_merges) {
-               if (strategy_options.nr)
-                       die(_("cannot combine '--rebase-merges' with "
-                             "'--strategy-option'"));
-               if (options.strategy)
-                       die(_("cannot combine '--rebase-merges' with "
-                             "'--strategy'"));
-       }
-
        if (!options.root) {
                if (argc < 1) {
                        struct branch *branch;
index 334de145421c1fe1b23dd4713f1f2acedd2f78d8..d228448cd8c54a1d8412d4d7d1658ae4945293cc 100644 (file)
@@ -3256,6 +3256,9 @@ static int do_merge(struct repository *r,
        struct commit *head_commit, *merge_commit, *i;
        struct commit_list *bases, *j, *reversed = NULL;
        struct commit_list *to_merge = NULL, **tail = &to_merge;
+       const char *strategy = !opts->xopts_nr &&
+               (!opts->strategy || !strcmp(opts->strategy, "recursive")) ?
+               NULL : opts->strategy;
        struct merge_options o;
        int merge_arg_len, oneline_offset, can_fast_forward, ret, k;
        static struct lock_file lock;
@@ -3404,7 +3407,7 @@ static int do_merge(struct repository *r,
                goto leave_merge;
        }
 
-       if (to_merge->next) {
+       if (strategy || to_merge->next) {
                /* Octopus merge */
                struct child_process cmd = CHILD_PROCESS_INIT;
 
@@ -3418,7 +3421,14 @@ static int do_merge(struct repository *r,
                cmd.git_cmd = 1;
                argv_array_push(&cmd.args, "merge");
                argv_array_push(&cmd.args, "-s");
-               argv_array_push(&cmd.args, "octopus");
+               if (!strategy)
+                       argv_array_push(&cmd.args, "octopus");
+               else {
+                       argv_array_push(&cmd.args, strategy);
+                       for (k = 0; k < opts->xopts_nr; k++)
+                               argv_array_pushf(&cmd.args,
+                                                "-X%s", opts->xopts[k]);
+               }
                argv_array_push(&cmd.args, "--no-edit");
                argv_array_push(&cmd.args, "--no-ff");
                argv_array_push(&cmd.args, "--no-log");
index a5868ea152f94108418175a4c8af583462c09fce..50e7960702da4fa0306818f305f5d735f2292f53 100755 (executable)
@@ -76,14 +76,4 @@ test_expect_success REBASE_P \
        test_must_fail git rebase --preserve-merges --rebase-merges A
 '
 
-test_expect_success '--rebase-merges incompatible with --strategy' '
-       git checkout B^0 &&
-       test_must_fail git rebase --rebase-merges -s resolve A
-'
-
-test_expect_success '--rebase-merges incompatible with --strategy-option' '
-       git checkout B^0 &&
-       test_must_fail git rebase --rebase-merges -Xignore-space-change A
-'
-
 test_done
index 42ba5b9f0981b2b7ce98e1c5c55012ef61757bab..8ea6ff3548444c03209771dba7768812854430d0 100755 (executable)
@@ -412,4 +412,25 @@ test_expect_success '--continue after resolving conflicts after a merge' '
        test_path_is_missing .git/MERGE_HEAD
 '
 
+test_expect_success '--rebase-merges with strategies' '
+       git checkout -b with-a-strategy F &&
+       test_tick &&
+       git merge -m "Merge conflicting-G" conflicting-G &&
+
+       : first, test with a merge strategy option &&
+       git rebase -ir -Xtheirs G &&
+       echo conflicting-G >expect &&
+       test_cmp expect G.t &&
+
+       : now, try with a merge strategy other than recursive &&
+       git reset --hard @{1} &&
+       write_script git-merge-override <<-\EOF &&
+       echo overridden$1 >>G.t
+       git add G.t
+       EOF
+       PATH="$PWD:$PATH" git rebase -ir -s override -Xxopt G &&
+       test_write_lines G overridden--xopt >expect &&
+       test_cmp expect G.t
+'
+
 test_done