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

[PATCH] submodule: resolve insteadof-aliases when matching remote

From
ÉNÉric NICOLAS <ccjmne@gmail.com>
Date
Jul 21, 2026, 21:30 UTC
Message-ID
<20260721213042.3357346-1-ccjmne@gmail.com>

When ca62f524c1 introduced a mechanism to identify which remote is to be used by a submodule, we had it compare the URL stored in the .gitmodules inventory to those of each available remote.

However, when using URL aliasing via url.<base>.insteadOf, we store in .gitmodules the URL pre-resolution of the alias, whereas the corresponding remote set up in the submodule reports using the *resolved* URL. This mechanism therefore fails to find a match then, and resorts to the fallback logic, which does use either the only configured remote if there is only one, or attempts using "origin" otherwise.

Resolve the alias in the URL inventoried in .gitmodules before comparing it against those of the corresponding submodule's configured remotes.

Signed-off-by: Éric NICOLAS <ccjmne@gmail.com>
---
 remote.c                    | 15 ++++++++++++---
 t/t7406-submodule-update.sh | 21 +++++++++++++++++++++
 2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/remote.c b/remote.c
index b17648d6ef..ae187fb3d6 100644
--- a/remote.c
+++ b/remote.c
@@ -1821,17 +1821,26 @@ const char *repo_default_remote(struct repository *repo)
 
 const char *repo_remote_from_url(struct repository *repo, const char *url)
 {
+	char *rewritten_url;
+	const char *url_to_match;
+	const char *remote_name = NULL;
+
 	read_config(repo, 0);
+	rewritten_url = alias_url(url, &repo->remote_state->rewrites);
+	url_to_match = rewritten_url ? rewritten_url : url;
 
 	for (int i = 0; i < repo->remote_state->remotes_nr; i++) {
 		struct remote *remote = repo->remote_state->remotes[i];
 		if (!remote)
 			continue;
 
-		if (remote_has_url(remote, url))
-			return remote->name;
+		if (remote_has_url(remote, url_to_match)) {
+			remote_name = remote->name;
+			break;
+		}
 	}
-	return NULL;
+	free(rewritten_url);
+	return remote_name;
 }
 
 int branch_has_merge_config(struct branch *branch)
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 9554720152..84e2cbbef9 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -256,6 +256,27 @@ test_expect_success 'submodule update --remote should fetch upstream changes' '
 	)
 '
 
+test_expect_success 'submodule update --remote resolves URL rewrites' '
+	test_config_global "url.$(pwd)/.insteadOf" local: &&
+	mkdir aliased-super aliased-submodule &&
+	(
+		cd aliased-submodule &&
+		git init &&
+		echo line >file &&
+		git add file &&
+		git commit -m "Initial commit"
+	) &&
+	(
+		cd aliased-super &&
+		git init &&
+		git submodule add local:aliased-submodule submodule &&
+		git submodule update --force submodule &&
+		git -C submodule remote rename origin upstream &&
+		git -C submodule remote add fork user@host &&
+		git submodule update --remote submodule
+	)
+'
+
 test_expect_success 'submodule update --remote should fetch upstream changes with .' '
 	(
 		cd super &&
-- 
2.55.0
Next: Junio C Hamano
Message 1 of 5 in “submodule: resolve insteadof-aliases when matching remote”
  1. submodule: resolve insteadof-aliases when matching remoteÉric NICOLAS, Jul 21, 2026
  2. Junio C HamanoJul 22, 2026
  3. submodule: resolve insteadOf aliases when matching remoteÉric NICOLAS, Jul 23, 2026
  4. Junio C HamanoJul 24, 2026
  5. Jacob KellerAug 11, 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.