Skip to content

Commit e145d99

Browse files
dschogitster
authored andcommitted
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>
1 parent 4e6023b commit e145d99

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

Documentation/git-rebase.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,6 @@ In addition, the following pairs of options are incompatible:
543543
* --preserve-merges and --interactive
544544
* --preserve-merges and --signoff
545545
* --preserve-merges and --rebase-merges
546-
* --rebase-merges and --strategy
547-
* --rebase-merges and --strategy-option
548546

549547
BEHAVIORAL DIFFERENCES
550548
-----------------------

builtin/rebase.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,15 +1811,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
18111811
"'--reschedule-failed-exec'"));
18121812
}
18131813

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-
18231814
if (!options.root) {
18241815
if (argc < 1) {
18251816
struct branch *branch;

sequencer.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,6 +3256,9 @@ static int do_merge(struct repository *r,
32563256
struct commit *head_commit, *merge_commit, *i;
32573257
struct commit_list *bases, *j, *reversed = NULL;
32583258
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;
32593262
struct merge_options o;
32603263
int merge_arg_len, oneline_offset, can_fast_forward, ret, k;
32613264
static struct lock_file lock;
@@ -3404,7 +3407,7 @@ static int do_merge(struct repository *r,
34043407
goto leave_merge;
34053408
}
34063409

3407-
if (to_merge->next) {
3410+
if (strategy || to_merge->next) {
34083411
/* Octopus merge */
34093412
struct child_process cmd = CHILD_PROCESS_INIT;
34103413

@@ -3418,7 +3421,14 @@ static int do_merge(struct repository *r,
34183421
cmd.git_cmd = 1;
34193422
argv_array_push(&cmd.args, "merge");
34203423
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+
}
34223432
argv_array_push(&cmd.args, "--no-edit");
34233433
argv_array_push(&cmd.args, "--no-ff");
34243434
argv_array_push(&cmd.args, "--no-log");

t/t3422-rebase-incompatible-options.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,4 @@ test_expect_success REBASE_P \
7676
test_must_fail git rebase --preserve-merges --rebase-merges A
7777
'
7878

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-
8979
test_done

t/t3430-rebase-merges.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,25 @@ test_expect_success '--continue after resolving conflicts after a merge' '
412412
test_path_is_missing .git/MERGE_HEAD
413413
'
414414

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+
415436
test_done

0 commit comments

Comments
 (0)