Re: [PATCH v2 3/8] checkout: validate stage and merge option compatibility in checkout_paths()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 1, 2026, 17:47 UTC
- Message-ID
- <xmqqld9ksw26.fsf@gitster.g>
- In-Reply-To
- <CAOLa=ZTA=xmPnEkMsncwd=3iZA62nsXq0jk-KiUr=GU7OUhh1Q@mail.gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
Show 18 quoted lines
>> @@ -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`Sorry, I do not quite understand your question.
The "if (opts->patch_mode)" block indeed appears in checkout_paths() and when "--patch" is given the control comes here. Are you worried about
git restore --patch --merge --theirs
triggering the option compatibility check, instead of ignoring it and directly jumping into the patch mode?
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