Git development
 help / color / mirror / Atom feed
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 v3 2/2] status: warn about stale submodule URLs
Date: Fri, 27 Nov 2026 20:08:57 -0800	[thread overview]
Message-ID: <xmqqv75hy4va.fsf@gitster.g> (raw)
In-Reply-To: <9dc62830755b06ca2a95d307dd0b593d2a77c536.1795814853.git.gitgitgadget@gmail.com> (Alessio Attilio via GitGitGadget's message of "Fri, 27 Nov 2026 21:27:33 +0000")

"Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com> writes:

> Resolve relative URLs using the same paths as git submodule sync, and
> do not resolve the already-resolved cached URL a second time. Emit the
> warning on standard error for long, short, and porcelain status output,
> limited to submodules matched by the pathspec. Do not emit it when
> --ignore-submodules is given or when the wt-status machinery is used by
> another command.

The three-URL check now avoids double-resolving config_url and
gitmodules_url when the superproject remote URL is relative, and
switches from the get_value() config readers to the get_string()
family.

The check at the beginning of wt_status_check_submodule_urls() has
been replaced with different logic, but I thought that we agreed to
move the check to the caller, wt_status_print(), to avoid calling
this new helper?  There also is a glaring bug in the updated logic
for the "--ignore-submodules" check.

Other than these, the issues in the remainder of the patch I saw in
an earlier round got much better.

> diff --git a/submodule.c b/submodule.c
> index 3eab799f1f..24775b21b7 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -296,9 +296,13 @@ char *resolve_submodule_url(struct repository *repo, const char *rel_url,
>  			    const char *up_path, int quiet)
>  {
>  	char *remoteurl, *resolved_url;
> -	const char *remote = repo_default_remote(repo);
> +	const char *remote;
>  	struct strbuf remotesb = STRBUF_INIT;
>  
> +	if (!starts_with_dot_dot_slash(rel_url) && !starts_with_dot_slash(rel_url))
> +		return xstrdup(rel_url);

It would make resolve_submodule_url() self-contained if you moved this
early return into the preparatory patch (the one you will split out of
[1/2] for the "repository aware" step).  It would allow callers in
builtin/submodule--helper.c to drop duplicate checks if desired, too.

Also, starts_with_dot_dot_slash() assumes 'rel_url' is non-NULL;
wt_status_check_submodule_urls() checks sub->url first, so current
callers are safe, though an explicit NULL guard or doc comment in
submodule.h may be worth considering to prevent future surprises.

> diff --git a/wt-status.c b/wt-status.c
> index 238bb48643..5bcbe634df 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -2692,8 +2696,124 @@ static void wt_porcelain_v2_print(struct wt_status *s)
>  	}
>  }
>  
> +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);

In builtin/submodule--helper.c, sync_submodule() picks which submodule
remote to update by calling get_default_remote_submodule().

That helper checks repo_remote_from_url() against the resolved
.gitmodules URL first and falls back to repo_default_remote(&subrepo)
only if no remote matches.  If a submodule has both a customized
'origin' remote and an 'upstream' remote that matches what .gitmodules
has, sync_submodule() updates 'upstream' without touching 'origin',
whereas submodule_has_custom_remote_url() checks only 'origin' and
suppresses the warning.

Checking only the default remote is reasonable for the common
single-remote case, though it is worth keeping this subtle difference in
mind.

> +static void wt_status_check_submodule_urls(struct wt_status *s)
> +{
> +	int i;
> +
> +	if (!s->check_submodule_urls || s->ignore_submodule_arg)
> +		return;

I do not think checking .ignore_submodule_arg like this helps.  It is of
type "const char *", so I assume it holds string values like "none" that
you will get when

    git status --ignore-submodules=none

is run, right?  You do not want to punt in such a case.

Comparing against wt_longstatus_print() in wt-status.c shows how other
status checks handle this:

    if (s->submodule_summary &&
        (!s->ignore_submodule_arg ||
         strcmp(s->ignore_submodule_arg, "all"))) {

Using

    if (!s->check_submodule_urls ||
        (s->ignore_submodule_arg &&
         !strcmp(s->ignore_submodule_arg, "all")))
            return;

here keeps '--ignore-submodules=none' (and =dirty/=untracked) warning as
expected, and matches "suppressed when '--ignore-submodules=all' (or
bare '--ignore-submodules') is specified" in the docs and commit log.

  reply	other threads:[~2026-11-28  4:09 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
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 [this message]
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=xmqqv75hy4va.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