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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Jan 25, 2023 at 04:03 UTC
7d718c552b8fa084f2d5bb9c3e3872cfe558a1eb
2 files changed
+13
-2
builtin/rebase.c
+10
-2
@@ -907,6 +907,9 @@ static int parse_opt_am(const struct option *opt, const char *arg, int unset)
907
BUG_ON_OPT_NEG(unset);
908
BUG_ON_OPT_ARG(arg);
909
910
+ if (opts->type != REBASE_UNSPECIFIED && opts->type != REBASE_APPLY)
911
+ die(_("apply options and merge options cannot be used together"));
912
+
913
opts->type = REBASE_APPLY;
914
915
return 0;
@@ -920,8 +923,10 @@ static int parse_opt_merge(const struct option *opt, const char *arg, int unset)
923
BUG_ON_OPT_NEG(unset);
924
BUG_ON_OPT_ARG(arg);
925
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;
930
931
return 0;
932
}
@@ -935,6 +940,9 @@ static int parse_opt_interactive(const struct option *opt, const char *arg,
940
BUG_ON_OPT_NEG(unset);
941
BUG_ON_OPT_ARG(arg);
942
943
+ if (opts->type != REBASE_UNSPECIFIED && opts->type != REBASE_MERGE)
944
+ die(_("apply options and merge options cannot be used together"));
945
+
946
opts->type = REBASE_MERGE;
947
opts->flags |= REBASE_INTERACTIVE_EXPLICIT;
948
t/t3422-rebase-incompatible-options.sh
+3
@@ -67,7 +67,10 @@ test_rebase_am_only () {
67
68
}
69
70
+# Check options which imply --apply
71
test_rebase_am_only --whitespace=fix
72
test_rebase_am_only -C4
73
+# Also check an explicit --apply
74
+test_rebase_am_only --apply
75
76
test_done