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

[PATCH 5/5] Teach 'git submodule' to rewrite submodule URLs according to super-repo's rules

From
Johan Herland <johan@herland.net>
Date
Aug 3, 2008, 23:02 UTC
Message-ID
<200808040102.58275.johan@herland.net>
In-Reply-To
<200808040057.00221.johan@herland.net>

When a 'url.*.insteadOf' rule in the superrepo matches a submodule URL, we should rewrite the submodule URL accordingly, so that we don't request the submodule from location that is inaccessible (or unwanted by the user for some other reason).

Signed-off-by: Johan Herland <johan@herland.net>
---
 git-submodule.sh           |    6 ++++++
 t/t7400-submodule-basic.sh |    2 +-
 2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index b40f876..ea2aa3b 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -96,6 +96,12 @@ module_clone()
 	test -e "$path" &&
 	die "A file already exist at path '$path'"
 
+	# The user may have added url.*.insteadOf rules intending to rewrite
+	# submodule URLs. We must explicitly do this rewrite before calling
+	# 'git clone', since 'git clone' will not consult the super-repo
+	# config and thus never see any url.*.insteadOf rules placed therein.
+	url=$(git config --rewrite-url "$url")
+
 	git-clone -n "$url" "$path" ||
 	die "Clone of '$url' into submodule path '$path' failed"
 }
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index bafc46c..9c56de2 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -209,7 +209,7 @@ test_expect_success 'update --init' '
 
 '
 
-test_expect_failure 'update --init with url.*.insteadOf' '
+test_expect_success 'update --init with url.*.insteadOf' '
 
 	rm -rf init &&
 	git config -f .gitmodules submodule.example.url "http://example.com/init2" &&
-- 
1.6.0.rc1.34.g0fe8c
Previous: Johan HerlandNext: Johannes Schindelin
Message 7 of 12 in “Fix 'url.*.insteadOf' for submodule URLs”
  1. 0/5 Fix 'url.*.insteadOf' for submodule URLsJohan Herland, Aug 3, 2008
  2. 1/5 Add testcase for 'git submodule' with url.*.insteadOf set in the super-repoJohan Herland, Aug 3, 2008
  3. 1/5 Add testcase for 'git submodule' with url.*.insteadOf set in the super-repoJohan Herland, Aug 3, 2008
  4. 2/5 Teach 'git config' to rewrite URLs according to current url.*.insteadOf rulesJohan Herland, Aug 3, 2008
  5. 3/5 Add selftest for new option '--rewrite-url' to 'git config'Johan Herland, Aug 3, 2008
  6. 4/5 Add documentation on the new --rewrite-url option to 'git config'Johan Herland, Aug 3, 2008
  7. 5/5 Teach 'git submodule' to rewrite submodule URLs according to super-repo's rulesJohan Herland, Aug 3, 2008
  8. Johannes SchindelinAug 3, 2008
  9. Johan HerlandAug 3, 2008
  10. Junio C HamanoAug 4, 2008
  11. Johan HerlandAug 4, 2008
  12. Junio C HamanoAug 3, 2008

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.