From: Karthik Nayak Date: Tue, 01 Sep 2026 11:53:23 GMT Subject: Re: [PATCH v2 3/8] checkout: validate stage and merge option compatibility in checkout_paths() Message-ID: In-Reply-To: <20260830204835.1040408-4-gitster@pobox.com> Junio C Hamano writes: > In checkout_main(), checking that no more than one of --ours/--theirs, > --force, and --merge is specified is performed when pathspecs are > present, before dispatching to checkout_paths(). Checking out a > branch does not use index stages, so this validation belongs in > checkout_paths(). > > Move the incompatibility check from checkout_main() into > checkout_paths(). > > Signed-off-by: Junio C Hamano > --- > builtin/checkout.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/builtin/checkout.c b/builtin/checkout.c > index 14542626e9..e3d23256e2 100644 > --- a/builtin/checkout.c > +++ b/builtin/checkout.c > @@ -591,6 +591,10 @@ static int checkout_paths(const struct checkout_opts *opts, > die(_("'%s', '%s', or '%s' cannot be used when checking out of a tree"), > "--merge", "--ours", "--theirs"); > > + if (1 < !!opts->writeout_stage + !!opts->force + !!opts->merge) > + die(_("git checkout: --ours/--theirs, --force and --merge are incompatible when\n" > + "checking out of the index.")); > + Doesn't checkout_paths() also get triggered when using '--patch', shouldn't this go below... > if (opts->patch_mode) { > enum add_p_mode patch_mode; > struct interactive_options interactive_opts = { > ...this block? As the original checked for `opts->patchspec.nr` > @@ -2063,11 +2067,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix, > > opts->pathspec.recursive = 1; > > - if (opts->pathspec.nr) { > - if (1 < !!opts->writeout_stage + !!opts->force + !!opts->merge) > - die(_("git checkout: --ours/--theirs, --force and --merge are incompatible when\n" > - "checking out of the index.")); > - } else { > + if (!opts->pathspec.nr) { > if (opts->accept_pathspec && !opts->empty_pathspec_ok && > !opts->patch_mode) /* patch mode is special */ > die(_("you must specify path(s) to restore")); > -- > 2.55.0-884-g76cf8659c2