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

[PATCH v7 8/9] submodule: fix handling of denormalized superproject origin URLs

From
Jon Seymour <jon.seymour@gmail.com>
Date
May 27, 2012, 15:34 UTC
Message-ID
<1338132851-23497-9-git-send-email-jon.seymour@gmail.com>
In-Reply-To
<1338132851-23497-1-git-send-email-jon.seymour@gmail.com>

Currently git calculates the submodule origin URL incorrectly in the case that the superproject origin URL is denormalized.

So, we normalize the path part of the superproject URL before iterating over the leading ../ parts of the submodule URL.

A remaining problem related to the handling of consecutive repeated ./'s in the superproject origin URL is deferred to a subsequent commit.

This change also fixes a subtle error in the setup of some tests which was masked by the denormalization issue that is now fixed.

Previous behaviour was relying on submodule add to clone trash/submodule into super/submodule, however from the perspective of super's origin (i.e. trash), the origin submodule is actually located at ./submodule not ../submodule.

However, because the origin URL of super was denormalized (it had a trailing /.) the incorrect handling of denormalized super URLs actually produced the correct result - a case of two errors cancelling out each other's effects.

Now that normalization is fixed, the erroneous use of git submodule add by the test setups needs to be fixed. The cleanest way to do this is to clone super not from ., but from ./omega. The subsequent invocation of

   git submodule add ../submodule submodule

now does the expected thing because ../submodule is the correct path from omega to the submodule origin repo.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-submodule.sh             |  1 +
 t/t7400-submodule-basic.sh   | 10 +++++-----
 t/t7403-submodule-sync.sh    | 14 +++++++++-----
 t/t7406-submodule-update.sh  | 16 ++++++++++------
 t/t7407-submodule-foreach.sh | 14 +++++++++-----
 t/t7506-status-submodule.sh  | 10 +++++++++-
 6 files changed, 43 insertions(+), 22 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 9ca2ffe..1f0983c 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -76,6 +76,7 @@ resolve_relative_url ()
 		;;
 	esac
 	invariant="${remoteurl%$variant}"
+	variant="$(normalize_path "$variant")"
 
 	while test -n "$url"
 	do
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index a94c5e9..b01f479 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -521,7 +521,7 @@ test_expect_failure 'relative path works with URL - ssh://hostname/path/detour/.
 	)
 '
 
-test_expect_failure 'relative path works with URL - ssh://hostname/path/repo/.' '
+test_expect_success 'relative path works with URL - ssh://hostname/path/repo/.' '
 	(
 		cd reltest &&
 		cp pristine-.git-config .git/config &&
@@ -663,7 +663,7 @@ test_expect_success '../subrepo works with scp-style URL - user@host:path/to/rep
 	)
 '
 
-test_expect_failure 'relative path works with user@host:path/to/repo/.' '
+test_expect_success 'relative path works with user@host:path/to/repo/.' '
 	(
 		cd reltest &&
 		cp pristine-.git-config .git/config &&
@@ -674,7 +674,7 @@ test_expect_failure 'relative path works with user@host:path/to/repo/.' '
 	)
 '
 
-test_expect_failure 'relative path works with user@host:path/to/./repo' '
+test_expect_success 'relative path works with user@host:path/to/./repo' '
 	(
 		cd reltest &&
 		cp pristine-.git-config .git/config &&
@@ -696,7 +696,7 @@ test_expect_failure 'relative path works with user@host:path/to/././repo' '
 	)
 '
 
-test_expect_failure 'relative path works with user@host:path/to/detour/../repo' '
+test_expect_success 'relative path works with user@host:path/to/detour/../repo' '
 	(
 		cd reltest &&
 		cp pristine-.git-config .git/config &&
@@ -773,7 +773,7 @@ test_expect_success '../subrepo works with relative local path - ../foo/bar' '
 	)
 '
 
-test_expect_failure 'relative path works with ../foo/./bar' '
+test_expect_success 'relative path works with ../foo/./bar' '
 	(
 		cd reltest &&
 		cp pristine-.git-config .git/config &&
diff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh
index b7466ba..d76e49f 100755
--- a/t/t7403-submodule-sync.sh
+++ b/t/t7403-submodule-sync.sh
@@ -11,11 +11,15 @@ These tests exercise the "git submodule sync" subcommand.
 . ./test-lib.sh
 
 test_expect_success setup '
-	echo file > file &&
-	git add file &&
-	test_tick &&
-	git commit -m upstream &&
-	git clone . super &&
+	mkdir omega &&
+	(cd omega &&
+	 git init &&
+	 echo file > file &&
+	 git add file &&
+	 test_tick &&
+	 git commit -m upstream
+	) &&
+	git clone omega super &&
 	git clone super submodule &&
 	(cd super &&
 	 git submodule add ../submodule submodule &&
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index dcb195b..8b6c330 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -22,11 +22,15 @@ compare_head()
 
 
 test_expect_success 'setup a submodule tree' '
-	echo file > file &&
-	git add file &&
-	test_tick &&
-	git commit -m upstream &&
-	git clone . super &&
+	mkdir omega &&
+	(cd omega &&
+	 git init &&
+	 echo file > file &&
+	 git add file &&
+	 test_tick &&
+	 git commit -m upstream
+	) &&
+	git clone omega super &&
 	git clone super submodule &&
 	git clone super rebasing &&
 	git clone super merging &&
@@ -58,7 +62,7 @@ test_expect_success 'setup a submodule tree' '
 	 git submodule add ../merging merging &&
 	 test_tick &&
 	 git commit -m "rebasing"
-	)
+	) &&
 	(cd super &&
 	 git submodule add ../none none &&
 	 test_tick &&
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index 9b69fe2..40f957c 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -13,11 +13,15 @@ that are currently checked out.
 
 
 test_expect_success 'setup a submodule tree' '
-	echo file > file &&
-	git add file &&
-	test_tick &&
-	git commit -m upstream &&
-	git clone . super &&
+	mkdir omega &&
+	(cd omega &&
+	 git init &&
+	 echo file > file &&
+	 git add file &&
+	 test_tick &&
+	 git commit -m upstream
+	) &&
+	git clone omega super &&
 	git clone super submodule &&
 	(
 		cd super &&
diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
index d31b34d..764c1d0 100755
--- a/t/t7506-status-submodule.sh
+++ b/t/t7506-status-submodule.sh
@@ -197,7 +197,15 @@ A  sub1
 EOF
 
 test_expect_success 'status with merge conflict in .gitmodules' '
-	git clone . super &&
+	mkdir omega &&
+	(cd omega &&
+	 git init &&
+	 echo file > file &&
+	 git add file &&
+	 test_tick &&
+	 git commit -m upstream
+	) &&
+	git clone omega super &&
 	test_create_repo_with_commit sub1 &&
 	test_tick &&
 	test_create_repo_with_commit sub2 &&
-- 
1.7.10.2.656.g24a6219
Previous: Jon SeymourNext: Jon Seymour
Message 12 of 17 in “submodule: improve robustness of path handling”
  1. 0/9 submodule: improve robustness of path handlingJon Seymour, May 27, 2012
  2. 1/9 submodule: additional regression tests for relative URLsJon Seymour, May 27, 2012
  3. 2/9 submodule: document failure to detect invalid submodule URLsJon Seymour, May 27, 2012
  4. 3/9 submodule: document failure to handle relative superproject origin URLsJon Seymour, May 27, 2012
  5. 4/9 submodule: document failure to handle improperly normalized remote origin URLsJon Seymour, May 27, 2012
  6. 5/9 submodule: extract normalize_path into standalone functionJon Seymour, May 27, 2012
  7. 6/9 submodule: fix detection of invalid submodule URLJon Seymour, May 27, 2012
  8. Johannes SixtMay 28, 2012
  9. Jon SeymourMay 28, 2012
  10. Jon SeymourJun 3, 2012
  11. 7/9 submodule: fix sync handling of relative superproject origin URLsJon Seymour, May 27, 2012
  12. 8/9 submodule: fix handling of denormalized superproject origin URLsJon Seymour, May 27, 2012
  13. Jon SeymourMay 27, 2012
  14. 9/9 submodule: fix normalization to handle repeated ./Jon Seymour, May 27, 2012
  15. Jens LehmannMay 28, 2012
  16. Jon SeymourMay 28, 2012
  17. Jens LehmannMay 29, 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.