Skip to content

status: report when submodule URLs are out of sync - #2509

Open
kairosci wants to merge 3 commits into
git:masterfrom
kairosci:topic/status-submodule-url-sync
Open

kairosci wants to merge 3 commits into
git:masterfrom
kairosci:topic/status-submodule-url-sync

Conversation

@kairosci

@kairosci kairosci commented Nov 26, 2026 •

Copy link
Copy Markdown

When a submodule URL changes in .gitmodules, the corresponding URL in the superproject's .git/config may keep pointing at the old location. This series makes git status warn about that mismatch and suggest git submodule sync.

The warning resolves relative URLs as git submodule sync does. It also suppresses the warning when the populated submodule has a custom remote URL that a sync would overwrite.

The series is split into:

  1. submodule: move URL helpers to submodule.c
  2. submodule: make URL resolution repository-aware
  3. status: warn about stale submodule URLs

Changes since v2:

  • Keep the helper relocation in a preparatory commit.
  • Move repository-aware URL resolution into its own commit.
  • Keep test output inside its fixture directory.

Closes gitgitgadget#565

@gitgitgadget-git

Copy link
Copy Markdown

There are issues in commit 13cf5d9:
status: warn about stale submodule URLs

  • Commit checks stopped - the message is too short
  • Commit not signed off

@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch 2 times, most recently from ac1bc78 to cf91014 Compare November 26, 2026 23:44
@kairosci kairosci changed the title status: warn about stale submodule URLs status: report when submodule URLs are out of sync Nov 26, 2026
@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit cf91014:
status: report when submodule URLs are out of sync

  • Lines in the body of the commit messages should be wrapped between 60 and 76 characters.
    Indented lines, and lines without whitespace, are exempt

@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch 3 times, most recently from b722330 to 1edd1a3 Compare November 26, 2026 23:48
@kairosci

Copy link
Copy Markdown
Author

/preview

@gitgitgadget-git

Copy link
Copy Markdown

Preview email sent as pull.2509.git.git.1795737094364.gitgitgadget@gmail.com

@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch from 1edd1a3 to b3d5d91 Compare November 27, 2026 00:05
@kairosci

Copy link
Copy Markdown
Author

/preview

@gitgitgadget-git

Copy link
Copy Markdown

Preview email sent as pull.2509.git.git.1795738226271.gitgitgadget@gmail.com

@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch from 2cf6387 to 528258e Compare November 27, 2026 10:17
@kairosci

Copy link
Copy Markdown
Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2509.git.git.1795774880142.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2509/kairosci/topic/status-submodule-url-sync-v1

To fetch this version to local tag pr-git-2509/kairosci/topic/status-submodule-url-sync-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2509/kairosci/topic/status-submodule-url-sync-v1

@gitgitgadget-git

Copy link
Copy Markdown

There are issues in commit 0d1682d:
status: clarify submodule URL comparisons

  • Commit checks stopped - the message is too short
  • Commit not signed off

@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch from 0d1682d to e84f7f1 Compare November 27, 2026 15:46
@gitgitgadget-git

Copy link
Copy Markdown

There are issues in commit 543e4c3:
submodule: expose URL resolution helpers

  • Commit checks stopped - the message is too short
  • Commit not signed off

@gitgitgadget-git

Copy link
Copy Markdown

There are issues in commit e84f7f1:
status: warn about stale submodule URLs

  • Commit checks stopped - the message is too short
  • Commit not signed off

@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch from e84f7f1 to 37ee443 Compare November 27, 2026 15:57
@gitgitgadget-git

Copy link
Copy Markdown

There are issues in commit 9b9e28d:
submodule: expose URL resolution helpers

  • Commit checks stopped - the message is too short
  • Commit not signed off

@gitgitgadget-git

Copy link
Copy Markdown

There are issues in commit 37ee443:
status: warn about stale submodule URLs

  • Commit checks stopped - the message is too short
  • Commit not signed off

@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch from 37ee443 to e088292 Compare November 27, 2026 16:00
@gitgitgadget-git

Copy link
Copy Markdown

There are issues in commit 7ae0356:
submodule: expose URL resolution helpers

  • Commit checks stopped - the message is too short
  • Commit not signed off

@gitgitgadget-git

Copy link
Copy Markdown

There are issues in commit e088292:
status: warn about stale submodule URLs

  • Commit checks stopped - the message is too short
  • Commit not signed off

@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch from e088292 to b0dd211 Compare November 27, 2026 16:14
@kairosci

Copy link
Copy Markdown
Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Preview email sent as pull.2509.v3.git.git.1795798903.gitgitgadget@gmail.com

@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch 3 times, most recently from e341a2b to 9dc6283 Compare November 27, 2026 21:25
@kairosci

Copy link
Copy Markdown
Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2509.v3.git.git.1795814853.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2509/kairosci/topic/status-submodule-url-sync-v3

To fetch this version to local tag pr-git-2509/kairosci/topic/status-submodule-url-sync-v3:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2509/kairosci/topic/status-submodule-url-sync-v3

Comment thread submodule.c
const char *up_path, int quiet)
{
const char *remote = repo_default_remote(repo);
char *remoteurl, *resolved_url;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATTILIO ALESSIO wrote on the Git mailing list (how to reply to this email):

"Junio C Hamano" <gitster@pobox.com> writes:

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

Will do.  I will explain in the commit message why the three URLs are
compared, under what condition the warning triggers, and which status
formats emit it.

> Perhaps move the unnecessary call to repo_default_remote() after this
> early return, before the first use of 'remote'?

Good catch.  I will move repo_default_remote() below the early return
for non-relative URLs.

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

Agreed.  I will switch to the *_get_string*() helpers (or guard against
valueless entries) so we never pass NULL to strcmp().

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

You are right: the values passed to submodule_has_custom_remote_url()
have already been resolved once, so resolving them again produces wrong
paths when the superproject's own remote URL is relative.  I will
rework this to resolve the raw .gitmodules URL and prepend up_path to
the cached config URL, matching git submodule sync.

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

Yes, gating the check so it runs only when invoked from git status is
much cleaner and avoids leaking warnings into commit templates.

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

I agree with "yes" on all three:

- Respecting <pathspec> keeps the warning scoped to the paths the user
  asked about.
- Respecting --ignore-submodules matches user expectations when they
  explicitly ask status to ignore submodule state.
- Emitting the warning on stderr in -s and --porcelain modes ensures
  users and scripts still get the diagnostic without affecting machine-
  readable stdout output.

I will update the implementation, tests, commit message, and git-status
documentation accordingly for the next reroll.

Thanks,
Alessio

Comment thread builtin/submodule--helper.c Resolved
@@ -46,35 +46,6 @@
typedef void (*each_submodule_fn)(const struct cache_entry *list_item,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

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

> From: Alessio Attilio <attilio.alessio@protonmail.com>
>
> Move the relative submodule URL resolver and the helper that computes
> the path back to the superproject from builtin/submodule--helper.c to
> submodule.c so they can be shared with git status.
>
> Pass the repository explicitly to the resolver instead of relying on
> the_repository, and update existing callers to use the shared helpers.

This preparatory extraction may make the next patch easier to read.

Removing the get_default_remote() wrapper that has only one caller, and
calling repo_default_remote(repo) directly is safe too, because
repo_default_remote() returns a pointer owned by repo->remote_state (or
a static "origin" string) and repo_config_get_string() does not
invalidate remote_state before relative_url() runs.

> Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
> ---
>  builtin/submodule--helper.c | 63 ++++++-------------------------------
>  submodule.c                 | 41 ++++++++++++++++++++++++
>  submodule.h                 |  3 ++
>  3 files changed, 54 insertions(+), 53 deletions(-)

While this takes 'repo', the fallback when remote.<remote>.url is unset
still calls xgetcwd().  For current callers ('submodule--helper' and
'git status' under RUN_SETUP | NEED_WORK_TREE), the working directory is
already the superproject worktree root, so behavior is preserved.

Still, if a future caller passes a 'struct repository *' for another
worktree or subrepository, xgetcwd() will resolve relative URLs against
the process working directory instead of repo->worktree.

Using

    remoteurl = repo->worktree ? xstrdup(repo->worktree) : xgetcwd();

may make the helper genuinely repository-aware, perhaps?

In any case, the "repository-aware" change should be a separate step,
outside the "move code around" step, right?

> diff --git a/submodule.h b/submodule.h
> index 1a465a1208..2028f272c4 100644
> --- a/submodule.h
> +++ b/submodule.h
> @@ -62,6 +62,9 @@ int is_tree_submodule_active(struct repository *repo,
>  			     const struct object_id *treeish_name,
>  			     const char *path);
>  int is_submodule_active(struct repository *repo, const char *path);
> +char *resolve_submodule_url(struct repository *repo, const char *url,
> +			    const char *up_path, int quiet);
> +char *get_submodule_up_path(const char *path);

The header names the second parameter 'url', while the definition in
submodule.c names it 'rel_url'.

It would help to add comments above the declarations of these two
functions and to document that callers free the returned string, that
'up_path' may be NULL, and that get_submodule_up_path() expects a
non-empty 'path' (because it indexes path[strlen(path) - 1]).  It would
match the surrounding declarations in this header file.

@@ -22,6 +22,12 @@ are what you _would_ commit by running `git commit`; the second and
third are what you _could_ commit by running `git add` before running

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

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

@gitgitgadget-git

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

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

> When a submodule URL changes in .gitmodules, the corresponding URL in the
> superproject's .git/config may keep pointing at the old location. This
> series makes git status warn about that mismatch and suggest git submodule
> sync.
>
> The warning resolves relative URLs as git submodule sync does. It also
> suppresses the warning when the populated submodule has a custom remote URL
> that a sync would overwrite.
>
> The series is split into:
>
>  1. submodule: move URL helpers to submodule.c
>  2. submodule: make URL resolution repository-aware
>  3. status: warn about stale submodule URLs

The cover letter describes a three-patch split, and the changelog notes
moving repository-aware URL resolution into its own commit, yet this v3
series contains two patches where patch 1/2 both relocates the helpers
and takes 'struct repository *repo' (matching the two-patch range-diff
against v2).  Sent before finishing the work and checking if the result
matches the cover letter description, perhaps?

@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch 2 times, most recently from 6fe6477 to 49e5628 Compare November 28, 2026 11:28
@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch from 49e5628 to 619101d Compare November 28, 2026 14:49
@kairosci

Copy link
Copy Markdown
Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2509.v4.git.git.1795884822.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2509/kairosci/topic/status-submodule-url-sync-v4

To fetch this version to local tag pr-git-2509/kairosci/topic/status-submodule-url-sync-v4:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2509/kairosci/topic/status-submodule-url-sync-v4

@gitgitgadget-git

Copy link
Copy Markdown

This branch is now known as aa/status-submodule-url-sync.

@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch from 619101d to 972d8ad Compare November 29, 2026 16:14
Move the relative submodule URL resolver and the helper that
computes the path back to the superproject from
builtin/submodule--helper.c to submodule.c. This lets other
callers reuse the helpers.

Return non-relative URLs unchanged before consulting remote
configuration, so the resolver handles every URL form itself.
Keep the repository parameter change for the next patch.

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
Pass the repository explicitly to resolve_submodule_url() instead
of relying on the_repository, and update existing callers. Resolve
relative URLs against the repository worktree when no default
remote URL is configured.

Keep this API change separate from moving the helpers. The
non-relative URL fast path is established in the preparatory
patch and remains independent of repository lookup.

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
When the URL in .gitmodules differs from the cached URL in the
superproject config, git status can help users discover that
submodule operations may use a stale location. Resolve relative
URLs the same way as git submodule sync does.

For populated submodules, compare the default remote URL as well.
If it matches neither the cached URL nor the newly declared URL,
treat it as a local customization and do not suggest a sync that
would overwrite it. Multiple remote URLs are also treated as a
customization.

Emit the warning on standard error for long, short, and porcelain
formats. Respect pathspecs and suppress the check only when
--ignore-submodules=all (or its bare form) is given. Run the check
only for git status, not other users of the wt-status machinery.

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
@kairosci
kairosci force-pushed the topic/status-submodule-url-sync branch from 972d8ad to e406cf5 Compare November 29, 2026 16:14
@kairosci

Copy link
Copy Markdown
Author

/preview

@gitgitgadget-git

Copy link
Copy Markdown

Preview email sent as pull.2509.v5.git.git.1795971233.gitgitgadget@gmail.com

@@ -22,6 +22,18 @@ are what you _would_ commit by running `git commit`; the second and
third are what you _could_ commit by running `git add` before running

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

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

> diff --git a/builtin/commit.c b/builtin/commit.c
> index 36e47e18ed..577b097aa0 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1636,6 +1636,7 @@ struct repository *repo UNUSED)
>  
>  	s.ignore_submodule_arg = ignore_submodule_arg;
>  	s.status_format = status_format;
> +	s.check_submodule_urls = 1;

The hunk header unfortunately is hard to read but this is inside
cmd_status().

Now whichever format wt_status_print() is triggered with, we will show
the submodule changes but only when the top-level command is "git
status".

Good.

> diff --git 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)) {

The third condition being a non-NULL check of the value and not a
comparison can easily become confusing.  GNU toolchains seem to
encourage putting such a "var = value" assignment that is also used for
a non-NULL/0 check inside an extra pair of parentheses, which is the
convention the above code also uses.  Use of the _get_value_ variant and
checking the NULL-ness of .string allows us to cope with a valueless
truth "[remote "frotz"] url;" cleanly.

> +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;
> +	}

Do we see a small inconsistency with the repository-aware design from
the previous patch here?

This function takes 'repo' and passes it to repo_submodule_init() and
resolve_submodule_url(), yet is_submodule_populated_gently() inspects
"%s/.git" relative to the current working directory rather than the
'.worktree' member of 'repo'.  

That may be harmless today because cmd_status() runs with NEED_WORK_TREE
and repo == the_repository, so we are always at the worktree root.  It
might be worth a comment near the call to is_submodule_populated_gently()
though.

> +static void wt_status_check_submodule_urls(struct wt_status *s)
> +{
> +	int i;
> +
> +	if (s->ignore_submodule_arg &&
> +	    !strcmp(s->ignore_submodule_arg, "all"))
> +		return;
> +
> +	if (is_gitmodules_unmerged(s->repo->index))
> +		return;
> +
> +	for (i = 0; i < s->repo->index->cache_nr; i++) {
> +		struct cache_entry *ce = s->repo->index->cache[i];

Because cmd_status() sets '.command_requires_full_index' to 0, you need
to be careful when iterating '.cache' directly like the above loop when
sparse-index is in effect.

In sparse-index.c, convert_to_sparse_rec() refuses to collapse any
directory containing S_ISGITLINK entries, so I _think_ gitlinks remain
visible even in a sparse index, but please double check.

Overall, this iteration was a very pleasant read.
Thanks for working on it.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into seen via 4273a3c.

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "New Topics" section about the branch aa/status-submodule-url-sync on the Git mailing list:

git status' has been taught to warn when an active submodule's URL in
'.gitmodules' differs from the URL cached in '.git/config', unless the
submodule's own default remote URL appears to be customized.

Needs review.
cf. <xmqqfqwjod8f.fsf@gitster.g>
source: <pull.2509.v4.git.git.1795884822.gitgitgadget@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git status should report when a submodule URL is out of sync

2 participants