All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alessio Attilio via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "D. Ben Knoble" <ben.knoble@gmail.com>,
	Alessio Attilio <attilio.alessio@protonmail.com>,
	Alessio Attilio <attilio.alessio@protonmail.com>
Subject: [PATCH v6 3/4] status: preserve customized submodule remotes
Date: Fri, 04 Dec 2026 12:58:09 +0000	[thread overview]
Message-ID: <69aed73e2301ea590fff4aa4cbefa4f4d64b1d86.1796389090.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2509.v6.git.git.1796389090.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


  parent reply	other threads:[~2026-12-04 12:58 UTC|newest]

Thread overview: 31+ 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
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
2026-12-01 21:08 ` [PATCH v5 0/4] " Alessio Attilio via GitGitGadget
2026-12-01 21:08   ` [PATCH v5 1/4] submodule: share repository-aware URL resolution Alessio Attilio via GitGitGadget
2026-12-01 21:08   ` [PATCH v5 2/4] status: warn about submodule URL mismatches Alessio Attilio via GitGitGadget
2026-12-01 21:08   ` [PATCH v5 3/4] status: preserve customized submodule remotes Alessio Attilio via GitGitGadget
2026-12-01 21:08   ` [PATCH v5 4/4] status: test submodule URL warnings Alessio Attilio via GitGitGadget
2026-12-04 12:58 ` [PATCH v6 0/4] status: report when submodule URLs are out of sync Alessio Attilio via GitGitGadget
2026-12-04 12:58   ` [PATCH v6 1/4] submodule: share repository-aware URL resolution Alessio Attilio via GitGitGadget
2026-12-04 12:58   ` [PATCH v6 2/4] status: warn about submodule URL mismatches Alessio Attilio via GitGitGadget
2026-12-04 12:58   ` Alessio Attilio via GitGitGadget [this message]
2026-12-04 12:58   ` [PATCH v6 4/4] status: test submodule URL warnings Alessio Attilio via GitGitGadget

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=69aed73e2301ea590fff4aa4cbefa4f4d64b1d86.1796389090.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=attilio.alessio@protonmail.com \
    --cc=ben.knoble@gmail.com \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.