Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Adrian Ratiu <adrian.ratiu@collabora.com>
Cc: git@vger.kernel.org,  Andreas Wendleder <gonsolo@gmail.com>,
	 Phillip Wood <phillip.wood@dunelm.org.uk>,
	 Patrick Steinhardt <ps@pks.im>
Subject: Re: [PATCH 1/3] submodule: return an error instead of BUG() for an unexpected git dir
Date: Wed, 18 Nov 2026 11:15:23 -0800	[thread overview]
Message-ID: <xmqqecci54tw.fsf@gitster.g> (raw)
In-Reply-To: <20261118163249.1693361-2-adrian.ratiu@collabora.com> (Adrian Ratiu's message of "Wed, 18 Nov 2026 18:32:47 +0200")

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.

> 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.

>  	if (len <= suffix_len || (p = git_dir + len - suffix_len)[-1] != '/' ||
>  	    strcmp(p, submodule_name))
> -		BUG("submodule name '%s' not a suffix of git dir '%s'",
> -		    submodule_name, git_dir);
> +		return error(_("submodule name '%s' not a suffix of git dir '%s'"),
> +			     submodule_name, git_dir);

  reply	other threads:[~2026-11-18 19:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 22:51 submodule: linked-worktree submodule hits BUG() in validate_submodule_legacy_git_dir() Andreas Wendleder
2026-11-17 17:45 ` Adrian Ratiu
2026-11-18 16:32 ` [PATCH 0/3] submodule: support linked worktrees in recursive checkout Adrian Ratiu
2026-11-18 16:32   ` [PATCH 1/3] submodule: return an error instead of BUG() for an unexpected git dir Adrian Ratiu
2026-11-18 19:15     ` Junio C Hamano [this message]
2026-11-18 16:32   ` [PATCH 2/3] submodule: only suggest submodulePathConfig when it is disabled Adrian Ratiu
2026-11-18 16:32   ` [PATCH 3/3] submodule: accept a linked worktree as the submodule's git dir Adrian Ratiu

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=xmqqecci54tw.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=adrian.ratiu@collabora.com \
    --cc=git@vger.kernel.org \
    --cc=gonsolo@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=ps@pks.im \
    /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