From: Junio C Hamano <gitster@pobox.com>
To: "Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Alessio Attilio <attilio.alessio@protonmail.com>
Subject: Re: [PATCH v2 2/2] status: warn about stale submodule URLs
Date: Fri, 27 Nov 2026 10:11:57 -0800 [thread overview]
Message-ID: <xmqqecc69maa.fsf@gitster.g> (raw)
In-Reply-To: <b0dd21100ccfe4411ccc1237fdb7ddedb66075e8.1795796162.git.gitgitgadget@gmail.com> (Alessio Attilio via GitGitGadget's message of "Fri, 27 Nov 2026 16:16:02 +0000")
"Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Alessio Attilio <attilio.alessio@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 <attilio.alessio@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.
> diff --git a/submodule.c b/submodule.c
> index f9ca99c5c8..5d0018d032 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -299,6 +299,9 @@ char *resolve_submodule_url(struct repository *repo, const char *url,
> char *remoteurl, *resolved_url;
> struct strbuf remotesb = STRBUF_INIT;
>
> + if (!starts_with_dot_dot_slash(url) && !starts_with_dot_slash(url))
> + return xstrdup(url);
> +
> strbuf_addf(&remotesb, "remote.%s.url", remote);
> if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {
> if (!quiet)
The split made it harder to spot, but this addition forces the helper
function to return if 'url' is not relative, yet we have already spent
cycles calling repo_default_remote() to compute 'remote', paying the
cost to call repo_config() and to look up the HEAD branch. Perhaps move
the unnecessary call to repo_default_remote() after this early return,
before the first use of 'remote'?
> diff --git a/wt-status.c b/wt-status.c
> index 238bb48643..be6902c9dd 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> ...
> +static int submodule_has_custom_remote_url(struct repository *repo,
> + const char *path,
> + const char *gitmodules_url,
> + const char *config_url)
> +{
> + struct repository subrepo = { 0 };
> + const struct string_list *remote_urls = NULL;
> + const char *remote;
> + const char *remote_url;
> + char *key, *up_path, *config_remote_url, *gitmodules_remote_url;
> + int error_code, ret = 0;
> +
> + if (!is_submodule_populated_gently(path, &error_code))
> + return 0;
> +
> + if (repo_submodule_init(&subrepo, repo, path,
> + null_oid(repo->hash_algo)) < 0) {
> + repo_clear(&subrepo);
> + return 0;
> + }
> +
> + remote = repo_default_remote(&subrepo);
> +
> + key = xstrfmt("remote.%s.url", remote);
> + if (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&
> + remote_urls->nr == 1) {
> + remote_url = remote_urls->items[0].string;
Can the '.string' member be NULL here, either by mistake or by malice?
We have two strcmp() calls below to compare this with two other URLs,
and either would segfault.
Perhaps use repo_config_get_string_multi() instead? I do not know what
error behavior you are aiming for here, but the 'string' variant would
barf on an entry like '[remote "origin"] url' (valueless true), which
would give you NULL in the '.string' member.
> + 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.
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.
* 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.
> +static void wt_status_check_submodule_urls(struct wt_status *s)
> +{
> + int i;
> +
> + if (s->status_format != STATUS_FORMAT_LONG &&
> + s->status_format != STATUS_FORMAT_NONE)
> + return;
Mental note. Restricting this only to the "long" and "none" formats
somehow feels arbitrary. Perhaps the callers ought to have more direct
and finer control, and tell the callchain leading to wt_status_print()
to refrain from calling this helper at all when the callers do not want
the warnings (like "git commit" preparing the commit template). That
would allow us to free this helper from making this arbitrary choice.
> + key = xstrfmt("submodule.%s.url", sub->name);
> + if (repo_config_get_value(s->repo, key, &config_url)) {
> + free(key);
> + continue;
> + }
> + free(key);
> +
> + gitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);
> + if (strcmp(config_url, gitmodules_url) &&
This is another potential NULL dereference due to the use of
repo_config_get_value() instead of _get_string(), no? The same
mechanism, the same segfault.
> void wt_status_print(struct wt_status *s)
> {
> + wt_status_check_submodule_urls(s);
> +
> trace2_data_intmax("status", s->repo, "count/changed", s->change.nr);
> trace2_data_intmax("status", s->repo, "count/untracked",
> s->untracked.nr);
wt_status_print() is not just for "git status", but is also used to
generate commit templates. Checking only '.status_format' at the
beginning of wt_status_check_submodule_urls() means that these extra
checks are done and warnings are leaked into unrelated commands.
In builtin/commit.c, cmd_commit() sets '.commit_template' to 1 and
'status_format' to STATUS_FORMAT_NONE, and prepare_to_commit() calls
run_status() with 'nowarn' set to 1 when populating COMMIT_EDITMSG.
Similarly, fill_commit_message() in builtin/history.c leaves
'.status_format' at STATUS_FORMAT_NONE, sets '.commit_template' to 1,
and calls wt_status_print() after collecting a diff between two trees.
As a result, running "git commit" with an editor or "git history" emits
this status warning to stderr.
Instead of excluding individual cases (like "commit or history can call
and .commit_template or .nowarn may be set by them"), can we make sure
we call the extra check only when "git status" is calling the wt-status
machinery to prevent it?
There are also a few design questions.
* Should "git status <pathspec>" limit its check to submodules under
the given directory?
* Should "git status --ignore-submodules" bypass the new check
altogether?
* Should "git status -s" and "git status --porcelain" detect the
misconfiguration like the normal "git status"?
My tentative answers to the above are all "yes", but the design needs to
be discussed, the choices justified, and the result documented in both
the proposed commit log message and in the "git status --help"
documentation.
Thanks.
next prev parent reply other threads:[~2026-11-27 18:11 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 10:21 [PATCH] status: warn about stale submodule URLs Alessio Attilio via GitGitGadget
2026-11-27 13:41 ` D. Ben Knoble
2026-11-27 16:16 ` [PATCH v2 0/2] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
2026-11-27 16:16 ` [PATCH v2 1/2] submodule: prepare URL helpers for reuse Alessio Attilio via GitGitGadget
2026-11-27 16:16 ` [PATCH v2 2/2] status: warn about stale submodule URLs Alessio Attilio via GitGitGadget
2026-11-27 18:11 ` Junio C Hamano [this message]
2026-11-27 20:35 ` ATTILIO ALESSIO
2026-11-30 15:46 ` D. Ben Knoble
2026-11-27 21:27 ` [PATCH v3 0/2] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
2026-11-27 21:27 ` [PATCH v3 1/2] submodule: prepare URL helpers for reuse Alessio Attilio via GitGitGadget
2026-11-28 3:38 ` Junio C Hamano
2026-11-27 21:27 ` [PATCH v3 2/2] status: warn about stale submodule URLs Alessio Attilio via GitGitGadget
2026-11-28 4:08 ` Junio C Hamano
2026-11-28 4:19 ` [PATCH v3 0/2] status: report when submodule URLs are out of sync Junio C Hamano
2026-11-28 16:53 ` [PATCH v4 0/3] " Alessio Attilio via GitGitGadget
2026-11-28 16:53 ` [PATCH v4 1/3] submodule: move URL helpers into submodule.c Alessio Attilio via GitGitGadget
2026-11-30 15:54 ` D. Ben Knoble
2026-11-28 16:53 ` [PATCH v4 2/3] submodule: make URL resolution repository-aware Alessio Attilio via GitGitGadget
2026-11-30 15:56 ` D. Ben Knoble
2026-11-28 16:53 ` [PATCH v4 3/3] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
2026-11-29 15:42 ` Junio C Hamano
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=xmqqecc69maa.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=attilio.alessio@protonmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
/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