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

[PATCH v5 3/4] status: preserve customized submodule remotes

From
AGAlessio Attilio via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 1, 2026, 21:08 UTC
Message-ID
<d80542df121417ad82ed52e29d8efd8ce75b01d7.1796159338.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2509.v5.git.git.1796159338.gitgitgadget@gmail.com>
From: Alessio Attilio <attilio.alessio@protonmail.com>

Users may point a populated submodule remote at a fork. Since git submodule sync would overwrite custom or multi-URL remotes, suppress the advice unless the configured remote matches the old or declared URL.

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
 wt-status.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 83 insertions(+), 1 deletion(-)
diff --git a/wt-status.c b/wt-status.c
index bbd0e082dc..69c05735ec 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -2696,6 +2696,85 @@ 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 *declared_url,
+					  const char *cached_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;
+	char *declared_super_url;
+	char *worktree_path;
+	int error_code, populated, ret = 0;
+
+	worktree_path = repo_worktree_path(repo, "%s", path);
+	if (!worktree_path)
+		return 0;
+	populated = is_submodule_populated_gently(worktree_path, &error_code);
+	free(worktree_path);
+	if (!populated)
+		return 0;
+
+	if (repo_submodule_init(&subrepo, repo, path,
+				null_oid(repo->hash_algo)) < 0) {
+		repo_clear(&subrepo);
+		return 0;
+	}
+
+	declared_super_url = resolve_submodule_url(repo, declared_url, NULL, 1);
+	remote = repo_remote_from_url(&subrepo, declared_super_url);
+	if (!remote)
+		remote = repo_default_remote(&subrepo);
+	free(declared_super_url);
+
+	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)) {
+		up_path = get_submodule_up_path(path);
+		/*
+		 * 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(cached_url) &&
+		    !is_absolute_path(cached_url)) {
+			struct strbuf sb = STRBUF_INIT;
+
+			strbuf_addstr(&sb, up_path);
+			strbuf_addstr(&sb, cached_url);
+			config_remote_url = strbuf_detach(&sb, NULL);
+		} else {
+			config_remote_url = xstrdup(cached_url);
+		}
+		gitmodules_remote_url = resolve_submodule_url(repo, declared_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;
+		free(gitmodules_remote_url);
+		free(config_remote_url);
+		free(up_path);
+	} else {
+		/*
+		 * Multiple URLs are a local customization; sync would replace
+		 * them all with a single URL.
+		 */
+		ret = remote_urls && remote_urls->nr > 1;
+	}
+	free(key);
+	repo_clear(&subrepo);
+
+	return ret;
+}
+
 static void wt_status_check_submodule_urls(struct wt_status *s)
 {
 	int i;
@@ -2734,7 +2813,10 @@ static void wt_status_check_submodule_urls(struct wt_status *s)
 		free(key);
 
 		gitmodules_url = resolve_submodule_url(s->repo, sub->url, NULL, 1);
-		if (strcmp(config_url, gitmodules_url))
+		if (strcmp(config_url, gitmodules_url) &&
+		    !submodule_has_custom_remote_url(s->repo, ce->name,
+						     sub->url,
+						     config_url))
 			warning(_("submodule '%s' has a different URL in .git/config "
 				  "than in .gitmodules\n"
 				  "  run 'git submodule sync' to update it"), ce->name);
-- 
gitgitgadget
Previous: Alessio Attilio via GitGitGadgetNext: Alessio Attilio via GitGitGadget
Message 25 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.