From: Junio C Hamano Date: Fri, 28 Aug 2026 22:52:01 GMT Subject: [PATCH 3/8] checkout: validate stage and merge option compatibility in checkout_paths() Message-ID: <20260828225206.310500-4-gitster@pobox.com> In-Reply-To: <20260828225206.310500-1-gitster@pobox.com> 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.")); + if (opts->patch_mode) { enum add_p_mode patch_mode; struct interactive_options interactive_opts = { @@ -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