|
5 | 5 | import re |
6 | 6 | import shutil |
7 | 7 | import subprocess |
| 8 | +import sys |
8 | 9 | import textwrap |
9 | 10 | from pathlib import Path, PurePath |
10 | 11 |
|
@@ -239,6 +240,122 @@ def test_list_sha(west_update_tmpdir): |
239 | 240 | assert cmd('list -f {sha}').startswith("N/A") |
240 | 241 |
|
241 | 242 |
|
| 243 | +def test_manifest_untracked(west_update_tmpdir): |
| 244 | + |
| 245 | + def check(expected, cwd=None): |
| 246 | + out_lines = cmd("manifest --untracked", cwd=cwd).splitlines() |
| 247 | + assert out_lines == expected |
| 248 | + |
| 249 | + # Ensure that all projects are active |
| 250 | + projs = cmd('list -f {name}').splitlines() |
| 251 | + assert projs == ['manifest', 'Kconfiglib', 'tagged_repo', 'net-tools'] |
| 252 | + |
| 253 | + # Disable Kconfiglib |
| 254 | + cmd('config manifest.group-filter -- -Kconfiglib-group') |
| 255 | + |
| 256 | + # Ensure that Kconfiglib is inactive |
| 257 | + projs = cmd('list -f {name}').splitlines() |
| 258 | + assert projs == ['manifest', 'tagged_repo', 'net-tools'] |
| 259 | + projs = cmd('list --all -f {name}').splitlines() |
| 260 | + assert projs == ['manifest', 'Kconfiglib', 'tagged_repo', 'net-tools'] |
| 261 | + |
| 262 | + topdir = Path(west_update_tmpdir) |
| 263 | + |
| 264 | + # No untracked files yet |
| 265 | + check(list()) |
| 266 | + |
| 267 | + (topdir / "dir").mkdir() |
| 268 | + # Untracked dir |
| 269 | + check(['dir']) |
| 270 | + |
| 271 | + (topdir / "unt").mkdir() |
| 272 | + (topdir / "unt" / "file.yml").touch() |
| 273 | + # Ensure we show the dir as untracked, not the file |
| 274 | + check(['dir', 'unt']) |
| 275 | + |
| 276 | + # Add a file to see it's displayed correctly as untracked |
| 277 | + (topdir / "file.txt").touch() |
| 278 | + check(['dir', 'file.txt', 'unt']) |
| 279 | + (topdir / 'subdir' / "z.py").touch() |
| 280 | + check(['dir', 'file.txt', str(Path('subdir/z.py')), 'unt']) |
| 281 | + |
| 282 | + (topdir / "subdir" / "new").mkdir() |
| 283 | + (topdir / "subdir" / "new" / "afile.txt").touch() |
| 284 | + check(['dir', 'file.txt', str(Path('subdir/new')), |
| 285 | + str(Path('subdir/z.py')), 'unt']) |
| 286 | + |
| 287 | + # Check relative paths |
| 288 | + check([str(Path('../dir')), str(Path('../file.txt')), |
| 289 | + str(Path('../subdir/new')), str(Path('../subdir/z.py')), '.'], |
| 290 | + cwd=str(Path("unt/"))) |
| 291 | + |
| 292 | + # Add a file to an existing project, ignored by --untracked |
| 293 | + (topdir / "net-tools" / "test_manifest_untracked.file").touch() |
| 294 | + check(['dir', 'file.txt', str(Path('subdir/new')), str(Path('subdir/z.py')), |
| 295 | + 'unt']) |
| 296 | + |
| 297 | + kconfiglib = Path(topdir / "subdir" / "Kconfiglib") |
| 298 | + # Same but with an inactive project |
| 299 | + (kconfiglib / "test_manifest_untracked.file").touch() |
| 300 | + check(['dir', 'file.txt', str(Path('subdir/new')), str(Path('subdir/z.py')), |
| 301 | + 'unt']) |
| 302 | + |
| 303 | + # Copy (via clone) a full Git repo so we verify that those are also |
| 304 | + # displayed as untracked. |
| 305 | + clone(topdir / "net-tools", Path('subdir/acopy')) |
| 306 | + clone(topdir / "net-tools", Path('tmpcopy')) |
| 307 | + |
| 308 | + check(['dir', 'file.txt', str(Path('subdir/acopy')), str(Path('subdir/new')), |
| 309 | + str(Path('subdir/z.py')), 'tmpcopy', 'unt']) |
| 310 | + |
| 311 | + # Empty a project so it's not a Git repo anymore |
| 312 | + (topdir / "net-tools" / ".git").rename(topdir / "net-tools" / "former-git") |
| 313 | + # Should make no difference |
| 314 | + check(['dir', 'file.txt', str(Path('subdir/acopy')), str(Path('subdir/new')), |
| 315 | + str(Path('subdir/z.py')), 'tmpcopy', 'unt']) |
| 316 | + |
| 317 | + # Same with an inactive project |
| 318 | + (kconfiglib / ".git").rename(kconfiglib / "former-git") |
| 319 | + # Should make no difference |
| 320 | + check(['dir', 'file.txt', str(Path('subdir/acopy')), str(Path('subdir/new')), |
| 321 | + str(Path('subdir/z.py')), 'tmpcopy', 'unt']) |
| 322 | + |
| 323 | + # Even if we make the whole inactive project disappear it should make no |
| 324 | + # difference at all, except that the renamed dir will show up. |
| 325 | + (kconfiglib).rename(topdir / "subdir" / "other") |
| 326 | + check(['dir', 'file.txt', str(Path('subdir/acopy')), str(Path('subdir/new')), |
| 327 | + str(Path('subdir/other')), str(Path('subdir/z.py')), 'tmpcopy', 'unt']) |
| 328 | + |
| 329 | +@pytest.mark.skipif(sys.platform.startswith("win"), reason="symbolic links not tested on Windows") |
| 330 | +def test_manifest_untracked_with_symlinks(west_update_tmpdir): |
| 331 | + |
| 332 | + def check(expected, cwd=None): |
| 333 | + out_lines = cmd("manifest --untracked", cwd=cwd).splitlines() |
| 334 | + assert out_lines == expected |
| 335 | + |
| 336 | + # Disable Kconfiglib to have an inactive project |
| 337 | + cmd('config manifest.group-filter -- -Kconfiglib-group') |
| 338 | + |
| 339 | + # Ensure that Kconfiglib is inactive |
| 340 | + projs = cmd('list -f {name}').splitlines() |
| 341 | + assert projs == ['manifest', 'tagged_repo', 'net-tools'] |
| 342 | + |
| 343 | + # Create a folder symlink |
| 344 | + Path('asl').symlink_to(Path('subdir/Kconfiglib')) |
| 345 | + # Create another one |
| 346 | + Path('anothersl').symlink_to(Path('../')) |
| 347 | + # Yet another one |
| 348 | + Path('subdir/yetanothersl').symlink_to(Path('tagged_repo')) |
| 349 | + # check that symlinks are displayed like any other regular untracked file or |
| 350 | + # directory |
| 351 | + check(['anothersl', 'asl', str(Path('subdir/yetanothersl'))]) |
| 352 | + |
| 353 | + # File symlink tests, should all be displayed as untracked as well |
| 354 | + Path('filesl.yml').symlink_to(Path('zephyr/west.yml')) |
| 355 | + Path('subdir/afsl.py').symlink_to(Path('net-tools/scripts/test.py')) |
| 356 | + check(['anothersl', 'asl', 'filesl.yml', str(Path('subdir/afsl.py')), |
| 357 | + str(Path('subdir/yetanothersl'))]) |
| 358 | + |
242 | 359 | def test_manifest_freeze(west_update_tmpdir): |
243 | 360 | # We should be able to freeze manifests. |
244 | 361 | actual = cmd('manifest --freeze').splitlines() |
|
0 commit comments