Re: [PATCH 1/3] submodule: return an error instead of BUG() for an unexpected git dir
- From
Adrian Ratiu <adrian.ratiu@collabora.com>
- Date
- Nov 18, 2026, 19:33 UTC
- Message-ID
- <874idej5o8.fsf@collabora.com>
- In-Reply-To
- <xmqqecci54tw.fsf@gitster.g>
On Wed, 18 Nov 2026, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> Adrian Ratiu <adrian.ratiu@collabora.com> writes: > >> 9cf8547320 (clone: prevent clashing git dirs when cloning submodule in >> parallel, 2024-01-28) added a caller that passes a path read from the >> gitfile, which made the BUG() reachable. >> >> Return an error instead of BUG(), so the command dies with the same >> "refusing to create/use ..." message as when the submodulePathConfig >> extension is enabled. > > Makes sense. > > The above archaeology was quite illuminating. It seems that the > offending commit came without the usual on-list reviews as part of > the Git 2.39.4/2.45.1 updates.
Yeah, I wasn't part of discussions on this, so I don't have the full context either, but I do think switching BUG() -> error() makes sense.
Show 29 quoted lines
>> Reported-by: Andreas Wendleder <gonsolo@gmail.com>
>> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
>> ---
>> submodule.c | 8 ++++++--
>> t/t7450-bad-git-dotfiles.sh | 14 ++++++++++++++
>> 2 files changed, 20 insertions(+), 2 deletions(-)
>>
>> diff --git a/submodule.c b/submodule.c
>> index 1302c11ddf..d00d820d42 100644
>> --- a/submodule.c
>> +++ b/submodule.c
>> @@ -2410,10 +2410,14 @@ static int validate_submodule_legacy_git_dir(char *git_dir, const char *submodul
>> BUG("validate_submodule_git_dir() must be called with "
>> "extensions.submodulePathConfig disabled.");
>>
>> + /*
>> + * The git dir may come from a gitfile on disk, so a mismatch is
>> + * not necessarily a bug in the caller.
>> + */
>
> "is not necessarily a bug" is not incorrect per se, but it is only
> relevant in the context of turning what was originally a BUG() into
> a "return error()". If this had been written to return an error
> instead of calling BUG() from the beginning, you would not have
> phrased the comment that way.
>
> If this if() statement needs a comment, we should state why these
> two are expected to match, or why it is an error if they do not
> match.Good point.
I'll drop the comment addition in v2 since we don't need to over-explain the BUG() -> error() transition.