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

[PATCH v3 0/2] status: report when submodule URLs are out of sync

From
AGAlessio Attilio via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 27, 2026, 21:27 UTC
Message-ID
<pull.2509.v3.git.git.1795814853.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 (2):
  submodule: prepare URL helpers for reuse
  status: warn about stale submodule URLs
 Documentation/git-status.adoc |   6 ++
 builtin/commit.c              |   1 +
 builtin/submodule--helper.c   |  63 +++---------------
 submodule.c                   |  45 +++++++++++++
 submodule.h                   |   3 +
 t/t7508-status.sh             |  84 ++++++++++++++++++++++++
 wt-status.c                   | 120 ++++++++++++++++++++++++++++++++++
 wt-status.h                   |   1 +
 8 files changed, 270 insertions(+), 53 deletions(-)
base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2509%2Fkairosci%2Ftopic%2Fstatus-submodule-url-sync-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2509/kairosci/topic/status-submodule-url-sync-v3
Pull-Request: https://github.com/git/git/pull/2509
Range-diff vs v2:
 1:  4cd0ab7e9b ! 1:  fc300295ff submodule: prepare URL helpers for reuse
     @@ 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 *url,
     ++char *resolve_submodule_url(struct repository *repo, const char *rel_url,
      +			    const char *up_path, int quiet)
      +{
     -+	const char *remote = repo_default_remote(repo);
      +	char *remoteurl, *resolved_url;
     ++	const char *remote = repo_default_remote(repo);
      +	struct strbuf remotesb = STRBUF_INIT;
      +
      +	strbuf_addf(&remotesb, "remote.%s.url", remote);
     @@ submodule.c: int is_submodule_active(struct repository *repo, const char *path)
      +				remotesb.buf);
      +		remoteurl = xgetcwd();
      +	}
     -+	resolved_url = relative_url(remoteurl, url, up_path);
     ++	resolved_url = relative_url(remoteurl, rel_url, up_path);
      +
      +	free(remoteurl);
      +	strbuf_release(&remotesb);
 2:  b0dd21100c ! 2:  9dc6283075 status: warn about stale submodule URLs
     @@ Commit message
          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.
     +    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.
     +
     +    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.
      
          Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
      
     + ## Documentation/git-status.adoc ##
     +@@ Documentation/git-status.adoc: are what you _would_ commit by running `git commit`; the second and
     + third are what you _could_ commit by running `git add` before running
     + `git commit`.
     + 
     ++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.
     ++
     + OPTIONS
     + -------
     + 
     +
     + ## builtin/commit.c ##
     +@@ builtin/commit.c: struct repository *repo UNUSED)
     + 
     + 	s.ignore_submodule_arg = ignore_submodule_arg;
     + 	s.status_format = status_format;
     ++	s.check_submodule_urls = 1;
     + 	s.verbose = verbose;
     + 	if (no_renames != -1)
     + 		s.detect_rename = !no_renames;
     +
       ## submodule.c ##
     -@@ submodule.c: char *resolve_submodule_url(struct repository *repo, const char *url,
     +@@ 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(url) && !starts_with_dot_slash(url))
     -+		return xstrdup(url);
     ++	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: test_expect_success 'setup status submodule summary' '
      +	git -C url-test/super config -f .gitmodules submodule.module.url \
      +		"$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 &&
     ++	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 >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 &&
     ++	test_must_be_empty url-test/err &&
     ++	git -C url-test/super status -- module >url-test/actual 2>url-test/err &&
     ++	test_grep "module.*different URL" url-test/err &&
      +	git -C url-test/super status >url-test/actual 2>url-test/err &&
      +	test_grep "module.*different URL" url-test/err &&
      +	test_grep "git submodule sync" url-test/err &&
     @@ t/t7508-status.sh: test_expect_success 'setup status submodule summary' '
      +	git -C url-test/super status >url-test/actual 2>url-test/err &&
      +	test_grep "module.*different URL" url-test/err
      +'
     ++
     ++test_expect_success 'status compares relative submodule URLs only once' '
     ++	test_when_finished "rm -rf url-test" &&
     ++	test_create_repo url-test/relative-source &&
     ++	test_commit -C url-test/relative-source initial &&
     ++	test_create_repo url-test/relative-super &&
     ++	git -C url-test/relative-super -c protocol.file.allow=always \
     ++		submodule add "$PWD/url-test/relative-source" module &&
     ++	git -C url-test/relative-super commit -m "add submodule" &&
     ++	git -C url-test/relative-super remote add origin ../a/b &&
     ++	git -C url-test/relative-super config -f .gitmodules \
     ++		submodule.module.url ../mod1 &&
     ++	git -C url-test/relative-super submodule sync &&
     ++	git -C url-test/relative-super status >url-test/actual 2>url-test/err &&
     ++	test_must_be_empty url-test/err &&
     ++	git -C url-test/relative-super config -f .gitmodules \
     ++		submodule.module.url ../mod2 &&
     ++	git -C url-test/relative-super status >url-test/actual 2>url-test/err &&
     ++	test_grep "module.*different URL" url-test/err
     ++'
      +
       test_expect_success 'status submodule summary is disabled by default' '
       	cat >expect <<EOF &&
     @@ wt-status.c
       
       #include "git-compat-util.h"
       #include "advice.h"
     ++#include "abspath.h"
      +#include "config.h"
       #include "wt-status.h"
       #include "object.h"
     @@ wt-status.c
       #include "remote.h"
       #include "refs.h"
       #include "submodule.h"
     ++#include "url.h"
      +#include "submodule-config.h"
       #include "column.h"
       #include "read-cache.h"
     @@ 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_value_multi(&subrepo, key, &remote_urls) &&
     ++	if (!repo_config_get_string_multi(&subrepo, key, &remote_urls) &&
      +	    remote_urls->nr == 1) {
      +		remote_url = remote_urls->items[0].string;
      +		up_path = get_submodule_up_path(path);
     -+		config_remote_url = resolve_submodule_url(repo, config_url,
     -+							  up_path, 1);
     ++		/*
     ++		 * sync_submodule() stores a relative URL in the superproject's
     ++		 * config without the submodule path prefix, but adds that prefix
     ++		 * when storing the URL in the submodule's remote configuration.
     ++		 */
     ++		if (url_is_local_not_ssh(config_url) && !is_absolute_path(config_url)) {
     ++			struct strbuf sb = STRBUF_INIT;
     ++
     ++			strbuf_addstr(&sb, up_path);
     ++			strbuf_addstr(&sb, config_url);
     ++			config_remote_url = strbuf_detach(&sb, NULL);
     ++		} else {
     ++			config_remote_url = xstrdup(config_url);
     ++		}
      +		gitmodules_remote_url = resolve_submodule_url(repo, gitmodules_url,
      +							      up_path, 1);
      +		/*
     @@ wt-status.c: static void wt_porcelain_v2_print(struct wt_status *s)
      +{
      +	int i;
      +
     -+	if (s->status_format != STATUS_FORMAT_LONG &&
     -+	    s->status_format != STATUS_FORMAT_NONE)
     ++	if (!s->check_submodule_urls || s->ignore_submodule_arg)
      +		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;
     -+		const char *config_url;
     ++		char *config_url;
      +		char *key, *gitmodules_url;
      +
     -+		if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode))
     ++		if (ce_stage(ce) || !S_ISGITLINK(ce->ce_mode) ||
     ++		    !ce_path_match(s->repo->index, ce, &s->pathspec, NULL))
      +			continue;
      +
      +		sub = submodule_from_path(s->repo, null_oid(s->repo->hash_algo),
     @@ 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_value(s->repo, key, &config_url)) {
     ++		if (repo_config_get_string(s->repo, key, &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);
      +	}
      +}
      +
       void wt_status_print(struct wt_status *s)
       {
     -+	wt_status_check_submodule_urls(s);
     ++	if (s->check_submodule_urls)
     ++		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.h ##
     +@@ wt-status.h: struct wt_status {
     + 	unsigned colopts;
     + 	int null_termination;
     + 	int commit_template;
     ++	int check_submodule_urls;
     + 	int show_branch;
     + 	int show_stash;
     + 	int hints;
-- 
gitgitgadget
Previous: D. Ben KnobleNext: Alessio Attilio via GitGitGadget
Message 9 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.