Skip to content

Commit

Permalink
Simplify busines logic for relative submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse committed Nov 26, 2022
1 parent 2059279 commit 972770f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
14 changes: 3 additions & 11 deletions src/poetry/vcs/git/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_utils_vcs_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 972770f

Please sign in to comment.