Skip to content

Commit 7d718c5

Browse files
newrengitster
authored andcommitted
rebase: flag --apply and --merge as incompatible
Previously, we flagged options which implied --apply as being incompatible with options which implied --merge. But if both options were given explicitly, then we didn't flag the incompatibility. The same is true with --apply and --interactive. Add the check, and add some testcases to verify these are also caught. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1207599 commit 7d718c5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

builtin/rebase.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,9 @@ static int parse_opt_am(const struct option *opt, const char *arg, int unset)
907907
BUG_ON_OPT_NEG(unset);
908908
BUG_ON_OPT_ARG(arg);
909909

910+
if (opts->type != REBASE_UNSPECIFIED && opts->type != REBASE_APPLY)
911+
die(_("apply options and merge options cannot be used together"));
912+
910913
opts->type = REBASE_APPLY;
911914

912915
return 0;
@@ -920,8 +923,10 @@ static int parse_opt_merge(const struct option *opt, const char *arg, int unset)
920923
BUG_ON_OPT_NEG(unset);
921924
BUG_ON_OPT_ARG(arg);
922925

923-
if (!is_merge(opts))
924-
opts->type = REBASE_MERGE;
926+
if (opts->type != REBASE_UNSPECIFIED && opts->type != REBASE_MERGE)
927+
die(_("apply options and merge options cannot be used together"));
928+
929+
opts->type = REBASE_MERGE;
925930

926931
return 0;
927932
}
@@ -935,6 +940,9 @@ static int parse_opt_interactive(const struct option *opt, const char *arg,
935940
BUG_ON_OPT_NEG(unset);
936941
BUG_ON_OPT_ARG(arg);
937942

943+
if (opts->type != REBASE_UNSPECIFIED && opts->type != REBASE_MERGE)
944+
die(_("apply options and merge options cannot be used together"));
945+
938946
opts->type = REBASE_MERGE;
939947
opts->flags |= REBASE_INTERACTIVE_EXPLICIT;
940948

t/t3422-rebase-incompatible-options.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ test_rebase_am_only () {
6767

6868
}
6969

70+
# Check options which imply --apply
7071
test_rebase_am_only --whitespace=fix
7172
test_rebase_am_only -C4
73+
# Also check an explicit --apply
74+
test_rebase_am_only --apply
7275

7376
test_done

0 commit comments

Comments
 (0)