Skip to content

Commit 2763b10

Browse files
committed
feat(iter_gitworktree): add ability to report untracked content only
This change is a preparation for replacing the `gitstatus()` helper `_yield_repo_untracked()`, and remove that now duplicate implementation with this standard iterator.
1 parent 71a07f4 commit 2763b10

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

datalad_next/iter_collections/gitworktree.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ def from_worktreeitem(
9393
'no-empty-dir':
9494
('--stage', '--cached', '--exclude-standard',
9595
'--others', '--directory', '--no-empty-directory'),
96+
'only':
97+
('--exclude-standard', '--others'),
98+
'only-whole-dir':
99+
('--exclude-standard', '--others', '--directory'),
100+
'only-no-empty-dir':
101+
('--exclude-standard',
102+
'--others', '--directory', '--no-empty-directory'),
96103
}
97104

98105

@@ -132,12 +139,15 @@ def iter_gitworktree(
132139
Path of a directory in a Git repository to report on. This directory
133140
need not be the root directory of the repository, but must be part of
134141
the repository's work tree.
135-
untracked: {'all', 'whole-dir', 'no-empty-dir'} or None, optional
142+
untracked: {'all', 'whole-dir', 'no-empty-dir', 'only', 'only-whole-dir', 'only-no-empty-dir'} or None, optional
136143
If not ``None``, also reports on untracked work tree content.
137144
``all`` reports on any untracked file; ``whole-dir`` yields a single
138145
report for a directory that is entirely untracked, and not individual
139146
untracked files in it; ``no-empty-dir`` skips any reports on
140-
untracked empty directories.
147+
untracked empty directories. The modes starting with 'only' offer the
148+
same untracked content reporting styles, but only untracked and no
149+
tracked content is reported. For example, 'only' is the corresponding
150+
mode to 'all' with no tracked content being reported.
141151
link_target: bool, optional
142152
If ``True``, information matching a
143153
:class:`~datalad_next.iter_collections.utils.FileSystemItem`

datalad_next/iter_collections/tests/test_itergitworktree.py

+22
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,28 @@ def test_iter_gitworktree_basic_fp(existing_dataset, no_result_rendering):
239239
assert not fcount
240240

241241

242+
def test_iter_gitworktree_untracked_only(modified_dataset):
243+
p = modified_dataset.pathobj
244+
# only untracked files
245+
repo_items = list(iter_gitworktree(p, untracked='only'))
246+
assert all(f.name.name == 'file_u' for f in repo_items)
247+
# same report, but compressed to immediate directory children
248+
dir_items = list(iter_gitworktree(p, untracked='only', recursive='no'))
249+
assert set(f.name.parts[0] for f in repo_items) == \
250+
set(f.name.name for f in dir_items)
251+
# no wholly untracked directories in standard report
252+
assert not any(f.name.name == 'dir_u'
253+
for f in iter_gitworktree(p, untracked='only'))
254+
# but this can be requested
255+
wholedir_items = list(iter_gitworktree(p, untracked='only-whole-dir'))
256+
assert any(f.name.name == 'dir_u' for f in wholedir_items)
257+
# smoke test remaining mode, test case doesn't cause difference
258+
assert any(f.name.name == 'dirempty_u' for f in wholedir_items)
259+
assert not any(f.name.name == 'dirempty_u'
260+
for f in iter_gitworktree(p, untracked='only-no-empty-dir'))
261+
262+
263+
242264
def test_iter_gitworktree_pathspec(modified_dataset):
243265
p = modified_dataset.pathobj
244266
# query for any files that are set to go straight to Git. these are just

0 commit comments

Comments
 (0)