Skip to content

Commit 8a59702

Browse files
committed
Merge branch 'tr/submodule-relative-scp-url' into maint
* tr/submodule-relative-scp-url: submodule: fix relative url parsing for scp-style origin
2 parents ea95907 + ea640cc commit 8a59702

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

git-submodule.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,24 @@ resolve_relative_url ()
3737
die "remote ($remote) does not have a url defined in .git/config"
3838
url="$1"
3939
remoteurl=${remoteurl%/}
40+
sep=/
4041
while test -n "$url"
4142
do
4243
case "$url" in
4344
../*)
4445
url="${url#../}"
45-
remoteurl="${remoteurl%/*}"
46+
case "$remoteurl" in
47+
*/*)
48+
remoteurl="${remoteurl%/*}"
49+
;;
50+
*:*)
51+
remoteurl="${remoteurl%:*}"
52+
sep=:
53+
;;
54+
*)
55+
die "cannot strip one component off url '$remoteurl'"
56+
;;
57+
esac
4658
;;
4759
./*)
4860
url="${url#./}"
@@ -51,7 +63,7 @@ resolve_relative_url ()
5163
break;;
5264
esac
5365
done
54-
echo "$remoteurl/${url%/}"
66+
echo "$remoteurl$sep${url%/}"
5567
}
5668

5769
#

t/t7400-submodule-basic.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,4 +446,42 @@ test_expect_success 'add should fail when path is used by an existing directory'
446446
)
447447
'
448448

449+
test_expect_success 'set up for relative path tests' '
450+
mkdir reltest &&
451+
(
452+
cd reltest &&
453+
git init &&
454+
mkdir sub &&
455+
(
456+
cd sub &&
457+
git init &&
458+
test_commit foo
459+
) &&
460+
git add sub &&
461+
git config -f .gitmodules submodule.sub.path sub &&
462+
git config -f .gitmodules submodule.sub.url ../subrepo &&
463+
cp .git/config pristine-.git-config
464+
)
465+
'
466+
467+
test_expect_success 'relative path works with URL' '
468+
(
469+
cd reltest &&
470+
cp pristine-.git-config .git/config &&
471+
git config remote.origin.url ssh://hostname/repo &&
472+
git submodule init &&
473+
test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
474+
)
475+
'
476+
477+
test_expect_success 'relative path works with user@host:path' '
478+
(
479+
cd reltest &&
480+
cp pristine-.git-config .git/config &&
481+
git config remote.origin.url user@host:repo &&
482+
git submodule init &&
483+
test "$(git config submodule.sub.url)" = user@host:subrepo
484+
)
485+
'
486+
449487
test_done

0 commit comments

Comments
 (0)