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

[PATCH v8 4/4] submodule: fix handling of superproject origin URLs like foo, ./foo and ./foo/bar

From
Jon Seymour <jon.seymour@gmail.com>
Date
Jun 3, 2012, 09:46 UTC
Message-ID
<1338716810-9881-5-git-send-email-jon.seymour@gmail.com>
In-Reply-To
<1338716810-9881-1-git-send-email-jon.seymour@gmail.com>

Currently git submodule init and git submodule sync fail with an error if the superproject origin URL is of the form foo but succeeds if the superproject origin URL is of the form ./foo or ./foo/bar or foo/bar.

This change makes handling of the foo case behave like the handling of the ./foo case and also ensures that superfluous leading ./'s are removed from the resulting derived URLs.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-submodule.sh           | 14 ++++++++++++--
 t/t7400-submodule-basic.sh |  6 +++---
 t/t7403-submodule-sync.sh  |  6 +++---
 3 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 314df20..5142379 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -60,8 +60,12 @@ resolve_relative_url ()
 		*:*|/*)
 			is_relative=
 			;;
+		./*|../*)
+			is_relative=t
+			;;
 		*)
 			is_relative=t
+			remoteurl="./$remoteurl"
 			;;
 	esac
 
@@ -79,7 +83,12 @@ resolve_relative_url ()
 				sep=:
 				;;
 			*)
-				die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")"
+				if test -z "$is_relative" || test "." = "$remoteurl"
+				then
+					die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")"
+				else
+					remoteurl=.
+				fi
 				;;
 			esac
 			;;
@@ -90,7 +99,8 @@ resolve_relative_url ()
 			break;;
 		esac
 	done
-	echo "${is_relative:+${up_path}}$remoteurl$sep${url%/}"
+	remoteurl="$remoteurl$sep${url%/}"
+	echo "${is_relative:+${up_path}}${remoteurl#./}"
 }
 
 #
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 09e2b9b..a899e6d 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -564,7 +564,7 @@ test_expect_success '../subrepo works with scp-style URL - user@host:path/to/rep
 	)
 '
 
-test_expect_failure '../subrepo works with relative local path - foo' '
+test_expect_success '../subrepo works with relative local path - foo' '
 	(
 		cd reltest &&
 		cp pristine-.git-config .git/config &&
@@ -587,7 +587,7 @@ test_expect_success '../subrepo works with relative local path - foo/bar' '
 	)
 '
 
-test_expect_failure '../subrepo works with relative local path - ./foo' '
+test_expect_success '../subrepo works with relative local path - ./foo' '
 	(
 		cd reltest &&
 		cp pristine-.git-config .git/config &&
@@ -598,7 +598,7 @@ test_expect_failure '../subrepo works with relative local path - ./foo' '
 	)
 '
 
-test_expect_failure '../subrepo works with relative local path - ./foo/bar' '
+test_expect_success '../subrepo works with relative local path - ./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 98bc74a..524d5c1 100755
--- a/t/t7403-submodule-sync.sh
+++ b/t/t7403-submodule-sync.sh
@@ -88,7 +88,7 @@ test_expect_success '"git submodule sync" should not vivify uninteresting submod
 	)
 '
 
-test_expect_failure '"git submodule sync" handles origin URL of the form foo' '
+test_expect_success '"git submodule sync" handles origin URL of the form foo' '
 	(cd relative-clone &&
 	 git remote set-url origin foo &&
 	 git submodule sync &&
@@ -110,7 +110,7 @@ test_expect_success '"git submodule sync" handles origin URL of the form foo/bar
 	)
 '
 
-test_expect_failure '"git submodule sync" handles origin URL of the form ./foo' '
+test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
 	(cd relative-clone &&
 	 git remote set-url origin ./foo &&
 	 git submodule sync &&
@@ -121,7 +121,7 @@ test_expect_failure '"git submodule sync" handles origin URL of the form ./foo'
 	)
 '
 
-test_expect_failure '"git submodule sync" handles origin URL of the form ./foo/bar' '
+test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
 	(cd relative-clone &&
 	 git remote set-url origin ./foo/bar &&
 	 git submodule sync &&
-- 
1.7.10.2.652.gdffd412
Previous: Jon Seymour
Message 10 of 10 in “submodule: improve support for relative superproject origin URLs”
  1. 0/4 submodule: improve support for relative superproject origin URLsJon Seymour, Jun 3, 2012
  2. 1/4 submodule: additional regression tests for relative URLsJon Seymour, Jun 3, 2012
  3. 2/4 submodule: document failure to handle relative superproject origin URLsJon Seymour, Jun 3, 2012
  4. 3/4 submodule: fix sync handling of some relative superproject origin URLsJon Seymour, Jun 3, 2012
  5. Junio C HamanoJun 3, 2012
  6. Jon SeymourJun 3, 2012
  7. Jens LehmannJun 5, 2012
  8. Junio C HamanoJun 5, 2012
  9. Jon SeymourJun 6, 2012
  10. 4/4 submodule: fix handling of superproject origin URLs like foo, ./foo and ./foo/barJon Seymour, Jun 3, 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.