|
5 | 5 |
|
6 | 6 | import pytest
|
7 | 7 |
|
| 8 | +from datalad_next.utils import check_symlink_capability |
| 9 | + |
8 | 10 | from datalad_next.tests.utils import rmtree
|
9 | 11 |
|
10 | 12 | from ..gitworktree import (
|
@@ -170,3 +172,58 @@ def test_iter_gitworktree_deadsymlinks(existing_dataset, no_result_rendering):
|
170 | 172 | # it may take a different form, hence not checking for type
|
171 | 173 | assert len(all_items) == 1
|
172 | 174 | assert all_items[0].name == PurePath('file1')
|
| 175 | + |
| 176 | + |
| 177 | +def prep_fp_tester(ds): |
| 178 | + # we expect to process an exact number of files below |
| 179 | + # 3 annexed files, 1 untracked, 1 in git, |
| 180 | + # and possibly 1 symlink in git, 1 symlink untracked |
| 181 | + # we count them up on creation, and then down on test |
| 182 | + fcount = 0 |
| 183 | + |
| 184 | + # TODO bring back the umlaut. But waiting for triage |
| 185 | + # https://github.com/datalad/datalad-next/pull/539#issuecomment-1842605708 |
| 186 | + #content_tmpl = 'content: #ö file_{}\n' |
| 187 | + content_tmpl = 'content: # file_{}\n' |
| 188 | + for i in range(3): |
| 189 | + (ds.pathobj / f'file_{i}').write_text(content_tmpl.format(i)) |
| 190 | + fcount += 1 |
| 191 | + ds.save() |
| 192 | + ds.drop( |
| 193 | + ds.pathobj / 'file_1', |
| 194 | + reckless='availability', |
| 195 | + ) |
| 196 | + # and also add a file to git directly and a have one untracked too |
| 197 | + for i in ('untracked', 'ingit'): |
| 198 | + (ds.pathobj / f'file_{i}').write_text(content_tmpl.format(i)) |
| 199 | + fcount += 1 |
| 200 | + ds.save('file_ingit', to_git=True) |
| 201 | + # and add symlinks (untracked and in git) |
| 202 | + if check_symlink_capability( |
| 203 | + ds.pathobj / '_dummy', ds.pathobj / '_dummy_target' |
| 204 | + ): |
| 205 | + for i in ('symlinkuntracked', 'symlinkingit'): |
| 206 | + tpath = ds.pathobj / f'target_{i}' |
| 207 | + lpath = ds.pathobj / f'file_{i}' |
| 208 | + tpath.write_text(content_tmpl.format(i)) |
| 209 | + lpath.symlink_to(tpath) |
| 210 | + fcount += 1 |
| 211 | + ds.save('file_symlinkingit', to_git=True) |
| 212 | + return fcount, content_tmpl |
| 213 | + |
| 214 | + |
| 215 | +def test_iter_gitworktree_basic_fp(existing_dataset, no_result_rendering): |
| 216 | + ds = existing_dataset |
| 217 | + fcount, content_tmpl = prep_fp_tester(ds) |
| 218 | + |
| 219 | + for ai in filter( |
| 220 | + lambda i: str(i.name.name).startswith('file_'), |
| 221 | + iter_gitworktree(ds.pathobj, fp=True) |
| 222 | + ): |
| 223 | + fcount -= 1 |
| 224 | + if ai.fp: |
| 225 | + assert content_tmpl.format( |
| 226 | + ai.name.name[5:]) == ai.fp.read().decode() |
| 227 | + else: |
| 228 | + assert (ds.pathobj / ai.name).exists() is False |
| 229 | + assert not fcount |
0 commit comments