On Fri, Nov 27, 2026 at 1:12 PM Junio C Hamano <gits…@pobox.com> wrote:
>
> "Alessio Attilio via GitGitGadget" <gitg…@gmail.com> writes:
>
> > From: Alessio Attilio <atti…@protonmail.com>
> >
> > When a submodule URL changes in .gitmodules, the cached
> > submodule.<name>.url in the superproject config can stay stale. Warn
> > in git status so users can run git submodule sync before a later
> > submodule operation uses the outdated URL.
> >
> > Resolve relative URLs using the same paths as git submodule sync.
> > Avoid warning when the submodule remote indicates a local
> > customization that sync would overwrite.
> >
> > Signed-off-by: Alessio Attilio <atti…@protonmail.com>
> > ---
>
> Surfacing stale submodule configuration in "git status" is a very useful
> improvement. Like Ben noted, splitting the helper extraction out into a
> preparatory commit made the series easier to follow.
>
> It would help to explain in the proposed log message why three URLs are
> compared and under what condition, and which status formats emit the
> warning.
Indeed, I was minded of "reviewing is a discussion"
(https://lore.kernel.org/git/2026…@pobox.com/)
and "good manners" being to discuss before sending off v2
(https://lore.kernel.org/git/xmqq…@gitster.g/).
> > + up_path = get_submodule_up_path(path);
> > + config_remote_url = resolve_submodule_url(repo, config_url,
> > + up_path, 1);
> > + gitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,
> > + up_path, 1);
> > + /*
> > + * The submodule's remote URL may be a local fork. If it matches
> > + * neither the old cached URL nor the new .gitmodules URL, leave it
> > + * alone; syncing would overwrite that customization.
> > + */
> > + ret = strcmp(remote_url, config_remote_url) != 0 &&
> > + strcmp(remote_url, gitmodules_remote_url) != 0;
>
> Renaming of new/old may address one of the points of confusion Ben had.
I think so: it now seems that "remote_url" is the one from the
submodule (e.g., git -C sub remote -v), config_*url is the cached URL,
and gitmodules_*url is, well, the .gitmodules URL.
> When the superproject's own default remote URL is relative, doesn't
> this logic break?
>
> In wt_status_check_submodule_urls() we see below, 'gitmodules_url' was
> already computed by resolving sub->url against the superproject's
> default remote with 'up_path' set to NULL. Likewise, 'config_url' from
> submodule.<name>.url in .git/config was already resolved once with
> 'up_path' set to NULL when init_submodule() or sync_submodule() wrote
> it.
>
> Passing already-resolved URLs into resolve_submodule_url() again smells
> fishy. There are a few ways I can think of that this can break. I may
> be misreading the code flow, and these may be no issue, or there may be
> other issues.
I mentioned the double-resolution in passing before, thanks for making
the potential issues (which I only thought of for performance) more
explicit.
> * When the superproject has "remote.origin.url = a/b" (relative without
> "./" or "../") and .gitmodules has "../mod1", sync_submodule() stores
> "a/mod1" in submodule.module.url and "../a/mod1" in the submodule's
> remote.origin.url.
>
> submodule_has_custom_remote_url() calls resolve_submodule_url() on
> "a/mod1". It hits the early return without prepending 'up_path', so
> 'config_remote_url' is "a/mod1" instead of "../a/mod1" and fails to
> match.
>
> * When the superproject has "remote.origin.url = ../a/b", .gitmodules
> initially has "submodule.module.url = ../mod1", and the user runs
> "git submodule sync". In sync_submodule(), relative_url() stores
> "../a/mod1" in submodule.module.url and "../../a/mod1" in the
> submodule's remote.origin.url.
>
> If submodule.module.url in .gitmodules then changes to "../mod2",
> wt_status_check_submodule_urls() sets 'gitmodules_remote_url' to
> "../a/mod2". Inside submodule_has_custom_remote_url(), both
> "../a/mod1" and "../a/mod2" still start with "../", so
> resolve_submodule_url() resolves them a second time against "../a/b".
>
> Wouldn't the result be "../../a/a/mod1" and "../../a/a/mod2" in such
> a case?
>
> Neither matches "../../a/mod1", so submodule_has_custom_remote_url()
> returns 1 and suppresses the warning even though the submodule remote
> was never customized. The new test in t7508 used "../source-parent"
> with only one path component after "..", where the second resolution
> happened to be a no-op, so it may not have noticed the breakage.
>
> In order to match what sync_submodule() does, 'gitmodules_remote_url'
> should be computed from the raw 'sub->url', not from 'gitmodules_url',
> no? For 'config_remote_url', we do not want to run relative_url() again
> on 'config_url', I think. You only need to prepend 'up_path', or
> something, no? I didn't think this one through, so take it with a huge
> grain of salt.
Thanks,
Ben