Skip to content

Commit

Permalink
Merge branch 'tr/submodule-relative-scp-url' into maint
Browse files Browse the repository at this point in the history
* tr/submodule-relative-scp-url:
  submodule: fix relative url parsing for scp-style origin
  • Loading branch information
Junio C Hamano committed Jan 19, 2011
2 parents ea95907 + ea640cc commit 8a59702
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
16 changes: 14 additions & 2 deletions git-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,24 @@ resolve_relative_url ()
die "remote ($remote) does not have a url defined in .git/config"
url="$1"
remoteurl=${remoteurl%/}
sep=/
while test -n "$url"
do
case "$url" in
../*)
url="${url#../}"
remoteurl="${remoteurl%/*}"
case "$remoteurl" in
*/*)
remoteurl="${remoteurl%/*}"
;;
*:*)
remoteurl="${remoteurl%:*}"
sep=:
;;
*)
die "cannot strip one component off url '$remoteurl'"
;;
esac
;;
./*)
url="${url#./}"
Expand All @@ -51,7 +63,7 @@ resolve_relative_url ()
break;;
esac
done
echo "$remoteurl/${url%/}"
echo "$remoteurl$sep${url%/}"
}

#
Expand Down
38 changes: 38 additions & 0 deletions t/t7400-submodule-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,42 @@ test_expect_success 'add should fail when path is used by an existing directory'
)
'

test_expect_success 'set up for relative path tests' '
mkdir reltest &&
(
cd reltest &&
git init &&
mkdir sub &&
(
cd sub &&
git init &&
test_commit foo
) &&
git add sub &&
git config -f .gitmodules submodule.sub.path sub &&
git config -f .gitmodules submodule.sub.url ../subrepo &&
cp .git/config pristine-.git-config
)
'

test_expect_success 'relative path works with URL' '
(
cd reltest &&
cp pristine-.git-config .git/config &&
git config remote.origin.url ssh://hostname/repo &&
git submodule init &&
test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
)
'

test_expect_success 'relative path works with user@host:path' '
(
cd reltest &&
cp pristine-.git-config .git/config &&
git config remote.origin.url user@host:repo &&
git submodule init &&
test "$(git config submodule.sub.url)" = user@host:subrepo
)
'

test_done

0 comments on commit 8a59702

Please sign in to comment.