submodule: fix handling of superproject origin URLs like foo, ./foo and ./foo/bar

Currently git submodule init and git submodule sync fail with an error if the superproject origin URL is of the form foo but succeed 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 and embedded ./'s are removed from the resulting derived URLs. Signed-off-by: Jon Seymour <jon.seymour@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jon Seymour committed Jun 6, 2012 at 21:57 UTC 758615e2517db8b9fda9218afded06a3e1b42e20
3 files changed +18 -8
git-submodule.sh
+12 -2
@@ -60,8 +60,12 @@ resolve_relative_url ()
60 *:*|/*)
61 is_relative=
62 ;;
63 + ./*|../*)
64 + is_relative=t
65 + ;;
66 *)
67 is_relative=t
68 + remoteurl="./$remoteurl"
69 ;;
70 esac
71
@@ -79,7 +83,12 @@ resolve_relative_url ()
83 sep=:
84 ;;
85 *)
82 - die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")"
86 + if test -z "$is_relative" || test "." = "$remoteurl"
87 + then
88 + die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")"
89 + else
90 + remoteurl=.
91 + fi
92 ;;
93 esac
94 ;;
@@ -90,7 +99,8 @@ resolve_relative_url ()
99 break;;
100 esac
101 done
93 - echo "${is_relative:+${up_path}}$remoteurl$sep${url%/}"
102 + remoteurl="$remoteurl$sep${url%/}"
103 + echo "${is_relative:+${up_path}}${remoteurl#./}"
104 }
105
106 #
t/t7400-submodule-basic.sh
+3 -3
@@ -564,7 +564,7 @@ test_expect_success '../subrepo works with scp-style URL - user@host:path/to/rep
564 )
565 '
566
567 -test_expect_failure '../subrepo works with relative local path - foo' '
567 +test_expect_success '../subrepo works with relative local path - foo' '
568 (
569 cd reltest &&
570 cp pristine-.git-config .git/config &&
@@ -587,7 +587,7 @@ test_expect_success '../subrepo works with relative local path - foo/bar' '
587 )
588 '
589
590 -test_expect_failure '../subrepo works with relative local path - ./foo' '
590 +test_expect_success '../subrepo works with relative local path - ./foo' '
591 (
592 cd reltest &&
593 cp pristine-.git-config .git/config &&
@@ -598,7 +598,7 @@ test_expect_failure '../subrepo works with relative local path - ./foo' '
598 )
599 '
600
601 -test_expect_failure '../subrepo works with relative local path - ./foo/bar' '
601 +test_expect_success '../subrepo works with relative local path - ./foo/bar' '
602 (
603 cd reltest &&
604 cp pristine-.git-config .git/config &&
t/t7403-submodule-sync.sh
+3 -3
@@ -88,7 +88,7 @@ test_expect_success '"git submodule sync" should not vivify uninteresting submod
88 )
89 '
90
91 -test_expect_failure '"git submodule sync" handles origin URL of the form foo' '
91 +test_expect_success '"git submodule sync" handles origin URL of the form foo' '
92 (cd relative-clone &&
93 git remote set-url origin foo &&
94 git submodule sync &&
@@ -110,7 +110,7 @@ test_expect_success '"git submodule sync" handles origin URL of the form foo/bar
110 )
111 '
112
113 -test_expect_failure '"git submodule sync" handles origin URL of the form ./foo' '
113 +test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
114 (cd relative-clone &&
115 git remote set-url origin ./foo &&
116 git submodule sync &&
@@ -121,7 +121,7 @@ test_expect_failure '"git submodule sync" handles origin URL of the form ./foo'
121 )
122 '
123
124 -test_expect_failure '"git submodule sync" handles origin URL of the form ./foo/bar' '
124 +test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
125 (cd relative-clone &&
126 git remote set-url origin ./foo/bar &&
127 git submodule sync &&