Skip to content

Commit 2fa5085

Browse files
Simplify busines logic for relative submodules
1 parent 893b92c commit 2fa5085

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

Diff for: src/poetry/vcs/git/backend.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pathlib import Path
88
from subprocess import CalledProcessError
99
from typing import TYPE_CHECKING
10+
from urllib.parse import urljoin
1011

1112
from dulwich import porcelain
1213
from dulwich.client import HTTPUnauthorized
@@ -345,22 +346,13 @@ def _clone_submodules(cls, repo: Repo, main_url: str) -> None:
345346
path_relative = Path(path.decode("utf-8"))
346347
path_absolute = repo_root.joinpath(path_relative)
347348

348-
url_string = url.decode()
349+
url_string = url.decode("utf-8")
349350
final_url = url_string
350351
submodule_is_relative = bool(
351352
relative_submodule_regex.search(url_string)
352353
)
353354
if submodule_is_relative:
354-
# Find a root list of url sections to mutate according
355-
# to the relative url
356-
url_sections = [section + "/" for section in main_url.split("/")]
357-
directories_upward = url_string.count("../")
358-
# Walk up the main URL until we know where to insert
359-
# the submodule URL
360-
url_portion_remaining = "".join(url_sections[:-directories_upward])
361-
# Insert the submodule URL - the last segment of url_string.split()
362-
# is the path relative to the main URL
363-
final_url = url_portion_remaining + url_string.split("../")[-1]
355+
final_url = urljoin(f"{Git.get_remote_url(repo)}/", url_string)
364356

365357
source_root = path_absolute.parent
366358
source_root.mkdir(parents=True, exist_ok=True)

Diff for: tests/integration/test_utils_vcs_git.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test_git_clone_clones_submodules(source_url: str) -> None:
240240
assert len(list(submodule_package_directory.glob("*"))) > 1
241241

242242

243-
def test_git_clone_clones_submodules1_with_relative_urls(source_url: str) -> None:
243+
def test_git_clone_clones_submodules_with_relative_urls(source_url: str) -> None:
244244
with Git.clone(url=source_url, branch="relative_submodule") as repo:
245245
submodule_package_directory = (
246246
Path(repo.path) / "submodules" / "relative-url-submodule"

0 commit comments

Comments
 (0)