From: Junio C Hamano <gitster@pobox.com>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: <git@vger.kernel.org>, Jeff King <peff@peff.net>,
Martin Wilck <mwilck@suse.com>,
Adrian Schroeter <adrian@suse.com>
Subject: Re: [PATCH v2 2/2] read-cache: drop submodule check from add_to_cache()
Date: Sat, 15 Nov 2025 11:57:17 -0800 [thread overview]
Message-ID: <xmqqseefdq76.fsf@gitster.g> (raw)
In-Reply-To: <20251115005818.2271557-2-sandals@crustytoothpaste.net> (brian m. carlson's message of "Sat, 15 Nov 2025 00:58:18 +0000")
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
> From: Jeff King <peff@peff.net>
>
> In add_to_cache(), we treat any directories as submodules, and complain
> if we can't resolve their HEAD. This call to resolve_gitlink_ref() was
> added by f937bc2f86 (add: error appropriately on repository with no
> commits, 2019-04-09), with the goal of improving the error message for
> empty repositories.
>
> But we already resolve the submodule HEAD in index_path(), which is
> where we find the actual oid we're going to use. Resolving it again here
> introduces some downsides:
>
> 1. It's more work, since we have to open up the submodule repository's
> files twice.
>
> 2. There are call paths that get to index_path() without going through
> add_to_cache(). For instance, we'd want a similar informative
> message if "git diff empty" finds that it can't resolve the
> submodule's HEAD. (In theory we can also get there through
> update-index, but AFAICT it refuses to consider directories as
> submodules at all, and just complains about them).
>
> 3. The resolution in index_path() catches more errors that we don't
> handle here. In particular, it will validate that the object format
> for the submodule matches that of the superproject. This isn't a
> bug, since our call in add_to_cache() throws away the oid it gets
> without looking at it. But it certainly caused confusion for me
> when looking at where the object-format check should go.
>
> So instead of resolving the submodule HEAD in add_to_cache(), let's just
> teach the call in index_path() to actually produce an error message
> (which it already does for other cases). That's probably what f937bc2f86
> should have done in the first place, and it gives us a single point of
> resolution when adding a submodule to the index.
>
> The resulting output is slightly more verbose, as we propagate the error
> up the call stack, but I think that's OK (and again, matches many other
> errors we get when indexing fails).
>
> I've left the text of the error message as-is, though it is perhaps
> overly specific. There are many reasons that resolving the submodule
> HEAD might fail, though outside of corruption or system errors it is
> probably most likely that the submodule HEAD is simply on an unborn
> branch.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
A tangent.
You can (!) place your own sign-off after Peff's, as you would want
to certify
c. The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
of the DCO, but it seems that it is optional (which I did not know
about---the explanation in SubmittingPatches stops at "Indeed you
are encouraged to do so" without making it a requirement).
next prev parent reply other threads:[~2025-11-15 19:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 12:58 git fails to checkout SHA1 submodule in SHA256 repo with --depth=1 Martin Wilck
2025-11-12 16:32 ` Junio C Hamano
2025-11-12 23:37 ` brian m. carlson
2025-11-13 10:15 ` Martin Wilck
2025-11-13 22:51 ` brian m. carlson
2025-11-13 22:57 ` Martin Wilck
2025-11-14 22:55 ` Marc Branchaud
2025-11-15 20:14 ` brian m. carlson
2025-11-12 23:54 ` [PATCH] object-file: disallow adding submodules of different hash algo brian m. carlson
2025-11-13 3:26 ` Jeff King
2025-11-13 3:56 ` Jeff King
2025-11-13 16:29 ` Junio C Hamano
2025-11-14 23:26 ` brian m. carlson
2025-11-15 1:53 ` Jeff King
2025-11-13 23:15 ` brian m. carlson
2025-11-15 0:58 ` [PATCH v2 1/2] " brian m. carlson
2025-11-15 0:58 ` [PATCH v2 2/2] read-cache: drop submodule check from add_to_cache() brian m. carlson
2025-11-15 19:57 ` Junio C Hamano [this message]
2025-11-15 20:06 ` brian m. carlson
2025-11-15 19:53 ` [PATCH v2 1/2] object-file: disallow adding submodules of different hash algo Junio C Hamano
2025-11-17 8:53 ` Martin Wilck
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=xmqqseefdq76.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=adrian@suse.com \
--cc=git@vger.kernel.org \
--cc=mwilck@suse.com \
--cc=peff@peff.net \
--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;
as well as URLs for NNTP newsgroup(s).