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

[PATCH v3 4/4] submodule: support superproject origin URLs of the form foo/bar

From
Jon Seymour <jon.seymour@gmail.com>
Date
May 21, 2012, 13:31 UTC
Message-ID
<1337607102-14737-4-git-send-email-jon.seymour@gmail.com>
In-Reply-To
<1337607102-14737-1-git-send-email-jon.seymour@gmail.com>

When the origin URL of a superproject is of the form foo/bar, submodule operations such as add, sync or init will configure the URL of any submodule with an origin URL that points at the incorrect location.

Origin URLs of this form are not expected in most cases, since the origin URL of a repo will usually point to a location that is not nested within the current working tree.

However, the situation can arise when the physical location of an upstream repo is managed with a symbolic link nested within the working tree itself.

For example, suppose that a toolset is installed in ~/tools and ~/tools/mnt/usb is a occasionally used as the origin for a refresh of the toolset. Different users with different USB devices may map ~/tools/mnt/usb to a different subdirectory of /media, but the auto-update function of the toolset may simply pull an update from mnt/usb, assuming that the user has done what is required to initialise mnt/usb to refer to the correct subdirectory of /media.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-submodule.sh           | 2 ++
 t/t7400-submodule-basic.sh | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 230c219..b8a7403 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -37,6 +37,7 @@ resolve_relative_url ()
 	remoteurl=$(git config "remote.$remote.url") ||
 		remoteurl=$(pwd) # the repository is its own authoritative upstream
 	url="$1"
+	remoteurl=$(echo "$remoteurl" | sed "s|^[^/][^:]*\$|./&|")
 	remoteurl=${remoteurl%/}
 	sep=/
 	while test -n "$url"
@@ -47,6 +48,7 @@ resolve_relative_url ()
 			case "$remoteurl" in
 			.*/*)
 				up_path="$(echo "$2" | sed "s/[^/]*/../g")"
+				remoteurl=${remoteurl#./}
 				remoteurl="${up_path%/}/${remoteurl%/*}"
 				;;
 			*/*)
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 71f30d8..a4a8363 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -533,7 +533,7 @@ test_expect_sucess 'test that submodule add creates the correct url when super o
 		test "$(git config submodule.sub.url)" = ../../relative/subrepo
 	)
 '
-test_expect_failure 'test that submodule add creates the correct url when super origin url is relative/repo' '
+test_expect_success 'test that submodule add creates the correct url when super origin url is relative/repo' '
 	mkdir reladd &&
 	(
 		cd reladd &&
-- 
1.7.10.2.594.g5c52315
Previous: Jon Seymour
Message 6 of 6 in “submodule: verify support for superproject origin URLs of the form ./foo/bar or ../foo/bar”
  1. 1/4 submodule: verify support for superproject origin URLs of the form ./foo/bar or ../foo/barJon Seymour, May 21, 2012
  2. 2/4 submodule: support superproject origin URLs of the form ./foo/bar or ../foo/barJon Seymour, May 21, 2012
  3. Jon SeymourMay 21, 2012
  4. Jon SeymourMay 21, 2012
  5. 3/4 submodule: verify support for superproject URLs of the form foo/bar.Jon Seymour, May 21, 2012
  6. 4/4 submodule: support superproject origin URLs of the form foo/barJon Seymour, May 21, 2012

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.