git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 0/4] submodule: improve support for relative superproject origin URLs
@ 2012-06-03  9:46 Jon Seymour
  2012-06-03  9:46 ` [PATCH v8 1/4] submodule: additional regression tests for relative URLs Jon Seymour
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Jon Seymour @ 2012-06-03  9:46 UTC (permalink / raw)
  To: git; +Cc: Jens.Lehmann, gitster, phil.hord, ramsay, j6t, Jon Seymour

This series improves handling by 'git submodule' of relative superproject origin URLs. 

Currently, 'git submodule':

* incorrectly configures origin URL for submodules with a path that is relative to
the work tree of the superproject when the configured path needs to be relative 
to the work tree of the submodule

* unnecessarily fails with an error if the superproject origin URL is of the form: foo

This series corrects these problems for paths like the following:
  foo
  foo/bar
  ./foo
  ./foo/bar
  ../foo
  ../foo/bar

It does not change current behaviour for URLs that begin with a leading / or contain
a : as such URLs are deemed to be absolute URLs for which no correction is required.

In addition, this series ensures that relative URLs configured by git submodule do
not include a superfluous leading or embedded './'.

This series differs from v7 by removing the patches dealing incorrect handling 
of greedy submodule URLs (those with too many leading ../'s) and those that deal
with improperly normalized superproject origin URLs. These patches may resubmitted
at a later date.

Jon Seymour (4):
  submodule: additional regression tests for relative URLs
  submodule: document failure to handle relative superproject origin
    URLs
  submodule: fix sync handling of some relative superproject origin
    URLs
  submodule: fix handling of superproject origin URLs like foo, ./foo
    and ./foo/bar

 git-submodule.sh           |  65 +++++++++++++++++---
 t/t7400-submodule-basic.sh | 144 ++++++++++++++++++++++++++++++++++++++++++++-
 t/t7403-submodule-sync.sh  |  90 +++++++++++++++++++++++++++-
 3 files changed, 287 insertions(+), 12 deletions(-)

-- 
1.7.10.2.652.gdffd412

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v8 1/4] submodule: additional regression tests for relative URLs
  2012-06-03  9:46 [PATCH v8 0/4] submodule: improve support for relative superproject origin URLs Jon Seymour
@ 2012-06-03  9:46 ` Jon Seymour
  2012-06-03  9:46 ` [PATCH v8 2/4] submodule: document failure to handle relative superproject origin URLs Jon Seymour
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Jon Seymour @ 2012-06-03  9:46 UTC (permalink / raw)
  To: git; +Cc: Jens.Lehmann, gitster, phil.hord, ramsay, j6t, Jon Seymour

Some additional tests are added to support regression testing of the changes in the
remainder of the series.

We also add a pristine copy of .gitmodules in anticipation of this being
required by later tests.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 t/t7400-submodule-basic.sh | 110 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 107 insertions(+), 3 deletions(-)

diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 81827e6..9428c7a 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -483,21 +483,67 @@ test_expect_success 'set up for relative path tests' '
 		git add sub &&
 		git config -f .gitmodules submodule.sub.path sub &&
 		git config -f .gitmodules submodule.sub.url ../subrepo &&
-		cp .git/config pristine-.git-config
+		cp .git/config pristine-.git-config &&
+		cp .gitmodules pristine-.gitmodules
 	)
 '
 
-test_expect_success 'relative path works with URL' '
+test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
 	(
 		cd reltest &&
 		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
 		git config remote.origin.url ssh://hostname/repo &&
 		git submodule init &&
 		test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
 	)
 '
 
-test_expect_success 'relative path works with user@host:path' '
+test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url ssh://hostname:22/repo &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
+	)
+'
+
+test_expect_success '../subrepo path works with local path - /foo/repo' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url /foo/repo &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = /foo/subrepo
+	)
+'
+
+test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url file:///tmp/repo &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = file:///tmp/subrepo
+	)
+'
+
+test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url helper:://hostname/repo &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
+	)
+'
+
+test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
 	(
 		cd reltest &&
 		cp pristine-.git-config .git/config &&
@@ -507,6 +553,64 @@ test_expect_success 'relative path works with user@host:path' '
 	)
 '
 
+test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url user@host:path/to/repo &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
+	)
+'
+
+test_expect_success '../subrepo works with relative local path - foo/bar' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url foo/bar &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = foo/subrepo
+	)
+'
+
+test_expect_success '../subrepo works with relative local path - ../foo' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url ../foo &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = ../subrepo
+	)
+'
+
+test_expect_success '../subrepo works with relative local path - ../foo/bar' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url ../foo/bar &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = ../foo/subrepo
+	)
+'
+
+test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		mkdir -p a/b/c &&
+		(cd a/b/c; git init) &&
+		git config remote.origin.url ../foo/bar.git &&
+		git submodule add ../bar/a/b/c ./a/b/c &&
+		git submodule init &&
+		test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
+	)
+'
+
 test_expect_success 'moving the superproject does not break submodules' '
 	(
 		cd addtest &&
-- 
1.7.10.2.652.gdffd412

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v8 2/4] submodule: document failure to handle relative superproject origin URLs
  2012-06-03  9:46 [PATCH v8 0/4] submodule: improve support for relative superproject origin URLs Jon Seymour
  2012-06-03  9:46 ` [PATCH v8 1/4] submodule: additional regression tests for relative URLs Jon Seymour
@ 2012-06-03  9:46 ` Jon Seymour
  2012-06-03  9:46 ` [PATCH v8 3/4] submodule: fix sync handling of some " Jon Seymour
  2012-06-03  9:46 ` [PATCH v8 4/4] submodule: fix handling of superproject origin URLs like foo, ./foo and ./foo/bar Jon Seymour
  3 siblings, 0 replies; 10+ messages in thread
From: Jon Seymour @ 2012-06-03  9:46 UTC (permalink / raw)
  To: git; +Cc: Jens.Lehmann, gitster, phil.hord, ramsay, j6t, Jon Seymour

This test case documents several cases where handling of relative
superproject origin URLs doesn't produce an expected result.

submodule.{sub}.url in the superproject is incorrect in these cases:
  foo
  ./foo
  ./foo/bar

The remote.origin.url of the submodule is incorrect in the above cases
and also when the superproject origin URL is like:
  foo/bar
  ../foo
  ../foo/bar

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 t/t7400-submodule-basic.sh | 34 ++++++++++++++++++
 t/t7403-submodule-sync.sh  | 90 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 9428c7a..09e2b9b 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -564,6 +564,18 @@ test_expect_success '../subrepo works with scp-style URL - user@host:path/to/rep
 	)
 '
 
+test_expect_failure '../subrepo works with relative local path - foo' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url foo &&
+		# actual: fails with an error
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = subrepo
+	)
+'
+
 test_expect_success '../subrepo works with relative local path - foo/bar' '
 	(
 		cd reltest &&
@@ -575,6 +587,28 @@ test_expect_success '../subrepo works with relative local path - foo/bar' '
 	)
 '
 
+test_expect_failure '../subrepo works with relative local path - ./foo' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url ./foo &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = subrepo
+	)
+'
+
+test_expect_failure '../subrepo works with relative local path - ./foo/bar' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url ./foo/bar &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = foo/subrepo
+	)
+'
+
 test_expect_success '../subrepo works with relative local path - ../foo' '
 	(
 		cd reltest &&
diff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh
index 3620215..56b933d 100755
--- a/t/t7403-submodule-sync.sh
+++ b/t/t7403-submodule-sync.sh
@@ -26,7 +26,9 @@ test_expect_success setup '
 	(cd super-clone && git submodule update --init) &&
 	git clone super empty-clone &&
 	(cd empty-clone && git submodule init) &&
-	git clone super top-only-clone
+	git clone super top-only-clone &&
+	git clone super relative-clone &&
+	(cd relative-clone && git submodule update --init)
 '
 
 test_expect_success 'change submodule' '
@@ -86,4 +88,90 @@ test_expect_success '"git submodule sync" should not vivify uninteresting submod
 	)
 '
 
+test_expect_failure '"git submodule sync" handles origin URL of the form foo' '
+	(cd relative-clone &&
+	 git remote set-url origin foo &&
+	 git submodule sync &&
+	(cd submodule &&
+	 #actual fails with: "cannot strip off url foo
+	 test "$(git config remote.origin.url)" = "../submodule"
+	)
+	)
+'
+
+test_expect_failure '"git submodule sync" handles origin URL of the form foo/bar' '
+	(cd relative-clone &&
+	 git remote set-url origin foo/bar &&
+	 git submodule sync &&
+	(cd submodule &&
+	 #actual foo/submodule
+	 test "$(git config remote.origin.url)" = "../foo/submodule"
+	)
+	)
+'
+
+test_expect_failure '"git submodule sync" handles origin URL of the form ./foo' '
+	(cd relative-clone &&
+	 git remote set-url origin ./foo &&
+	 git submodule sync &&
+	(cd submodule &&
+	 #actual ./submodule
+	 test "$(git config remote.origin.url)" = "../submodule"
+	)
+	)
+'
+
+test_expect_failure '"git submodule sync" handles origin URL of the form ./foo/bar' '
+	(cd relative-clone &&
+	 git remote set-url origin ./foo/bar &&
+	 git submodule sync &&
+	(cd submodule &&
+	 #actual ./foo/submodule
+	 test "$(git config remote.origin.url)" = "../foo/submodule"
+	)
+	)
+'
+
+test_expect_failure '"git submodule sync" handles origin URL of the form ../foo' '
+	(cd relative-clone &&
+	 git remote set-url origin ../foo &&
+	 git submodule sync &&
+	(cd submodule &&
+	 #actual ../submodule
+	 test "$(git config remote.origin.url)" = "../../submodule"
+	)
+	)
+'
+
+test_expect_failure '"git submodule sync" handles origin URL of the form ../foo/bar' '
+	(cd relative-clone &&
+	 git remote set-url origin ../foo/bar &&
+	 git submodule sync &&
+	(cd submodule &&
+	 #actual ../foo/submodule
+	 test "$(git config remote.origin.url)" = "../../foo/submodule"
+	)
+	)
+'
+
+test_expect_failure '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
+	(cd relative-clone &&
+	 git remote set-url origin ../foo/bar &&
+	 mkdir -p a/b/c &&
+	 ( cd a/b/c &&
+	   git init &&
+	   :> .gitignore &&
+	   git add .gitignore &&
+	   test_tick &&
+	   git commit -m "initial commit" ) &&
+	 git submodule add ../bar/a/b/c ./a/b/c &&
+	 git submodule sync &&
+	(cd a/b/c &&
+	 #actual ../foo/bar/a/b/c
+	 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
+	)
+	)
+'
+
+
 test_done
-- 
1.7.10.2.652.gdffd412

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v8 3/4] submodule: fix sync handling of some relative superproject origin URLs
  2012-06-03  9:46 [PATCH v8 0/4] submodule: improve support for relative superproject origin URLs Jon Seymour
  2012-06-03  9:46 ` [PATCH v8 1/4] submodule: additional regression tests for relative URLs Jon Seymour
  2012-06-03  9:46 ` [PATCH v8 2/4] submodule: document failure to handle relative superproject origin URLs Jon Seymour
@ 2012-06-03  9:46 ` Jon Seymour
  2012-06-03 22:10   ` Junio C Hamano
  2012-06-05 21:18   ` Jens Lehmann
  2012-06-03  9:46 ` [PATCH v8 4/4] submodule: fix handling of superproject origin URLs like foo, ./foo and ./foo/bar Jon Seymour
  3 siblings, 2 replies; 10+ messages in thread
From: Jon Seymour @ 2012-06-03  9:46 UTC (permalink / raw)
  To: git; +Cc: Jens.Lehmann, gitster, phil.hord, ramsay, j6t, Jon Seymour

When the origin URL of the superproject is itself relative, git submodule sync
configures the remote.origin.url configuration property of the submodule
with a path that is relative to the work tree of the superproject
rather than the work tree of the submodule.

To fix this an 'up_path' that navigates from the work tree of the submodule
to the work tree of the superproject needs to be prepended to the URL
otherwise calculated.

Correct handling of superproject origin URLs like foo, ./foo and ./foo/bar is
left to a subsequent patch since an additional change is required to handle
these cases.

The documentation of resolve_relative_url() is expanded to give a more thorough
description of the function's objective is intended to be.

This change also renames the url variable used by cmd_sync() to module_url
and introduces two new variables super_config_url and sub_origin_url to help
explain the purpose of the different urls derived from the module_url.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-submodule.sh          | 53 ++++++++++++++++++++++++++++++++++++++++-------
 t/t7403-submodule-sync.sh |  8 +++----
 2 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 64a70d6..314df20 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -30,7 +30,22 @@ nofetch=
 update=
 prefix=
 
-# Resolve relative url by appending to parent's url
+# The function takes at most 2 arguments. The first argument is the
+# relative URL that navigates from the superproject origin repo to the
+# submodule origin repo. The second up_path argument, if specified, is
+# the relative path that navigates from the submodule working tree to
+# the superproject working tree.
+#
+# The output of the function is the origin URL of the submodule.
+#
+# The output will either be an absolute URL or filesystem path (if the
+# superproject origin URL is an absolute URL or filesystem path,
+# respectively) or a relative file system path (if the superproject
+# origin URL is a relative file system path).
+#
+# When the output is a relative file system path, the path is either
+# relative to the submodule working tree, if up_path is specified, or to
+# the superproject working tree otherwise.
 resolve_relative_url ()
 {
 	remote=$(get_default_remote)
@@ -39,6 +54,17 @@ resolve_relative_url ()
 	url="$1"
 	remoteurl=${remoteurl%/}
 	sep=/
+	up_path="$2"
+
+	case "$remoteurl" in
+		*:*|/*)
+			is_relative=
+			;;
+		*)
+			is_relative=t
+			;;
+	esac
+
 	while test -n "$url"
 	do
 		case "$url" in
@@ -64,7 +90,7 @@ resolve_relative_url ()
 			break;;
 		esac
 	done
-	echo "$remoteurl$sep${url%/}"
+	echo "${is_relative:+${up_path}}$remoteurl$sep${url%/}"
 }
 
 #
@@ -959,19 +985,32 @@ cmd_sync()
 	while read mode sha1 stage sm_path
 	do
 		name=$(module_name "$sm_path")
-		url=$(git config -f .gitmodules --get submodule."$name".url)
+		# path from superproject origin repo to submodule origin repo
+		module_url=$(git config -f .gitmodules --get submodule."$name".url)
 
 		# Possibly a url relative to parent
-		case "$url" in
+		case "$module_url" in
 		./*|../*)
-			url=$(resolve_relative_url "$url") || exit
+			# rewrite foo/bar as ../.. to find path from
+			# submodule work tree to superproject work tree
+			up_path="$(echo "$sm_path" | sed "s/[^/]*/../g")" &&
+			# guarantee a trailing /
+			up_path=${up_path%/}/ &&
+			# path from submodule work tree to submodule origin repo
+			sub_origin_url=$(resolve_relative_url "$module_url" "$up_path") &&
+			# path from superproject work tree to submodule origin repo
+			super_config_url=$(resolve_relative_url "$module_url") || exit
+			;;
+		*)
+			sub_origin_url="$module_url"
+			super_config_url="$module_url"
 			;;
 		esac
 
 		if git config "submodule.$name.url" >/dev/null 2>/dev/null
 		then
 			say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
-			git config submodule."$name".url "$url"
+			git config submodule."$name".url "$super_config_url"
 
 			if test -e "$sm_path"/.git
 			then
@@ -979,7 +1018,7 @@ cmd_sync()
 				clear_local_git_env
 				cd "$sm_path"
 				remote=$(get_default_remote)
-				git config remote."$remote".url "$url"
+				git config remote."$remote".url "$sub_origin_url"
 			)
 			fi
 		fi
diff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh
index 56b933d..98bc74a 100755
--- a/t/t7403-submodule-sync.sh
+++ b/t/t7403-submodule-sync.sh
@@ -99,7 +99,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 &&
@@ -132,7 +132,7 @@ test_expect_failure '"git submodule sync" handles origin URL of the form ./foo/b
 	)
 '
 
-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 &&
@@ -143,7 +143,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 &&
@@ -154,7 +154,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 with deeply nested submodule' '
+test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
 	(cd relative-clone &&
 	 git remote set-url origin ../foo/bar &&
 	 mkdir -p a/b/c &&
-- 
1.7.10.2.652.gdffd412

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v8 4/4] submodule: fix handling of superproject origin URLs like foo, ./foo and ./foo/bar
  2012-06-03  9:46 [PATCH v8 0/4] submodule: improve support for relative superproject origin URLs Jon Seymour
                   ` (2 preceding siblings ...)
  2012-06-03  9:46 ` [PATCH v8 3/4] submodule: fix sync handling of some " Jon Seymour
@ 2012-06-03  9:46 ` Jon Seymour
  3 siblings, 0 replies; 10+ messages in thread
From: Jon Seymour @ 2012-06-03  9:46 UTC (permalink / raw)
  To: git; +Cc: Jens.Lehmann, gitster, phil.hord, ramsay, j6t, Jon Seymour

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v8 3/4] submodule: fix sync handling of some relative superproject origin URLs
  2012-06-03  9:46 ` [PATCH v8 3/4] submodule: fix sync handling of some " Jon Seymour
@ 2012-06-03 22:10   ` Junio C Hamano
  2012-06-03 23:52     ` Jon Seymour
  2012-06-05 21:18   ` Jens Lehmann
  1 sibling, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2012-06-03 22:10 UTC (permalink / raw)
  To: Jon Seymour; +Cc: git, Jens.Lehmann, phil.hord, ramsay, j6t

Jon Seymour <jon.seymour@gmail.com> writes:

> diff --git a/git-submodule.sh b/git-submodule.sh
> index 64a70d6..314df20 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -30,7 +30,22 @@ nofetch=
>  update=
>  prefix=
>  
> -# Resolve relative url by appending to parent's url
> +# The function takes at most 2 arguments. The first argument is the
> +# relative URL that navigates from the superproject origin repo to the
> +# submodule origin repo. The second up_path argument, if specified, is
> +# the relative path that navigates from the submodule working tree to
> +# the superproject working tree.
> +#
> +# The output of the function is the origin URL of the submodule.
> +#
> +# The output will either be an absolute URL or filesystem path (if the
> +# superproject origin URL is an absolute URL or filesystem path,
> +# respectively) or a relative file system path (if the superproject
> +# origin URL is a relative file system path).
> +#
> +# When the output is a relative file system path, the path is either
> +# relative to the submodule working tree, if up_path is specified, or to
> +# the superproject working tree otherwise.
>  resolve_relative_url ()

OK.

> @@ -39,6 +54,17 @@ resolve_relative_url ()
>  	url="$1"
>  	remoteurl=${remoteurl%/}
>  	sep=/
> +	up_path="$2"
> +
> +	case "$remoteurl" in
> +		*:*|/*)
> +			is_relative=
> +			;;
> +		*)
> +			is_relative=t
> +			;;
> +	esac

Style: please align case/esac and the labels on case arms (see how
two existing nested case statements in this function are written).

> @@ -959,19 +985,32 @@ cmd_sync()
>  	while read mode sha1 stage sm_path
>  	do
>  		name=$(module_name "$sm_path")
> -		url=$(git config -f .gitmodules --get submodule."$name".url)
> +		# path from superproject origin repo to submodule origin repo
> +		module_url=$(git config -f .gitmodules --get submodule."$name".url)
>  
>  		# Possibly a url relative to parent
> -		case "$url" in
> +		case "$module_url" in
>  		./*|../*)
> -			url=$(resolve_relative_url "$url") || exit
> +			# rewrite foo/bar as ../.. to find path from
> +			# submodule work tree to superproject work tree
> +			up_path="$(echo "$sm_path" | sed "s/[^/]*/../g")" &&

Didn't we add some workaround for implementations of sed that do not
match and replace a possibly empty pattern?  Am I seeing the same
breakage as c5bc42b (Avoid bug in Solaris xpg4/sed as used in
submodule, 2012-04-09) addressed with this patch?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v8 3/4] submodule: fix sync handling of some relative superproject origin URLs
  2012-06-03 22:10   ` Junio C Hamano
@ 2012-06-03 23:52     ` Jon Seymour
  0 siblings, 0 replies; 10+ messages in thread
From: Jon Seymour @ 2012-06-03 23:52 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Jens.Lehmann, phil.hord, ramsay, j6t

On Mon, Jun 4, 2012 at 8:10 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Jon Seymour <jon.seymour@gmail.com> writes:
>
> Style: please align case/esac and the labels on case arms (see how
> two existing nested case statements in this function are written).

Thanks.

> Didn't we add some workaround for implementations of sed that do not
> match and replace a possibly empty pattern?  Am I seeing the same
> breakage as c5bc42b (Avoid bug in Solaris xpg4/sed as used in
> submodule, 2012-04-09) addressed with this patch?

Have modified accordingly. It may not have mattered *much* in this
case since I think
normalisation during git submodule add would have ensured at least one matching
character, but then I don't pretend to understand the nature of the
Solaris issue and
that would in any case, not protect against a manual .gitmodules edit.

I'll re-roll in a day or so after Jens (and/or others) have had a
chance to comment.

jon.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v8 3/4] submodule: fix sync handling of some relative superproject origin URLs
  2012-06-03  9:46 ` [PATCH v8 3/4] submodule: fix sync handling of some " Jon Seymour
  2012-06-03 22:10   ` Junio C Hamano
@ 2012-06-05 21:18   ` Jens Lehmann
  2012-06-05 22:49     ` Junio C Hamano
  1 sibling, 1 reply; 10+ messages in thread
From: Jens Lehmann @ 2012-06-05 21:18 UTC (permalink / raw)
  To: Jon Seymour; +Cc: git, gitster, phil.hord, ramsay, j6t

Am 03.06.2012 11:46, schrieb Jon Seymour:
> @@ -959,19 +985,32 @@ cmd_sync()
>  	while read mode sha1 stage sm_path
>  	do
>  		name=$(module_name "$sm_path")
> -		url=$(git config -f .gitmodules --get submodule."$name".url)
> +		# path from superproject origin repo to submodule origin repo

This comment is misleading as it only describes part of the truth, in a lot
of cases it'll just be an absolute URL of the submodule.

> +		module_url=$(git config -f .gitmodules --get submodule."$name".url)

And I see no real value of renaming "url" to "module_url" here (but maybe
that is just me).

So I'd vote for dropping that comment and the "url" to "module_url" change.
But apart from that and the issues Junio mentioned in his response this
series is looking good to me.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v8 3/4] submodule: fix sync handling of some relative superproject origin URLs
  2012-06-05 21:18   ` Jens Lehmann
@ 2012-06-05 22:49     ` Junio C Hamano
  2012-06-06 11:09       ` Jon Seymour
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2012-06-05 22:49 UTC (permalink / raw)
  To: Jens Lehmann; +Cc: Jon Seymour, git, phil.hord, ramsay, j6t

Jens Lehmann <Jens.Lehmann@web.de> writes:

> Am 03.06.2012 11:46, schrieb Jon Seymour:
>> @@ -959,19 +985,32 @@ cmd_sync()
>>  	while read mode sha1 stage sm_path
>>  	do
>>  		name=$(module_name "$sm_path")
>> -		url=$(git config -f .gitmodules --get submodule."$name".url)
>> +		# path from superproject origin repo to submodule origin repo
>
> This comment is misleading as it only describes part of the truth, in a lot
> of cases it'll just be an absolute URL of the submodule.
>
>> +		module_url=$(git config -f .gitmodules --get submodule."$name".url)
>
> And I see no real value of renaming "url" to "module_url" here (but maybe
> that is just me).

I tend to agree; there is no other kind of URL involved, and I do
not see a clear motivation behind this renaming.  Renaming url to
module_url would not help much if it is to differenciate URLs to the
repositories of submodule and superproject, so that can't be it.

In any case, I suspect that you would be involved in maintaining
this code in the long haul, so even if it were "just you", your
opinion counts.

> So I'd vote for dropping that comment and the "url" to "module_url" change.
> But apart from that and the issues Junio mentioned in his response this
> series is looking good to me.

Thanks for looking this over.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v8 3/4] submodule: fix sync handling of some relative superproject origin URLs
  2012-06-05 22:49     ` Junio C Hamano
@ 2012-06-06 11:09       ` Jon Seymour
  0 siblings, 0 replies; 10+ messages in thread
From: Jon Seymour @ 2012-06-06 11:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jens Lehmann, git, phil.hord, ramsay, j6t

On Wed, Jun 6, 2012 at 8:49 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Jens Lehmann <Jens.Lehmann@web.de> writes:
>
>> Am 03.06.2012 11:46, schrieb Jon Seymour:
>>> @@ -959,19 +985,32 @@ cmd_sync()
>>>      while read mode sha1 stage sm_path
>>>      do
>>>              name=$(module_name "$sm_path")
>>> -            url=$(git config -f .gitmodules --get submodule."$name".url)
>>> +            # path from superproject origin repo to submodule origin repo
>>
>> This comment is misleading as it only describes part of the truth, in a lot
>> of cases it'll just be an absolute URL of the submodule.

Done. v9 3/4 also updates the header comments for resolve_relative_url to remove
a similar misleading implication.

>>
>>> +            module_url=$(git config -f .gitmodules --get submodule."$name".url)
>>
>> And I see no real value of renaming "url" to "module_url" here (but maybe
>> that is just me).
>
> I tend to agree; there is no other kind of URL involved, and I do
> not see a clear motivation behind this renaming.  Renaming url to
> module_url would not help much if it is to differenciate URLs to the
> repositories of submodule and superproject, so that can't be it.
>
> In any case, I suspect that you would be involved in maintaining
> this code in the long haul, so even if it were "just you", your
> opinion counts.
>

This is reverted in v9.

>> So I'd vote for dropping that comment and the "url" to "module_url" change.
>> But apart from that and the issues Junio mentioned in his response this
>> series is looking good to me.
>
> Thanks for looking this over.

Yes, thank you all.

jon.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-06-06 11:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-03  9:46 [PATCH v8 0/4] submodule: improve support for relative superproject origin URLs Jon Seymour
2012-06-03  9:46 ` [PATCH v8 1/4] submodule: additional regression tests for relative URLs Jon Seymour
2012-06-03  9:46 ` [PATCH v8 2/4] submodule: document failure to handle relative superproject origin URLs Jon Seymour
2012-06-03  9:46 ` [PATCH v8 3/4] submodule: fix sync handling of some " Jon Seymour
2012-06-03 22:10   ` Junio C Hamano
2012-06-03 23:52     ` Jon Seymour
2012-06-05 21:18   ` Jens Lehmann
2012-06-05 22:49     ` Junio C Hamano
2012-06-06 11:09       ` Jon Seymour
2012-06-03  9:46 ` [PATCH v8 4/4] submodule: fix handling of superproject origin URLs like foo, ./foo and ./foo/bar Jon Seymour

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).