Skip to content

Commit

Permalink
handle trailing slash in git url
Browse files Browse the repository at this point in the history
fixes #7326
  • Loading branch information
dimbleby committed Mar 23, 2024
1 parent 9b3893a commit 8aff3f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/poetry/vcs/git/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def info(cls, repo: Repo | Path) -> GitRepoLocalInfo:

@staticmethod
def get_name_from_source_url(url: str) -> str:
return re.sub(r"(.git)?$", "", url.rsplit("/", 1)[-1])
return re.sub(r"(.git)?$", "", url.rstrip("/").rsplit("/", 1)[-1])

@classmethod
def _fetch_remote_refs(cls, url: str, local: Repo) -> FetchPackResult:
Expand Down
17 changes: 17 additions & 0 deletions tests/vcs/git/test_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

import pytest

from poetry.vcs.git.backend import Git
from poetry.vcs.git.backend import is_revision_sha


Expand All @@ -24,3 +27,17 @@ def test_invalid_revision_sha_min_len() -> None:
def test_invalid_revision_sha_max_len() -> None:
result = is_revision_sha(VALID_SHA + "42")
assert result is False


@pytest.mark.parametrize(
("url"),
[
"git@github.com:python-poetry/poetry.git",
"https://github.com/python-poetry/poetry.git",
"https://github.com/python-poetry/poetry",
"https://github.com/python-poetry/poetry/",
],
)
def test_get_name_from_source_url(url: str) -> None:
name = Git.get_name_from_source_url(url)
assert name == "poetry"

0 comments on commit 8aff3f8

Please sign in to comment.