Re: [PATCH v2 3/8] checkout: validate stage and merge option compatibility in checkout_paths()
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Sep 1, 2026, 11:53 UTC
- Message-ID
- <CAOLa=ZTA=xmPnEkMsncwd=3iZA62nsXq0jk-KiUr=GU7OUhh1Q@mail.gmail.com>
- In-Reply-To
- <20260830204835.1040408-4-gitster@pobox.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 26 quoted lines
> 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 <gitster@pobox.com>
> ---
> 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`
Show 15 quoted lines
> @@ -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