Skip to content

Commit 2ee297c

Browse files
claudespoorcc
authored andcommitted
Fix four code review findings
- subproject.py: _is_already_pinned now treats a matching tag as sufficient even when on_disk_version carries a resolved revision, preventing freeze_project from silently rewriting tag pins to SHAs - git_types.py: align must_keeps to Sequence[str]|None so both CheckoutOptions collection fields share the same type - git.py: move __all__ to after all imports (was between the git_types and patch imports) - tests/test_util.py: use tmp_path_factory for the outside directory in test_glob_within_root_rejects_escaped_paths so pytest manages cleanup instead of leaving it on disk on failure https://claude.ai/code/session_01Doq8oQtBRH4afusvp9Dv4p
1 parent 9e947d6 commit 2ee297c

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

dfetch/project/subproject.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,11 @@ def freeze_project(self, project: ProjectEntry) -> str | None:
466466
def _is_already_pinned(
467467
self, project: ProjectEntry, on_disk_version: Version
468468
) -> bool:
469-
"""Return True if *project* is already pinned to its on-disk version."""
469+
"""Return True if *project* is already pinned to *on_disk_version*."""
470+
if project.version.tag and project.version.tag == on_disk_version.tag:
471+
return True
470472
return (
471473
project.version.tag == on_disk_version.tag
472474
and project.version.revision == on_disk_version.revision
473-
and (bool(project.version.tag) or self.revision_is_enough())
475+
and self.revision_is_enough()
474476
)

dfetch/vcs/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
unique_parent_dirs,
2323
)
2424
from dfetch.vcs.git_types import CheckoutOptions, Submodule
25+
from dfetch.vcs.patch import Patch, PatchType
2526

2627
__all__ = ["CheckoutOptions", "GitLocalRepo", "GitRemote", "Submodule"]
27-
from dfetch.vcs.patch import Patch, PatchType
2828

2929
logger = get_logger(__name__)
3030

dfetch/vcs/git_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ class CheckoutOptions:
2424
remote: str
2525
version: str
2626
src: str | None = None
27-
must_keeps: list[str] | None = None
27+
must_keeps: Sequence[str] | None = None
2828
ignore: Sequence[str] | None = None

tests/test_util.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,17 @@ def test_glob_within_root_returns_safe_paths(tmp_path):
203203
assert escaped == []
204204

205205

206-
def test_glob_within_root_rejects_escaped_paths(tmp_path):
206+
def test_glob_within_root_rejects_escaped_paths(tmp_path, tmp_path_factory):
207207
"""Paths that resolve outside the root are returned in the escaped list."""
208-
outside = tmp_path.parent / "outside_glob_test"
209-
outside.mkdir(exist_ok=True)
208+
outside = tmp_path_factory.mktemp("outside_glob_test")
210209
(outside / "secret.txt").write_text("data")
211210

212211
from unittest.mock import patch
213212

214213
with patch(
215214
"dfetch.util.util.glob.glob", return_value=[str(outside / "secret.txt")]
216215
):
217-
safe, escaped = glob_within_root("../outside_glob_test/*.txt", tmp_path)
216+
safe, escaped = glob_within_root(str(outside / "*.txt"), tmp_path)
218217

219218
assert safe == []
220219
assert escaped == [str(outside / "secret.txt")]

0 commit comments

Comments
 (0)