Skip to contentSkip to conversation

series: submodule: fix handling of relative superproject origin URLs

PATCH In review Jon Seymour 2 participants 7 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

v5 cover series: submodule: fix handling of relative superproject origin URLs

This series ensures that git submodule handles relative superproject origin URLs correctly.

Current behaviour:

* does not guarantee that the submodule.{name}.url property of the superproject is always confgured with a valid path to the submodule's origin repo that is relative to the working tree of the superproject.
* does not guarantee that the remote.origin.url property of the submodule is always configured with a valid path to the submodule's origin repo that is relative to the working tree of the submodule
* errors out (origin URL = foo) even though this is not strictly necessary.

These changes:

* guarantee that the configured paths are always valid relative paths from the working tree of the repo containing to the configuration to the origin repo of the described submodule.

Jon Seymour (2):
submodule: document failures handling relative superproject origin
URLs
submodule: fix handling of relative superproject origin URLs

 git-submodule.sh           | 57 +++++++++++++++++++++++++++++++++----
 t/t7400-submodule-basic.sh | 60 +++++++++++++++++++++++++++++++++++++++
 t/t7403-submodule-sync.sh  | 70 +++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 180 insertions(+), 7 deletions(-)

v4->v5 changes:
Used test_expect_failure for failing tests.
Added comments to justify statements.
Isolated changes to the relative branch.
Used role-based variable names to help explain transformations.

Signature · 1 line
1.7.10.2.649.g5ca7d80
#1 lore raw

PATCH v5 1/2 submodule: document failures handling relative superproject origin URLs

These tests document how submodule sync and init handle various kinds of relative super project origin URLs. The submodule URL path is ../subrepo.

6 cases are documented:
foo
foo/bar
./foo
./foo/bar
../foo
../foo/bar

---
 t/t7400-submodule-basic.sh | 62 +++++++++++++++++++++++++++++++++++++
 t/t7403-submodule-sync.sh  | 76 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 137 insertions(+), 1 deletion(-)
t/t7400-submodule-basic.sh +62 -0
index 81827e6..08b8d2f 100755
@@ -507,6 +507,68 @@ test_expect_success 'relative path works with user@host:path' '
 	)
 '
 
+test_expect_failure 'relative path works with foo' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		git config remote.origin.url foo &&
+		# actual: fails with an error
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = ./subrepo
+	)
+'
+
+test_expect_success 'relative path works with foo/bar' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		git config remote.origin.url foo/bar &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = foo/subrepo
+	)
+'
+
+test_expect_success 'relative path works with ./foo' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		git config remote.origin.url ./foo &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = ./subrepo
+	)
+'
+
+test_expect_failure 'relative path works with ./foo/bar' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		git config remote.origin.url ./foo/bar &&
+		git submodule init &&
+		#actual: ./foo/subrepo
+		test "$(git config submodule.sub.url)" = foo/subrepo
+	)
+'
+
+test_expect_success 'relative path works with ../foo' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		git config remote.origin.url ../foo &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = ../subrepo
+	)
+'
+
+test_expect_success 'relative path works with ../foo/bar' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		git config remote.origin.url ../foo/bar &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = ../foo/subrepo
+	)
+'
+
 test_expect_success 'moving the superproject does not break submodules' '
 	(
 		cd addtest &&
t/t7403-submodule-sync.sh +75 -1

86 lines not on this page · raw message

Signature · 1 line
1.7.10.2.649.g5ca7d80
#2 lore raw

PATCH v5 2/2 submodule: fix handling of relative superproject origin URLs

In reply to Jon Seymour

When the origin URL of the superproject is itself relative, an operation such as git submodule add, init or sync may result in either the submodule.{name}.url configuration property of the superproject referring to the incorrect location or remote.origin.url configuration property of the submodule referring to the incorrect location or both these conditions. In some cases, git submodule fails to update the configuration and fails with an error condition.

The issue arises in these cases because the origin URL of the superproject needs to be prepended with a prefix that navigates from the submodule to the superproject so that when the submodule URL is concatenated the resulting URL is relative to the working tree of the submodule.

This change fixes handling for relative superproject origin URLs for 6 cases:
foo
foo/bar
./foo
./foo/bar
../foo
../foo/bar

In each case, the configuration properties in the superproject's configuration and the submodule's configuration refer to the correct, relative, location of the submodule's origin repo. In all cases, the configured paths are relative to the working trees of the repositories containing the configuration.

---
 git-submodule.sh           | 57 +++++++++++++++++++++++++++++++++++++++++-----
 t/t7400-submodule-basic.sh |  6 ++---
 t/t7403-submodule-sync.sh  | 18 +++++----------
 3 files changed, 59 insertions(+), 22 deletions(-)
git-submodule.sh +51 -6
index 64a70d6..738eba3 100755
@@ -30,13 +30,35 @@ nofetch=
 update=
 prefix=
 
-# Resolve relative url by appending to parent's url
+# Resolve relative url by appending the submodule url
+# to the superproject's origin URL
+#
+# If the origin URL is itself a relative URL prepend
+# an additional prefix, if present, that represents
+# the relative path from the submodule's working tree
+# to the superprojects' working tree.
+#
+# This behaviour is required to ensure that the origin URL
+# of a submodule, when relative, is relative to the
+# submodule's work tree and not to the superproject's work tree.
+#
 resolve_relative_url ()
 {
 	remote=$(get_default_remote)
 	remoteurl=$(git config "remote.$remote.url") ||
 		remoteurl=$(pwd) # the repository is its own authoritative upstream
 	url="$1"
+	up_path="$2"
+
+	#
+	# ensure all relative paths begin with ./ to enable
+	# selection relative branch of subsequent case "$remoteurl"
+	# statement.
+	#
+	# rewrites foo/bar to ./foo/bar but leaves /foo, :foo ./foo
+	# and ../foo untouched.
+	#
+	remoteurl=$(echo "$remoteurl" | sed "s|^[^/:\\.][^:]*\$|./&|")
 	remoteurl=${remoteurl%/}
 	sep=/
 	while test -n "$url"
@@ -45,6 +67,16 @@ resolve_relative_url ()
 		../*)
 			url="${url#../}"
 			case "$remoteurl" in
+			.*/*)
+				# remove last part
+				remoteurl="${remoteurl%/*}"
+				# remove redundant leading ./
+				remoteurl="${remoteurl#./}"
+				# prefix path from submodule work tree to superproject work tree
+				remoteurl="${up_path}${remoteurl}"
+				# remove trailing /.
+				remoteurl="${remoteurl%/.}"
+				;;
 			*/*)
 				remoteurl="${remoteurl%/*}"
 				;;
@@ -959,19 +991,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 +1024,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
t/t7400-submodule-basic.sh +2 -4
index 08b8d2f..f2f907f 100755
@@ -507,12 +507,11 @@ test_expect_success 'relative path works with user@host:path' '
 	)
 '
 
-test_expect_failure 'relative path works with foo' '
+test_expect_success 'relative path works with foo' '
 	(
 		cd reltest &&
 		cp pristine-.git-config .git/config &&
 		git config remote.origin.url foo &&
-		# actual: fails with an error
 		git submodule init &&
 		test "$(git config submodule.sub.url)" = ./subrepo
 	)
@@ -538,13 +537,12 @@ test_expect_success 'relative path works with ./foo' '
 	)
 '
 
-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 &&
 		git config remote.origin.url ./foo/bar &&
 		git submodule init &&
-		#actual: ./foo/subrepo
 		test "$(git config submodule.sub.url)" = foo/subrepo
 	)
 '
t/t7403-submodule-sync.sh +6 -12
index 9fa4e58..9526f8d 100755
@@ -88,72 +88,66 @@ 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 &&
 	(cd submodule &&
-	 #actual fails with: "cannot strip off url foo
 	 git config remote.origin.url &&
 	 test "$(git config remote.origin.url)" == "../submodule"
 	)
 	)
 '
 
-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 &&
 	(cd submodule &&
-	 #actual foo/submodule
 	 git config remote.origin.url &&
 	 test "$(git config remote.origin.url)" == "../foo/submodule"
 	)
 	)
 '
 
-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 &&
 	(cd submodule &&
-	 #actual ./submodule
 	 git config remote.origin.url &&
 	 test "$(git config remote.origin.url)" == "../submodule"
 	)
 	)
 '
 
-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 &&
 	(cd submodule &&
-	 #actual ./foo/submodule
 	 git config remote.origin.url &&
 	 test "$(git config remote.origin.url)" == "../foo/submodule"
 	)
 	)
 '
 
-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 &&
 	(cd submodule &&
-	 #actual ../submodule
 	 git config remote.origin.url &&
 	 test "$(git config remote.origin.url)" == "../../submodule"
 	)
 	)
 '
 
-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 &&
 	(cd submodule &&
-	 #actual ../foo/submodule
 	 git config remote.origin.url &&
 	 test "$(git config remote.origin.url)" == "../../foo/submodule"
 	)
Signature · 1 line
1.7.10.2.649.g5ca7d80
#3 lore raw

Re: [PATCH v5 2/2] submodule: fix handling of relative superproject origin URLs

Quoted 183 lines · Jon Seymour

When the origin URL of the superproject is itself relative, an operation such as git submodule add, init or sync may result in either the submodule.{name}.url configuration property of the superproject referring to the incorrect location or remote.origin.url configuration property of the submodule referring to the incorrect location or both these conditions. In some cases, git submodule fails to update the configuration and fails with an error condition.

The issue arises in these cases because the origin URL of the superproject needs to be prepended with a prefix that navigates from the submodule to the superproject so that when the submodule URL is concatenated the resulting URL is relative to the working tree of the submodule.

This change fixes handling for relative superproject origin URLs for 6 cases:
 foo
 foo/bar
 ./foo
 ./foo/bar
 ../foo
 ../foo/bar

In each case, the configuration properties in the superproject's configuration and the submodule's configuration refer to the correct, relative, location of the submodule's origin repo. In all cases, the configured paths are relative to the working trees of the repositories containing the configuration.

---
 git-submodule.sh           | 57 +++++++++++++++++++++++++++++++++++++++++----- t/t7400-submodule-basic.sh |  6 ++---
 t/t7403-submodule-sync.sh  | 18 +++++----------

 3 files changed, 59 insertions(+), 22 deletions(-)
git-submodule.sh +0 -0
index 64a70d6..738eba3 100755
@@ -30,13 +30,35 @@ nofetch=

 update=
 prefix=

git-submodule.sh +12 -1
-# Resolve relative url by appending to parent's url
+# Resolve relative url by appending the submodule url
+# to the superproject's origin URL
+#
+# If the origin URL is itself a relative URL prepend
+# an additional prefix, if present, that represents
+# the relative path from the submodule's working tree
+# to the superprojects' working tree.
+#
+# This behaviour is required to ensure that the origin URL
+# of a submodule, when relative, is relative to the
+# submodule's work tree and not to the superproject's work tree.
+#

 resolve_relative_url ()
 {
       remote=$(get_default_remote)
       remoteurl=$(git config "remote.$remote.url") || remoteurl=$(pwd) # the repository is its own authoritative upstream url="$1"
+       up_path="$2"
+
+       #
+       # ensure all relative paths begin with ./ to enable
+       # selection relative branch of subsequent case "$remoteurl"
+       # statement.
+       #
+       # rewrites foo/bar to ./foo/bar but leaves /foo, :foo ./foo
+       # and ../foo untouched.
+       #
+       remoteurl=$(echo "$remoteurl" | sed "s|^[^/:\\.][^:]*\$|./&|") remoteurl=${remoteurl%/}
       sep=/
       while test -n "$url"

git-submodule.sh +0 -0
@@ -45,6 +67,16 @@ resolve_relative_url ()
                ../*)

                       url="${url#../}"
                       case "$remoteurl" in
+                       .*/*)
+                               # remove last part
+                               remoteurl="${remoteurl%/*}"
+                               # remove redundant leading ./
+                               remoteurl="${remoteurl#./}"
+                               # prefix path from submodule work tree to superproject work tree
+                               remoteurl="${up_path}${remoteurl}"
+                               # remove trailing /.
+                               remoteurl="${remoteurl%/.}"
+                               ;;
                       */*)
                               remoteurl="${remoteurl%/*}"
                               ;;

git-submodule.sh +0 -0
@@ -959,19 +991,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

git-submodule.sh +0 -0
@@ -979,7 +1024,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

t/t7400-submodule-basic.sh +0 -0
index 08b8d2f..f2f907f 100755
@@ -507,12 +507,11 @@ test_expect_success 'relative path works with user@host:path' '
        )

 '

t/t7400-submodule-basic.sh +1 -1
-test_expect_failure 'relative path works with foo' '
+test_expect_success 'relative path works with foo' '

       (
               cd reltest &&
               cp pristine-.git-config .git/config && git config remote.origin.url foo &&
-               # actual: fails with an error
               git submodule init &&
               test "$(git config submodule.sub.url)" = ./subrepo )

t/t7400-submodule-basic.sh +0 -0
@@ -538,13 +537,12 @@ test_expect_success 'relative path works with ./foo' '
        )

 '

t/t7400-submodule-basic.sh +1 -1
-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 && git config remote.origin.url ./foo/bar && git submodule init &&
-               #actual: ./foo/subrepo
               test "$(git config submodule.sub.url)" = foo/subrepo )
 '

t/t7403-submodule-sync.sh +0 -0
index 9fa4e58..9526f8d 100755
@@ -88,72 +88,66 @@ test_expect_success '"git submodule sync" should not vivify uninteresting submod
        )

 '

t/t7403-submodule-sync.sh +1 -1
-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' '
Quoted 6 lines

       (cd relative-clone &&
        git remote set-url origin foo
        git submodule sync &&
       (cd submodule &&
-        #actual fails with: "cannot strip off url foo git config remote.origin.url &&

Sorry, it appears I left some debug output in the tests. Will roll this into a v6 with any updates you suggest.

Regards,

jon.

#4 lore raw

Re: [PATCH v5 2/2] submodule: fix handling of relative superproject origin URLs

In reply to Jon Seymour

git-submodule.sh nofetch= · line 41

Quoted 10 lines · Jon Seymour
git-submodule.sh +9 -1
-# Resolve relative url by appending to parent's url
+# Resolve relative url by appending the submodule url
+# to the superproject's origin URL
+#
+# If the origin URL is itself a relative URL prepend
+# an additional prefix, if present, that represents
+# the relative path from the submodule's working tree
+# to the superprojects' working tree.
+#
+# This behaviour is required to ensure that the origin URL

"Required behavior" always seems overstated to me when I read it in comments and so I tend to distrust it. I'd prefer to see "This behaviour is intended to ensure..." But this is only my personal preference.

Quoted 5 lines
git-submodule.sh +3 -0
+# of a submodule, when relative, is relative to the
+# submodule's work tree and not to the superproject's work tree.
+#

 resolve_relative_url ()
 {

Quoted 8 lines

       remote=$(get_default_remote)
       remoteurl=$(git config "remote.$remote.url") || remoteurl=$(pwd) # the repository is its own authoritative upstream url="$1"
+       up_path="$2"
+
+       #
+       # ensure all relative paths begin with ./ to enable

Are we talking about remote urls or local filesystem paths? I think this is all confusing enough without the comments also using terminology inconsistently. Would it be more correct to say "all relatiive urls" here? Or is this function only interested in local filesystem paths?

I realize that urls are paths of a different nature. I pick this nit only in the cause of clarity.

Quoted 6 lines

+       # selection relative branch of subsequent case "$remoteurl"
+       # statement.
+       #
+       # rewrites foo/bar to ./foo/bar but leaves /foo, :foo ./foo
+       # and ../foo untouched.
+       #

In many filesystems, ":foo" and "\foo" are valid filenames. I suspect it is unwise to employ them and expect them not to cause trouble, so I don't know if we should make special efforts to accept them here. But I think it is worth noting.

On the other hand, I do not know how these special characters are represented in urls.

Quoted 7 lines

+       remoteurl=$(echo "$remoteurl" | sed "s|^[^/:\\.][^:]*\$|./&|") remoteurl=${remoteurl%/}
       sep=/
       while test -n "$url"

(quoted diff) +0 -0
@@ -45,6 +67,16 @@ resolve_relative_url ()
                ../*)

                       url="${url#../}"

Quoted 8 lines

                       case "$remoteurl" in
+                       .*/*)
+                               # remove last part
+                               remoteurl="${remoteurl%/*}"
+                               # remove redundant leading ./
+                               remoteurl="${remoteurl#./}"
+                               # prefix path from submodule work tree to superproject work tree
+                               remoteurl="${up_path}${remoteurl}"

Here we seem to be talking about paths since we are concerned with the worktrees. So maybe my earlier concern about "urls" vs. "paths" was miguided. My head swims.

Quoted 6 lines

+                               # remove trailing /.
+                               remoteurl="${remoteurl%/.}"
+                               ;;
                       */*) remoteurl="${remoteurl%/*}" ;;

I haven't tested it, but the rest of this is making more sense to me now.

Phil

#5 lore raw

Re: [PATCH v5 2/2] submodule: fix handling of relative superproject origin URLs

Quoted 8 lines · Phil Hord

Review

Quoted 2 lines · Jon Seymour
(quoted diff) +2 -0
+#
+# This behaviour is required to ensure that the origin URL

"Required behavior" always seems overstated to me when I read it in comments and so I tend to distrust it.  I'd prefer to see "This behaviour is intended to ensure..."  But this is only my personal preference.

Sure.

Quoted 3 lines
Quoted 2 lines

+       #
+       # ensure all relative paths begin with ./ to enable

For clarity, this should be:

ensure all relative superproject origin URLs begin with ./ to enable ...

Quoted 7 lines

Are we talking about remote urls or local filesystem paths?  I think this is all confusing enough without the comments also using terminology inconsistently.  Would it be more correct to say "all relatiive urls" here? Or is this function only interested in local filesystem paths?

I realize that urls are paths of a different nature.  I pick this nit only in the cause of clarity.

How about I rewrite the function blurb as something like:

"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."

Phil/Jens: Perhaps we should rename the function to be:
submodule_origin_url to reflect its intended use?

Quoted 8 lines
Quoted 7 lines

+       # selection relative branch of subsequent case "$remoteurl"
+       # statement.
+       #
+       # rewrites foo/bar to ./foo/bar but leaves /foo, :foo ./foo
+       # and ../foo untouched.
+       #

Quoted 8 lines

In many filesystems, ":foo" and "\foo" are valid filenames. I suspect it is unwise to employ them and expect them not to cause trouble, so I don't know if we should make special efforts to accept them here.  But I think it is worth noting.

On the other hand, I do not know how these special characters are represented in urls.

Perhaps I should indicate 'why' these paths are not touched? Something like:

"Rewrites foo/bar foo/bar as ./foo/bar but leaves ./foo, ../foo, /foo, foo:bar, :bar untouched because the first 2 forms do not require additional qualification and the last forms
are assumed to be absolute URLs or paths."

Perhaps I shouldn't be treating :foo as a possible absolute file system path ? My knowledge of filesystems is not good enough to know if there are filesystems that git supports where :foo might be regarded a valid absolute path?

Quoted 12 lines
Quoted 12 lines

+       remoteurl=$(echo "$remoteurl" | sed "s|^[^/:\\.][^:]*\$|./&|") remoteurl=${remoteurl%/}
       sep=/
       while test -n "$url"

(quoted diff) +0 -0
@@ -45,6 +67,16 @@ resolve_relative_url ()
                ../*)

                       url="${url#../}"
                       case "$remoteurl" in
+                       .*/*)
+                               # remove last part
+                               remoteurl="${remoteurl%/*}"

Quoted 9 lines
Quoted 4 lines

+                               # remove redundant leading ./
+                               remoteurl="${remoteurl#./}"
+                               # prefix path from submodule work tree to superproject work tree
+                               remoteurl="${up_path}${remoteurl}"

Here we seem to be talking about paths since we are concerned with the worktrees.  So maybe my earlier concern about "urls" vs. "paths" was miguided.  My head swims.

This branch of the case statement is specifically when the origin superproject URL is a relative file system path.

Quoted 11 lines
Quoted 7 lines

+                               # remove trailing /.
+                               remoteurl="${remoteurl%/.}"
+                               ;;
                       */*) remoteurl="${remoteurl%/*}" ;;

I haven't tested it, but the rest of this is making more sense to me now.

Phil

Thanks for your review and suggestions.

jon.

#6 lore raw

Re: [PATCH v5 2/2] submodule: fix handling of relative superproject origin URLs

In reply to Jon Seymour
Quoted 8 lines · Jon Seymour

       sep=/
       while test -n "$url"

(quoted diff) +0 -0
@@ -45,6 +67,16 @@ resolve_relative_url ()
                ../*)

                       url="${url#../}" case "$remoteurl" in
+                       .*/*)
+                               # remove last part

Quoted 8 lines

+                               remoteurl="${remoteurl%/*}"
+                               # remove redundant leading ./
+                               remoteurl="${remoteurl#./}"
+                               # prefix path from submodule work tree to superproject work tree
+                               remoteurl="${up_path}${remoteurl}"
+                               # remove trailing /.
+                               remoteurl="${remoteurl%/.}"
+                               ;;

Mmmm. Probably shouldn't be doing these _all_ of these edits on each iteration of the while loop, methinks.

I'll write a test, and fix.

jon.