Skip to content

Commit

Permalink
rf(iter_gitstatus): simplify _path_has_untracked() helper
Browse files Browse the repository at this point in the history
We can now benefit from the recently introduced submodule recursion, and
need not implement that separately.
  • Loading branch information
mih committed Jun 10, 2024
1 parent 98c8ab0 commit 87fef46
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
13 changes: 4 additions & 9 deletions datalad_next/iter_collections/gitstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _yield_dir_items(
# there is no recursion, avoid wasting cycles on listing individual
# files in subdirectories
untracked = 'whole-dir' if untracked == 'all' else untracked
# gather all dierectory items upfront, we subtract the ones reported
# gather all directory items upfront, we subtract the ones reported
# modified later and lastly yield all untracked content from them
dir_items = {
str(item.name): item
Expand Down Expand Up @@ -192,7 +192,7 @@ def _yield_dir_items(
item.add_modification_type(
GitContainerModificationType.modified_content)
if untracked is not None \
and _path_has_untracked(path / item.path):
and _path_has_untracked(dir_path):
item.add_modification_type(
GitContainerModificationType.untracked_content)
else:
Expand Down Expand Up @@ -236,6 +236,7 @@ def _yield_dir_items(
else:
# this is on a directory. if it appears here, it has
# no modified content
testpath = path / dir_item.path
if _path_has_untracked(path / dir_item.path):
item.status = GitDiffStatus.modification
item.add_modification_type(
Expand Down Expand Up @@ -398,16 +399,10 @@ def _path_has_untracked(path: Path) -> bool:
untracked='only-no-empty-dir',
link_target=False,
fp=False,
recursive='submodules',
):
# fast exit on the first detection
return True
# we need to find all submodules, regardless of mode.
# untracked content can also be in a submodule underneath
# a directory
for subm in iter_submodules(path):
if _path_has_untracked(path / subm.path):
# fast exit on the first detection
return True
# only after we saw everything we can say there is nothing
return False

Expand Down
3 changes: 2 additions & 1 deletion datalad_next/iter_collections/tests/test_itergitstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def _assert_testcases(st, tc):
assert st[c['name']].status == c['status']
mod_types = st[c['name']].modification_types
if 'qual' in c:
assert set(mod_types) == set(c['qual'])
assert set(mod_types) == set(c['qual']), \
f'Mismatch for {c=!r}'
else:
assert mod_types is None

Expand Down

0 comments on commit 87fef46

Please sign in to comment.