From 972770fcd46c55143c7eeaaf9b42ef787a1ef55c Mon Sep 17 00:00:00 2001 From: Evan Rittenhouse Date: Sat, 26 Nov 2022 14:44:01 -0600 Subject: [PATCH] Simplify busines logic for relative submodules --- src/poetry/vcs/git/backend.py | 14 +++----------- tests/integration/test_utils_vcs_git.py | 2 +- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/poetry/vcs/git/backend.py b/src/poetry/vcs/git/backend.py index df7b8dc4c5a..4bef2825ac4 100644 --- a/src/poetry/vcs/git/backend.py +++ b/src/poetry/vcs/git/backend.py @@ -7,6 +7,7 @@ from pathlib import Path from subprocess import CalledProcessError from typing import TYPE_CHECKING +from urllib.parse import urljoin from dulwich import porcelain from dulwich.client import HTTPUnauthorized @@ -342,22 +343,13 @@ def _clone_submodules(cls, repo: Repo, main_url: str) -> None: path_relative = Path(path.decode("utf-8")) path_absolute = repo_root.joinpath(path_relative) - url_string = url.decode() + url_string = url.decode("utf-8") final_url = url_string submodule_is_relative = bool( relative_submodule_regex.search(url_string) ) if submodule_is_relative: - # Find a root list of url sections to mutate according - # to the relative url - url_sections = [section + "/" for section in main_url.split("/")] - directories_upward = url_string.count("../") - # Walk up the main URL until we know where to insert - # the submodule URL - url_portion_remaining = "".join(url_sections[:-directories_upward]) - # Insert the submodule URL - the last segment of url_string.split() - # is the path relative to the main URL - final_url = url_portion_remaining + url_string.split("../")[-1] + final_url = urljoin(f"{Git.get_remote_url(repo)}/", url_string) source_root = path_absolute.parent source_root.mkdir(parents=True, exist_ok=True) diff --git a/tests/integration/test_utils_vcs_git.py b/tests/integration/test_utils_vcs_git.py index 7c9028bff8b..1738d0e4849 100644 --- a/tests/integration/test_utils_vcs_git.py +++ b/tests/integration/test_utils_vcs_git.py @@ -240,7 +240,7 @@ def test_git_clone_clones_submodules(source_url: str) -> None: assert len(list(submodule_package_directory.glob("*"))) > 1 -def test_git_clone_clones_submodules1_with_relative_urls(source_url: str) -> None: +def test_git_clone_clones_submodules_with_relative_urls(source_url: str) -> None: with Git.clone(url=source_url, branch="relative_submodule") as repo: submodule_package_directory = ( Path(repo.path) / "submodules" / "relative-url-submodule"