Skip to content

Commit 68aa495

Browse files
newrengitster
authored andcommitted
rebase: implement --merge via the interactive machinery
As part of an ongoing effort to make rebase have more uniform behavior, modify the merge backend to behave like the interactive one, by re-implementing it on top of the latter. Interactive rebases are implemented in terms of cherry-pick rather than the merge-recursive builtin, but cherry-pick also calls into the recursive merge machinery by default and can accept special merge strategies and/or special strategy options. As such, there really is not any need for having both git-rebase--merge and git-rebase--interactive anymore. Delete git-rebase--merge.sh and instead implement it in builtin/rebase.c. This results in a few deliberate but small user-visible changes: * The progress output is modified (see t3406 and t3420 for examples) * A few known test failures are now fixed (see t3421) * bash-prompt during a rebase --merge is now REBASE-i instead of REBASE-m. Reason: The prompt is a reflection of the backend in use; this allows users to report an issue to the git mailing list with the appropriate backend information, and allows advanced users to know where to search for relevant control files. (see t9903) testcase modification notes: t3406: --interactive and --merge had slightly different progress output while running; adjust a test to match the new expectation t3420: these test precise output while running, but rebase--am, rebase--merge, and rebase--interactive all were built on very different commands (am, merge-recursive, cherry-pick), so the tests expected different output for each type. Now we expect --merge and --interactive to have the same output. t3421: --interactive fixes some bugs in --merge! Wahoo! t9903: --merge uses the interactive backend so the prompt expected is now REBASE-i. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c91c944 commit 68aa495

10 files changed

+43
-297
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
/git-rebase--am
125125
/git-rebase--common
126126
/git-rebase--interactive
127-
/git-rebase--merge
128127
/git-rebase--preserve-merges
129128
/git-receive-pack
130129
/git-reflog

Documentation/git-rebase.txt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -504,31 +504,20 @@ See also INCOMPATIBLE OPTIONS below.
504504
INCOMPATIBLE OPTIONS
505505
--------------------
506506

507-
git-rebase has many flags that are incompatible with each other,
508-
predominantly due to the fact that it has three different underlying
509-
implementations:
510-
511-
* one based on linkgit:git-am[1] (the default)
512-
* one based on git-merge-recursive (merge backend)
513-
* one based on linkgit:git-cherry-pick[1] (interactive backend)
514-
515-
Flags only understood by the am backend:
507+
The following options:
516508

517509
* --committer-date-is-author-date
518510
* --ignore-date
519511
* --whitespace
520512
* --ignore-whitespace
521513
* -C
522514

523-
Flags understood by both merge and interactive backends:
515+
are incompatible with the following options:
524516

525517
* --merge
526518
* --strategy
527519
* --strategy-option
528520
* --allow-empty-message
529-
530-
Flags only understood by the interactive backend:
531-
532521
* --[no-]autosquash
533522
* --rebase-merges
534523
* --preserve-merges
@@ -539,7 +528,7 @@ Flags only understood by the interactive backend:
539528
* --edit-todo
540529
* --root when used in combination with --onto
541530

542-
Other incompatible flag pairs:
531+
In addition, the following pairs of options are incompatible:
543532

544533
* --preserve-merges and --interactive
545534
* --preserve-merges and --signoff

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,6 @@ SCRIPT_LIB += git-parse-remote
628628
SCRIPT_LIB += git-rebase--am
629629
SCRIPT_LIB += git-rebase--common
630630
SCRIPT_LIB += git-rebase--preserve-merges
631-
SCRIPT_LIB += git-rebase--merge
632631
SCRIPT_LIB += git-sh-setup
633632
SCRIPT_LIB += git-sh-i18n
634633

builtin/rebase.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void imply_interactive(struct rebase_options *opts, const char *option)
122122
case REBASE_PRESERVE_MERGES:
123123
break;
124124
case REBASE_MERGE:
125-
/* we silently *upgrade* --merge to --interactive if needed */
125+
/* we now implement --merge via --interactive */
126126
default:
127127
opts->type = REBASE_INTERACTIVE; /* implied */
128128
break;
@@ -481,10 +481,6 @@ static int run_specific_rebase(struct rebase_options *opts)
481481
backend = "git-rebase--am";
482482
backend_func = "git_rebase__am";
483483
break;
484-
case REBASE_MERGE:
485-
backend = "git-rebase--merge";
486-
backend_func = "git_rebase__merge";
487-
break;
488484
case REBASE_PRESERVE_MERGES:
489485
backend = "git-rebase--preserve-merges";
490486
backend_func = "git_rebase__preserve_merges";
@@ -1191,6 +1187,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
11911187
}
11921188
}
11931189

1190+
if (options.type == REBASE_MERGE)
1191+
imply_interactive(&options, "--merge");
1192+
11941193
if (options.root && !options.onto_name)
11951194
imply_interactive(&options, "--root without --onto");
11961195

@@ -1220,10 +1219,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12201219
break;
12211220

12221221
if (is_interactive(&options) && i >= 0)
1223-
die(_("cannot combine am options "
1224-
"with interactive options"));
1225-
if (options.type == REBASE_MERGE && i >= 0)
1226-
die(_("cannot combine am options with merge options "));
1222+
die(_("cannot combine am options with either "
1223+
"interactive or merge options"));
12271224
}
12281225

12291226
if (options.signoff) {

git-legacy-rebase.sh

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,15 @@ then
218218
state_dir="$apply_dir"
219219
elif test -d "$merge_dir"
220220
then
221+
type=interactive
221222
if test -d "$merge_dir"/rewritten
222223
then
223224
type=preserve-merges
224225
interactive_rebase=explicit
225226
preserve_merges=t
226227
elif test -f "$merge_dir"/interactive
227228
then
228-
type=interactive
229229
interactive_rebase=explicit
230-
else
231-
type=merge
232230
fi
233231
state_dir="$merge_dir"
234232
fi
@@ -477,6 +475,7 @@ then
477475
test -z "$interactive_rebase" && interactive_rebase=implied
478476
fi
479477

478+
actually_interactive=
480479
if test -n "$interactive_rebase"
481480
then
482481
if test -z "$preserve_merges"
@@ -485,11 +484,12 @@ then
485484
else
486485
type=preserve-merges
487486
fi
488-
487+
actually_interactive=t
489488
state_dir="$merge_dir"
490489
elif test -n "$do_merge"
491490
then
492-
type=merge
491+
interactive_rebase=implied
492+
type=interactive
493493
state_dir="$merge_dir"
494494
else
495495
type=am
@@ -505,13 +505,9 @@ incompatible_opts=$(echo " $git_am_opt " | \
505505
sed -e 's/ -q / /g' -e 's/^ \(.*\) $/\1/')
506506
if test -n "$incompatible_opts"
507507
then
508-
if test -n "$interactive_rebase"
509-
then
510-
die "$(gettext "fatal: cannot combine am options with interactive options")"
511-
fi
512-
if test -n "$do_merge"
508+
if test -n "$actually_interactive" || test "$do_merge"
513509
then
514-
die "$(gettext "fatal: cannot combine am options with merge options")"
510+
die "$(gettext "fatal: cannot combine am options with either interactive or merge options")"
515511
fi
516512
fi
517513

@@ -676,7 +672,7 @@ require_clean_work_tree "rebase" "$(gettext "Please commit or stash them.")"
676672
# but this should be done only when upstream and onto are the same
677673
# and if this is not an interactive rebase.
678674
mb=$(git merge-base "$onto" "$orig_head")
679-
if test -z "$interactive_rebase" && test "$upstream" = "$onto" &&
675+
if test -z "$actually_interactive" && test "$upstream" = "$onto" &&
680676
test "$mb" = "$onto" && test -z "$restrict_revision" &&
681677
# linear history?
682678
! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
@@ -726,6 +722,19 @@ then
726722
GIT_PAGER='' git diff --stat --summary "$mb_tree" "$onto"
727723
fi
728724

725+
if test -z "$actually_interactive" && test "$mb" = "$orig_head"
726+
then
727+
say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")"
728+
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" \
729+
git checkout -q "$onto^0" || die "could not detach HEAD"
730+
# If the $onto is a proper descendant of the tip of the branch, then
731+
# we just fast-forwarded.
732+
git update-ref ORIG_HEAD $orig_head
733+
move_to_original_branch
734+
finish_rebase
735+
exit 0
736+
fi
737+
729738
test -n "$interactive_rebase" && run_specific_rebase
730739

731740
# Detach HEAD and reset the tree
@@ -735,16 +744,6 @@ GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" \
735744
git checkout -q "$onto^0" || die "could not detach HEAD"
736745
git update-ref ORIG_HEAD $orig_head
737746

738-
# If the $onto is a proper descendant of the tip of the branch, then
739-
# we just fast-forwarded.
740-
if test "$mb" = "$orig_head"
741-
then
742-
say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")"
743-
move_to_original_branch
744-
finish_rebase
745-
exit 0
746-
fi
747-
748747
if test -n "$rebase_root"
749748
then
750749
revisions="$onto..$orig_head"

git-rebase--merge.sh

Lines changed: 0 additions & 166 deletions
This file was deleted.

t/t3406-rebase-message.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@ test_expect_success 'setup' '
1717
git tag start
1818
'
1919

20-
cat >expect <<\EOF
21-
Already applied: 0001 A
22-
Already applied: 0002 B
23-
Committed: 0003 Z
24-
EOF
25-
2620
test_expect_success 'rebase -m' '
2721
git rebase -m master >report &&
22+
>expect &&
2823
sed -n -e "/^Already applied: /p" \
2924
-e "/^Committed: /p" report >actual &&
3025
test_cmp expect actual

0 commit comments

Comments
 (0)