[PATCH 3/3] fix corner case for relative submodule path calculation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A trailing /. for the superprojects origin is treated as
a full path component. This is wrong. Lets add a test and
fix this.

Signed-off-by: Heiko Voigt <hvoigt@xxxxxxxxxx>
---
 git-submodule.sh           | 22 ++++++++++++++++++++++
 t/t7400-submodule-basic.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/git-submodule.sh b/git-submodule.sh
index ab6b110..9f61a9c 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -69,6 +69,28 @@ resolve_relative_url ()
 		;;
 	esac
 
+	# strip one dot path components
+	tempurl="$remoteurl"
+	remoteurl=
+	sep=
+	while test -n "$tempurl"
+	do
+		case "$tempurl" in
+		*/.)
+			tempurl="${tempurl%/.}"
+			;;
+		?*/*)
+			remoteurl="${tempurl##*/}$sep$remoteurl"
+			tempurl="${tempurl%/*}"
+			sep=/
+		;;
+		*)
+			remoteurl="$tempurl$sep$remoteurl"
+			tempurl=
+			;;
+		esac
+	done
+
 	while test -n "$url"
 	do
 		case "$url" in
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 3c2afa6..1b4cc00 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -518,6 +518,50 @@ test_expect_success 'subrepo is NOT considered a relative path"' '
 	)
 '
 
+test_expect_success '../subrepo works with absolute local path - "$submodurl/repo/."' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url "$submodurl/repo/." &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = "$submodurl/subrepo"
+	)
+'
+
+test_expect_success '../subrepo works with absolute local path - "$submodurl/repo/./"' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url "$submodurl/repo/./" &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = "$submodurl/subrepo"
+	)
+'
+
+test_expect_success '../subrepo works with absolute local path - "$submodurl/./repo/."' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url "$submodurl/./repo/." &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = "$submodurl/subrepo"
+	)
+'
+
+test_expect_success '../subrepo works with absolute local path - "$submodurl/././repo/."' '
+	(
+		cd reltest &&
+		cp pristine-.git-config .git/config &&
+		cp pristine-.gitmodules .gitmodules &&
+		git config remote.origin.url "$submodurl/././repo/." &&
+		git submodule init &&
+		test "$(git config submodule.sub.url)" = "$submodurl/subrepo"
+	)
+'
+
 test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
 	(
 		cd reltest &&
-- 
1.8.0.3.gaed4666

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]