diff --git a/src/poetry/vcs/git/backend.py b/src/poetry/vcs/git/backend.py index 484eae45285..a9701738038 100644 --- a/src/poetry/vcs/git/backend.py +++ b/src/poetry/vcs/git/backend.py @@ -134,7 +134,9 @@ def is_sha(self) -> bool: @property def is_ref(self) -> bool: - return self.branch is not None and self.branch.startswith("refs/") + return self.branch is not None and ( + self.branch.startswith("refs/") or self.branch == "HEAD" + ) @property def is_sha_short(self) -> bool: diff --git a/tests/integration/test_utils_vcs_git.py b/tests/integration/test_utils_vcs_git.py index b08ba240839..069566a22c5 100644 --- a/tests/integration/test_utils_vcs_git.py +++ b/tests/integration/test_utils_vcs_git.py @@ -8,6 +8,7 @@ from pathlib import Path from typing import TYPE_CHECKING from typing import Iterator +from typing import TypedDict from urllib.parse import urlparse from urllib.parse import urlunparse @@ -39,6 +40,15 @@ pytestmark = pytest.mark.integration +class GitCloneKwargs(TypedDict): + name: str | None + branch: str | None + tag: str | None + revision: str | None + source_root: Path | None + clean: bool + + @pytest.fixture(autouse=True) def git_mock() -> None: pass @@ -133,7 +143,11 @@ def test_git_local_info( assert info.revision == remote_refs.refs[remote_default_ref].decode("utf-8") +@pytest.mark.parametrize( + "specification", [{}, {"revision": "HEAD"}, {"branch": "HEAD"}] +) def test_git_clone_default_branch_head( + specification: GitCloneKwargs, source_url: str, remote_refs: FetchPackResult, remote_default_ref: bytes, @@ -142,7 +156,7 @@ def test_git_clone_default_branch_head( spy = mocker.spy(Git, "_clone") spy_legacy = mocker.spy(Git, "_clone_legacy") - with Git.clone(url=source_url) as repo: + with Git.clone(url=source_url, **specification) as repo: assert remote_refs.refs[remote_default_ref] == repo.head() spy_legacy.assert_not_called()