git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 0/3] status: report when submodule URLs are out of sync

From
AGAlessio Attilio via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 28, 2026, 16:53 UTC
Message-ID
<pull.2509.v4.git.git.1795884822.gitgitgadget@gmail.com>
In-Reply-To
<pull.2509.git.git.1795774880142.gitgitgadget@gmail.com>

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/git#565
Alessio Attilio (3):
  submodule: move URL helpers into submodule.c
  submodule: make URL resolution repository-aware
  status: report when submodule URLs are out of sync
 Documentation/git-status.adoc |  12 ++++
 builtin/commit.c              |   1 +
 builtin/submodule--helper.c   |  60 ++---------------
 submodule.c                   |  45 +++++++++++++
 submodule.h                   |  12 ++++
 t/t7508-status.sh             | 100 ++++++++++++++++++++++++++++
 wt-status.c                   | 120 ++++++++++++++++++++++++++++++++++
 wt-status.h                   |   1 +
 8 files changed, 298 insertions(+), 53 deletions(-)
base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v4
Pull-Request: https://github.com/git/git/pull/2509
Range-diff vs v3:
 1:  fc300295ff ! 1:  b09e8501ed submodule: prepare URL helpers for reuse
     @@ Metadata
      Author: Alessio Attilio <attilio.alessio@protonmail.com>
      
       ## Commit message ##
     -    submodule: prepare URL helpers for reuse
     +    submodule: move URL helpers into submodule.c
      
     -    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.
     +    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.
      
     -    Pass the repository explicitly to the resolver instead of relying on
     -    the_repository, and update existing callers to use the shared 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>
      
     @@ builtin/submodule--helper.c: static int get_default_remote_submodule(const char
       			char *oldurl = url;
       
      -			url = resolve_relative_url(oldurl, NULL, 1);
     -+			url = resolve_submodule_url(the_repository, oldurl, NULL, 1);
     ++			url = resolve_submodule_url(oldurl, NULL, 1);
       			free(oldurl);
       		}
       	}
     @@ builtin/submodule--helper.c: static void init_submodule(const char *path, const
       			char *oldurl = url;
       
      -			url = resolve_relative_url(oldurl, NULL, 0);
     -+			url = resolve_submodule_url(the_repository, oldurl, NULL, 0);
     ++			url = resolve_submodule_url(oldurl, NULL, 0);
       			free(oldurl);
       		}
       
     @@ builtin/submodule--helper.c: static void sync_submodule(const char *path, const
       
      -			sub_origin_url = resolve_relative_url(sub->url, up_path, 1);
      -			super_config_url = resolve_relative_url(sub->url, NULL, 1);
     -+			sub_origin_url = resolve_submodule_url(the_repository, sub->url,
     -+							      up_path, 1);
     -+			super_config_url = resolve_submodule_url(the_repository,
     -+								 sub->url, NULL, 1);
     ++			sub_origin_url = resolve_submodule_url(sub->url, up_path, 1);
     ++			super_config_url = resolve_submodule_url(sub->url, NULL, 1);
       			free(up_path);
       		} else {
       			sub_origin_url = xstrdup(sub->url);
     @@ builtin/submodule--helper.c: static int prepare_to_clone_next_submodule(const st
       		if (sub->url && (starts_with_dot_slash(sub->url) ||
       				 starts_with_dot_dot_slash(sub->url))) {
      -			url = resolve_relative_url(sub->url, NULL, 0);
     -+			url = resolve_submodule_url(the_repository, sub->url, NULL, 0);
     ++			url = resolve_submodule_url(sub->url, NULL, 0);
       			need_free_url = 1;
       		} else
       			url = sub->url;
     @@ builtin/submodule--helper.c: static int module_add(int argc, const char **argv,
       
       		/* dereference source url relative to parent's url */
      -		to_free = resolve_relative_url(add_data.repo, NULL, 1);
     -+		to_free = resolve_submodule_url(the_repository, add_data.repo,
     -+						NULL, 1);
     ++		to_free = resolve_submodule_url(add_data.repo, NULL, 1);
       		add_data.realrepo = to_free;
       	} else if (is_dir_sep(add_data.repo[0]) || strchr(add_data.repo, ':')) {
       		add_data.realrepo = add_data.repo;
     @@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)
       	return is_tree_submodule_active(repo, null_oid(the_hash_algo), path);
       }
       
     -+char *resolve_submodule_url(struct repository *repo, const char *rel_url,
     -+			    const char *up_path, int quiet)
     ++static char *get_default_remote(void)
     ++{
     ++	return xstrdup(repo_default_remote(the_repository));
     ++}
     ++
     ++char *resolve_submodule_url(const char *rel_url, const char *up_path, int quiet)
      +{
      +	char *remoteurl, *resolved_url;
     -+	const char *remote = repo_default_remote(repo);
     ++	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);
     ++
     ++	remote = get_default_remote();
      +	strbuf_addf(&remotesb, "remote.%s.url", remote);
     -+	if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {
     ++	if (repo_config_get_string(the_repository, remotesb.buf, &remoteurl)) {
      +		if (!quiet)
      +			warning(_("could not look up configuration '%s'. "
      +				  "Assuming this repository is its own "
     @@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)
      +	}
      +	resolved_url = relative_url(remoteurl, rel_url, up_path);
      +
     ++	free(remote);
      +	free(remoteurl);
      +	strbuf_release(&remotesb);
      +
     @@ submodule.h: 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 *resolve_submodule_url(const char *url, const char *up_path, int quiet);
      +char *get_submodule_up_path(const char *path);
       /*
        * Determine if a submodule has been populated at a given 'path' by checking if
 -:  ---------- > 2:  ad4dafd82b submodule: make URL resolution repository-aware
 2:  9dc6283075 ! 3:  619101d5e1 status: warn about stale submodule URLs
     @@ Metadata
      Author: Alessio Attilio <attilio.alessio@protonmail.com>
      
       ## Commit message ##
     -    status: warn about stale submodule URLs
     +    status: report when submodule URLs are out of sync
      
     -    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.
     +    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.
      
     -    The check considers three URLs: the .gitmodules URL resolved against
     -    the superproject's default remote, the cached submodule.<name>.url, and
     -    the submodule's default remote URL. The first two determine whether the
     -    cached URL is stale. If they differ, compare the submodule remote with
     -    the old and new URLs as sync would write them. Warn only when that
     -    remote matches either URL; a different URL or multiple URLs indicate a
     -    local customization that sync would otherwise overwrite.
     +    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.
      
     -    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.
     +    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>
      
     @@ Documentation/git-status.adoc: are what you _would_ commit by running `git commi
       
      +When a submodule's URL in `.gitmodules` differs from the URL cached in
      +`.git/config`, `git status` warns that `git submodule sync` can update the
     -+cached URL. The warning is written to standard error in all output formats.
     -+It is limited to submodules matched by the pathspec, and is suppressed when
     -+`--ignore-submodules` is specified.
     ++cached URL. For a populated submodule, the warning is suppressed when its
     ++default remote URL differs from both URLs, since syncing would overwrite a
     ++customized remote. Relative URLs are resolved as `git submodule sync`
     ++resolves them.
     ++
     ++The warning is written to standard error in long, short, and porcelain
     ++formats, and is limited to submodules matched by the pathspec. It is
     ++suppressed when `--ignore-submodules` or `--ignore-submodules=all` is
     ++specified.
      +
       OPTIONS
       -------
     @@ builtin/commit.c: struct repository *repo UNUSED)
       	if (no_renames != -1)
       		s.detect_rename = !no_renames;
      
     - ## submodule.c ##
     -@@ submodule.c: 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);
     -+
     -+	remote = repo_default_remote(repo);
     - 	strbuf_addf(&remotesb, "remote.%s.url", remote);
     - 	if (repo_config_get_string(repo, remotesb.buf, &remoteurl)) {
     - 		if (!quiet)
     -
       ## t/t7508-status.sh ##
      @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '
       	git add sm
     @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '
      +		"$PWD/url-test/updated-source" &&
      +	git -C url-test/super status --porcelain >url-test/actual 2>url-test/err &&
      +	test_grep "module.*different URL" url-test/err &&
     ++	cat >url-test/editor <<\EOF &&
     ++#!/bin/sh
     ++echo "status test commit" >"$1"
     ++EOF
     ++	chmod +x url-test/editor &&
     ++	echo staged >url-test/super/staged &&
     ++	git -C url-test/super add staged &&
     ++	test_set_editor "$PWD/url-test/editor" &&
     ++	git -C url-test/super commit >url-test/actual 2>url-test/err &&
     ++	test_must_be_empty url-test/err &&
      +	git -C url-test/super status --short >url-test/actual 2>url-test/err &&
      +	test_grep "module.*different URL" url-test/err &&
      +	git -C url-test/super status --porcelain=v2 >url-test/actual 2>url-test/err &&
      +	test_grep "module.*different URL" url-test/err &&
     ++	git -C url-test/super status --ignore-submodules=none >url-test/actual 2>url-test/err &&
     ++	test_grep "module.*different URL" url-test/err &&
     ++	git -C url-test/super status --ignore-submodules=dirty >url-test/actual 2>url-test/err &&
     ++	test_grep "module.*different URL" url-test/err &&
     ++	git -C url-test/super status --ignore-submodules=all >url-test/actual 2>url-test/err &&
     ++	test_must_be_empty url-test/err &&
      +	git -C url-test/super status --ignore-submodules >url-test/actual 2>url-test/err &&
      +	test_must_be_empty url-test/err &&
      +	git -C url-test/super status -- .gitmodules >url-test/actual 2>url-test/err &&
     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
      +	remote = repo_default_remote(&subrepo);
      +
      +	key = xstrfmt("remote.%s.url", remote);
     -+	if (!repo_config_get_string_multi(&subrepo, key, &remote_urls) &&
     -+	    remote_urls->nr == 1) {
     -+		remote_url = remote_urls->items[0].string;
     ++	if (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&
     ++	    remote_urls->nr == 1 &&
     ++	    (remote_url = remote_urls->items[0].string)) {
      +		up_path = get_submodule_up_path(path);
      +		/*
      +		 * sync_submodule() stores a relative URL in the superproject's
     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
      +{
      +	int i;
      +
     -+	if (!s->check_submodule_urls || s->ignore_submodule_arg)
     ++	if (s->ignore_submodule_arg &&
     ++	    !strcmp(s->ignore_submodule_arg, "all"))
      +		return;
      +
      +	if (is_gitmodules_unmerged(s->repo->index))
     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
      +	for (i = 0; i < s->repo->index->cache_nr; i++) {
      +		struct cache_entry *ce = s->repo->index->cache[i];
      +		const struct submodule *sub;
     -+		char *config_url;
     ++		const char *config_url;
      +		char *key, *gitmodules_url;
      +
      +		if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||
     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
      +			continue;
      +
      +		key = xstrfmt("submodule.%s.url", sub->name);
     -+		if (repo_config_get_string(s->repo, key, &config_url)) {
     ++		if (repo_config_get_value(s->repo, key, &config_url) || !config_url) {
      +			free(key);
      +			continue;
      +		}
     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
      +				  "than in .gitmodules\n"
      +				  "  run 'git submodule sync' to update it"), ce->name);
      +
     -+		free(config_url);
      +		free(gitmodules_url);
      +	}
      +}
-- 
gitgitgadget
Previous: Junio C HamanoNext: Alessio Attilio via GitGitGadget
Message 15 of 26 in “status: warn about stale submodule URLs”
  1. status: warn about stale submodule URLsAlessio Attilio via GitGitGadget, Nov 27, 2026
  2. D. Ben KnobleNov 27, 2026
  3. 0/2 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 27, 2026
  4. 1/2 submodule: prepare URL helpers for reuseAlessio Attilio via GitGitGadget, Nov 27, 2026
  5. 2/2 status: warn about stale submodule URLsAlessio Attilio via GitGitGadget, Nov 27, 2026
  6. Junio C HamanoNov 27, 2026
  7. ATTILIO ALESSIONov 27, 2026
  8. D. Ben KnobleNov 30, 2026
  9. 0/2 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 27, 2026
  10. 1/2 submodule: prepare URL helpers for reuseAlessio Attilio via GitGitGadget, Nov 27, 2026
  11. Junio C HamanoNov 28, 2026
  12. 2/2 status: warn about stale submodule URLsAlessio Attilio via GitGitGadget, Nov 27, 2026
  13. Junio C HamanoNov 28, 2026
  14. Junio C HamanoNov 28, 2026
  15. 0/3 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 28, 2026
  16. 1/3 submodule: move URL helpers into submodule.cAlessio Attilio via GitGitGadget, Nov 28, 2026
  17. D. Ben KnobleNov 30, 2026
  18. 2/3 submodule: make URL resolution repository-awareAlessio Attilio via GitGitGadget, Nov 28, 2026
  19. D. Ben KnobleNov 30, 2026
  20. 3/3 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Nov 28, 2026
  21. Junio C HamanoNov 29, 2026
  22. 0/4 status: report when submodule URLs are out of syncAlessio Attilio via GitGitGadget, Dec 1, 2026
  23. 1/4 submodule: share repository-aware URL resolutionAlessio Attilio via GitGitGadget, Dec 1, 2026
  24. 2/4 status: warn about submodule URL mismatchesAlessio Attilio via GitGitGadget, Dec 1, 2026
  25. 3/4 status: preserve customized submodule remotesAlessio Attilio via GitGitGadget, Dec 1, 2026
  26. 4/4 status: test submodule URL warningsAlessio Attilio via GitGitGadget, Dec 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.