]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase: flag --apply and --merge as incompatible
authorElijah Newren <newren@gmail.com>
Wed, 25 Jan 2023 04:03:46 +0000 (04:03 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Jan 2023 17:20:52 +0000 (09:20 -0800)
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>
builtin/rebase.c
t/t3422-rebase-incompatible-options.sh

index c111b89e137a3ce41c231caf661d32e7f51f9b8a..b742cc8fb5c1d600e3ff33982dff577eedecd9c1 100644 (file)
@@ -907,6 +907,9 @@ static int parse_opt_am(const struct option *opt, const char *arg, int unset)
        BUG_ON_OPT_NEG(unset);
        BUG_ON_OPT_ARG(arg);
 
+       if (opts->type != REBASE_UNSPECIFIED && opts->type != REBASE_APPLY)
+           die(_("apply options and merge options cannot be used together"));
+
        opts->type = REBASE_APPLY;
 
        return 0;
@@ -920,8 +923,10 @@ static int parse_opt_merge(const struct option *opt, const char *arg, int unset)
        BUG_ON_OPT_NEG(unset);
        BUG_ON_OPT_ARG(arg);
 
-       if (!is_merge(opts))
-               opts->type = REBASE_MERGE;
+       if (opts->type != REBASE_UNSPECIFIED && opts->type != REBASE_MERGE)
+           die(_("apply options and merge options cannot be used together"));
+
+       opts->type = REBASE_MERGE;
 
        return 0;
 }
@@ -935,6 +940,9 @@ static int parse_opt_interactive(const struct option *opt, const char *arg,
        BUG_ON_OPT_NEG(unset);
        BUG_ON_OPT_ARG(arg);
 
+       if (opts->type != REBASE_UNSPECIFIED && opts->type != REBASE_MERGE)
+           die(_("apply options and merge options cannot be used together"));
+
        opts->type = REBASE_MERGE;
        opts->flags |= REBASE_INTERACTIVE_EXPLICIT;
 
index 9da39cd91c2ce2e4fa75971c06190e1e157b699b..9b9e78479f6f6ef286ff3a8e14b860ad056fe99a 100755 (executable)
@@ -67,7 +67,10 @@ test_rebase_am_only () {
 
 }
 
+# Check options which imply --apply
 test_rebase_am_only --whitespace=fix
 test_rebase_am_only -C4
+# Also check an explicit --apply
+test_rebase_am_only --apply
 
 test_done