From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: "Mathias Rav" <m@git.strova.dk>,
git@vger.kernel.org, "Phillip Wood" <phillip.wood@dunelm.org.uk>,
"John Cai" <johncai86@gmail.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"brian m. carlson" <sandals@crustytoothpaste.net>
Subject: Re: [PATCH] merge-file: fix BUG when --object-id is used in a worktree
Date: Tue, 10 Mar 2026 13:01:53 -0700 [thread overview]
Message-ID: <xmqqh5qntpvy.fsf@gitster.g> (raw)
In-Reply-To: <abATPiRUczb8fe4t@pks.im> (Patrick Steinhardt's message of "Tue, 10 Mar 2026 13:49:02 +0100")
Patrick Steinhardt <ps@pks.im> writes:
> On Tue, Mar 10, 2026 at 11:46:01AM +0000, Mathias Rav wrote:
>
> Which commit is this patch based on? It doesn't apply in its current
> form on top of "master" since at least 8600b4ec9e (merge-file: honor
> merge.conflictStyle outside of a repository, 2026-02-07). Please rebase
> the patch.
This applies cleanly relative to v2.53.0. Generally, it is a
recommended practice to fork from the latest stable release in many
projects, so I do not mind it too much.
>> diff --git a/builtin/merge-file.c b/builtin/merge-file.c
>> index 46775d0c79..a8768c6e0c 100644
>> --- a/builtin/merge-file.c
>> +++ b/builtin/merge-file.c
>> @@ -110,7 +110,7 @@ int cmd_merge_file(int argc,
>> return error_errno("failed to redirect stderr to /dev/null");
>> }
>>
>> - if (object_id)
>> + if (object_id && !repo)
>> setup_git_directory();
Good. I suspect we would want to check !repo first, though. The
idea here is
(1) We know we need to support running "git merge-file" outside a
repository, so the git potty may have called us with !repo (aka
RUN_SETUP_GENTLY);
(2) But we do need to make sure we have a repository in some case.
We happen to have only one case, i.e., when "--object-id"
option is in use, but that condition may grow in the future.
So in the longer run, we'd better prepared for the "has the user
gave us the object_id option?" part to grow over time, which would
mean
if (!repo &&
(object_id || another_option || yet_another ...))
setup_git_directory();
would be easier to handle.
>> for (i = 0; i < 3; i++) {
>
> Okay, makes sense. Makes me wonder whether we have other cases of the
> same error class.
While I agree that the second call to setup_git_directory() that
triggered this patch is pointless, I also wish that the function
were more robust. I wonder if there is a clean way to make it
idempotent.
>> diff --git a/t/t6403-merge-file.sh b/t/t6403-merge-file.sh
>> index 06ab4d7aed..60cc43775f 100755
>> --- a/t/t6403-merge-file.sh
>> +++ b/t/t6403-merge-file.sh
>> @@ -506,6 +506,15 @@ test_expect_success '--object-id fails without repository' '
>> grep "not a git repository" err
>> '
>>
>> +test_expect_success 'run inside worktree with --object-id' '
>> + empty="$(test_oid empty_blob)" &&
>> + git worktree add work &&
>> + (cd work && git merge-file --object-id $empty $empty $empty) >actual &&
>
> This can be written without a subshell by saying `git -C work
> merge-file`.
Yup, that would make the test even better.
next prev parent reply other threads:[~2026-03-10 20:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 11:46 [PATCH] merge-file: fix BUG when --object-id is used in a worktree Mathias Rav
2026-03-10 12:35 ` Karthik Nayak
2026-03-10 12:49 ` Patrick Steinhardt
2026-03-10 20:01 ` Junio C Hamano [this message]
2026-03-11 6:44 ` [PATCH v2] " Mathias Rav
2026-03-11 7:18 ` Kristoffer Haugsbakk
2026-03-11 11:14 ` Kristoffer Haugsbakk
2026-03-11 17:26 ` Junio C Hamano
2026-03-11 20:16 ` Kristoffer Haugsbakk
2026-03-18 19:40 ` Junio C Hamano
2026-03-18 19:16 ` Mathias Rav
2026-03-18 19:45 ` Junio C Hamano
2026-03-10 13:34 ` [PATCH] " Kristoffer Haugsbakk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqh5qntpvy.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=johncai86@gmail.com \
--cc=m@git.strova.dk \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
--cc=sandals@crustytoothpaste.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox