Skip to content

Commit

Permalink
fix: make git ref resolution less greedy for HEAD
Browse files Browse the repository at this point in the history
This change ensures that when ref `HEAD` is specified, it is not incorrectly
resolved to `refs/head/HEAD`. `HEAD` is not treated as a branch, and correctly
resolved from the ref spec.

Resolves: #7024
Closes: #6874
  • Loading branch information
abn committed Feb 23, 2024
1 parent 0ab6204 commit 1a3c9d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/poetry/vcs/git/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/test_utils_vcs_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,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: dict[str, str],
source_url: str,
remote_refs: FetchPackResult,
remote_default_ref: bytes,
Expand All @@ -142,7 +146,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()
Expand Down

0 comments on commit 1a3c9d4

Please sign in to comment.