Skip to content

Commit c840e1a

Browse files
newrengitster
authored andcommitted
git-rebase: error out when incompatible options passed
git rebase has three different types: am, merge, and interactive, all of which are implemented in terms of separate scripts. am builds on git-am, merge builds on git-merge-recursive, and interactive builds on git-cherry-pick. We make use of features in those lower-level commands in the different rebase types, but those features don't exist in all of the lower level commands so we have a range of incompatibilities. Previously, we just accepted nearly any argument and silently ignored whichever ones weren't implemented for the type of rebase specified. Change this so the incompatibilities are documented, included in the testsuite, and tested for at runtime with an appropriate error message shown. Some exceptions I left out: * --merge and --interactive are technically incompatible since they are supposed to run different underlying scripts, but with a few small changes, --interactive can do everything that --merge can. In fact, I'll shortly be sending another patch to remove git-rebase--merge and reimplement it on top of git-rebase--interactive. * One could argue that --interactive and --quiet are incompatible since --interactive doesn't implement a --quiet mode (perhaps since cherry-pick itself does not implement one). However, the interactive mode is more quiet than the other modes in general with progress messages, so one could argue that it's already quiet. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9929430 commit c840e1a

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

git-rebase.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,24 @@ then
503503
git_format_patch_opt="$git_format_patch_opt --progress"
504504
fi
505505

506+
if test -n "$git_am_opt"; then
507+
incompatible_opts=$(echo " $git_am_opt " | \
508+
sed -e 's/ -q / /g' -e 's/^ \(.*\) $/\1/')
509+
if test -n "$interactive_rebase"
510+
then
511+
if test -n "$incompatible_opts"
512+
then
513+
die "$(gettext "error: cannot combine interactive options (--interactive, --exec, --rebase-merges, --preserve-merges, --keep-empty, --root + --onto) with am options ($incompatible_opts)")"
514+
fi
515+
fi
516+
if test -n "$do_merge"; then
517+
if test -n "$incompatible_opts"
518+
then
519+
die "$(gettext "error: cannot combine merge options (--merge, --strategy, --strategy-option) with am options ($incompatible_opts)")"
520+
fi
521+
fi
522+
fi
523+
506524
if test -n "$signoff"
507525
then
508526
test -n "$preserve_merges" &&
@@ -511,6 +529,23 @@ then
511529
force_rebase=t
512530
fi
513531

532+
if test -n "$preserve_merges"
533+
then
534+
# Note: incompatibility with --signoff handled in signoff block above
535+
# Note: incompatibility with --interactive is just a strong warning;
536+
# git-rebase.txt caveats with "unless you know what you are doing"
537+
test -n "$rebase_merges" &&
538+
die "$(gettext "error: cannot combine '--preserve_merges' with '--rebase-merges'")"
539+
fi
540+
541+
if test -n "$rebase_merges"
542+
then
543+
test -n "$strategy_opts" &&
544+
die "$(gettext "error: cannot combine '--rebase_merges' with '--strategy-option'")"
545+
test -n "$strategy" &&
546+
die "$(gettext "error: cannot combine '--rebase_merges' with '--strategy'")"
547+
fi
548+
514549
if test -z "$rebase_root"
515550
then
516551
case "$#" in

t/t3422-rebase-incompatible-options.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,27 @@ test_expect_success 'setup' '
3333
test_rebase_am_only () {
3434
opt=$1
3535
shift
36-
test_expect_failure "$opt incompatible with --merge" "
36+
test_expect_success "$opt incompatible with --merge" "
3737
git checkout B^0 &&
3838
test_must_fail git rebase $opt --merge A
3939
"
4040

41-
test_expect_failure "$opt incompatible with --strategy=ours" "
41+
test_expect_success "$opt incompatible with --strategy=ours" "
4242
git checkout B^0 &&
4343
test_must_fail git rebase $opt --strategy=ours A
4444
"
4545

46-
test_expect_failure "$opt incompatible with --strategy-option=ours" "
46+
test_expect_success "$opt incompatible with --strategy-option=ours" "
4747
git checkout B^0 &&
4848
test_must_fail git rebase $opt --strategy-option=ours A
4949
"
5050

51-
test_expect_failure "$opt incompatible with --interactive" "
51+
test_expect_success "$opt incompatible with --interactive" "
5252
git checkout B^0 &&
5353
test_must_fail git rebase $opt --interactive A
5454
"
5555

56-
test_expect_failure "$opt incompatible with --exec" "
56+
test_expect_success "$opt incompatible with --exec" "
5757
git checkout B^0 &&
5858
test_must_fail git rebase $opt --exec 'true' A
5959
"
@@ -70,17 +70,17 @@ test_expect_success '--preserve-merges incompatible with --signoff' '
7070
test_must_fail git rebase --preserve-merges --signoff A
7171
'
7272

73-
test_expect_failure '--preserve-merges incompatible with --rebase-merges' '
73+
test_expect_success '--preserve-merges incompatible with --rebase-merges' '
7474
git checkout B^0 &&
7575
test_must_fail git rebase --preserve-merges --rebase-merges A
7676
'
7777

78-
test_expect_failure '--rebase-merges incompatible with --strategy' '
78+
test_expect_success '--rebase-merges incompatible with --strategy' '
7979
git checkout B^0 &&
8080
test_must_fail git rebase --rebase-merges -s resolve A
8181
'
8282

83-
test_expect_failure '--rebase-merges incompatible with --strategy-option' '
83+
test_expect_success '--rebase-merges incompatible with --strategy-option' '
8484
git checkout B^0 &&
8585
test_must_fail git rebase --rebase-merges -Xignore-space-change A
8686
'

0 commit comments

Comments
 (0)