Skip to content

Commit 2a97d06

Browse files
claudespoorcc
authored andcommitted
Fix _apply_move scope, _revision_only_mode branch guard, and docstrings
- git.py _apply_move: narrow try/except to cover only move_directory_contents so the "didn't match any files" warning is not emitted for a safe_rm failure after a successful move; return early on FileNotFoundError - subproject.py _revision_only_mode: remove the not-branch guard so the predicate matches check_wanted_with_local (revision + revision_is_enough is sufficient, branch presence is irrelevant) - git.py ignored_files / any_changes_or_untracked: document the intentional asymmetry — ignored_files returns [] for a missing path while any_changes_or_untracked raises RuntimeError because callers must verify existence first https://claude.ai/code/session_01Doq8oQtBRH4afusvp9Dv4p
1 parent 2ee297c commit 2a97d06

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

dfetch/project/subproject.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,7 @@ def _on_disk_hash(self) -> str | None:
374374

375375
def _revision_only_mode(self) -> bool:
376376
"""Return True when the wanted version should be resolved by revision alone."""
377-
return (
378-
not self.wanted_version.branch
379-
and bool(self.wanted_version.revision)
380-
and self.revision_is_enough()
381-
)
377+
return bool(self.wanted_version.revision) and self.revision_is_enough()
382378

383379
def _check_for_newer_version(self) -> Version | None:
384380
"""Check if a newer version is available on the given branch.

dfetch/vcs/git.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,14 @@ def _apply_move(chosen: Path, repo_root: Path, remote: str) -> None:
443443
"""Move the contents of *chosen* to the repo root and remove the empty parent."""
444444
try:
445445
move_directory_contents(str(chosen), ".")
446-
parts = chosen.relative_to(repo_root).parts
447-
if parts:
448-
safe_rm(repo_root / parts[0], within=repo_root)
449446
except FileNotFoundError:
450447
logger.warning(
451448
f"The 'src:' filter '{chosen}' didn't match any files from '{remote}'"
452449
)
450+
return
451+
parts = chosen.relative_to(repo_root).parts
452+
if parts:
453+
safe_rm(repo_root / parts[0], within=repo_root)
453454

454455
@staticmethod
455456
def _move_src_folder_up(remote: str, src: str) -> None:
@@ -569,7 +570,11 @@ def create_diff(
569570
return str(result.stdout.decode())
570571

571572
def ignored_files(self) -> Sequence[str]:
572-
"""List of ignored files in this repository."""
573+
"""List of ignored files in this repository.
574+
575+
Returns an empty list if the repository path does not exist (e.g. during
576+
an initial fetch before the local copy has been created).
577+
"""
573578
if not Path(self._path).exists():
574579
return []
575580

@@ -591,7 +596,12 @@ def ignored_files(self) -> Sequence[str]:
591596
)
592597

593598
def any_changes_or_untracked(self) -> bool:
594-
"""Return True if the repo has any changed or untracked files."""
599+
"""Return True if the repo has any changed or untracked files.
600+
601+
Raises RuntimeError if the repository path does not exist. Callers are
602+
expected to verify existence first (e.g. via on_disk_version) before
603+
invoking this method.
604+
"""
595605
if not Path(self._path).exists():
596606
raise RuntimeError("Path does not exist.")
597607

0 commit comments

Comments
 (0)