submodule: fix relative url parsing for scp-style origin
The function resolve_relative_url was not prepared to deal with an scp-style origin 'user@host:path' in the case where 'path' is only a single component. Fix this by extending the logic that strips one path component from the $remoteurl. Also add tests for both styles of URLs. Noticed-by: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Jan 10, 2011 at 11:37 UTC
ea640cc691d56f7151c5ba654b09c4a987dbef93
2 files changed
+52
-2
git-submodule.sh
+14
-2
@@ -36,12 +36,24 @@ resolve_relative_url ()
36
die "remote ($remote) does not have a url defined in .git/config"
37
url="$1"
38
remoteurl=${remoteurl%/}
39
+ sep=/
40
while test -n "$url"
41
do
42
case "$url" in
43
../*)
44
url="${url#../}"
44
- remoteurl="${remoteurl%/*}"
45
+ case "$remoteurl" in
46
+ */*)
47
+ remoteurl="${remoteurl%/*}"
48
+ ;;
49
+ *:*)
50
+ remoteurl="${remoteurl%:*}"
51
+ sep=:
52
+ ;;
53
+ *)
54
+ die "cannot strip one component off url '$remoteurl'"
55
+ ;;
56
+ esac
57
;;
58
./*)
59
url="${url#./}"
@@ -50,7 +62,7 @@ resolve_relative_url ()
62
break;;
63
esac
64
done
53
- echo "$remoteurl/${url%/}"
65
+ echo "$remoteurl$sep${url%/}"
66
}
67
68
#
t/t7400-submodule-basic.sh
+38
@@ -331,4 +331,42 @@ test_expect_success 'add submodules without specifying an explicit path' '
331
git config -f .gitmodules submodule.bare.path bare
332
'
333
334
+test_expect_success 'set up for relative path tests' '
335
+ mkdir reltest &&
336
+ (
337
+ cd reltest &&
338
+ git init &&
339
+ mkdir sub &&
340
+ (
341
+ cd sub &&
342
+ git init &&
343
+ test_commit foo
344
+ ) &&
345
+ git add sub &&
346
+ git config -f .gitmodules submodule.sub.path sub &&
347
+ git config -f .gitmodules submodule.sub.url ../subrepo &&
348
+ cp .git/config pristine-.git-config
349
+ )
350
+'
351
+
352
+test_expect_success 'relative path works with URL' '
353
+ (
354
+ cd reltest &&
355
+ cp pristine-.git-config .git/config &&
356
+ git config remote.origin.url ssh://hostname/repo &&
357
+ git submodule init &&
358
+ test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
359
+ )
360
+'
361
+
362
+test_expect_success 'relative path works with user@host:path' '
363
+ (
364
+ cd reltest &&
365
+ cp pristine-.git-config .git/config &&
366
+ git config remote.origin.url user@host:repo &&
367
+ git submodule init &&
368
+ test "$(git config submodule.sub.url)" = user@host:subrepo
369
+ )
370
+'
371
+
372
test_done