|
9 | 9 | from conftest import ( |
10 | 10 | GIT, |
11 | 11 | add_commit, |
| 12 | + chdir, |
12 | 13 | cmd, |
13 | 14 | create_branch, |
14 | 15 | create_repo, |
@@ -314,6 +315,69 @@ def test_update_auto_cache(tmpdir): |
314 | 315 | assert bar_head_newer in rev_list(auto_cache_dir / "bar" / bar_hash) |
315 | 316 |
|
316 | 317 |
|
| 318 | +def test_update_auto_cache_skipped_remote_update(tmpdir): |
| 319 | + foo_remote = Path(tmpdir / 'remotes' / 'foo') |
| 320 | + bar_remote = Path(tmpdir / 'remotes' / 'bar') |
| 321 | + auto_cache_dir = Path(tmpdir / 'auto_cache_dir') |
| 322 | + |
| 323 | + def create_foo_bar_commits(): |
| 324 | + add_commit(foo_remote, 'new commit') |
| 325 | + add_commit(bar_remote, 'new commit') |
| 326 | + foo_head = rev_parse(foo_remote, 'HEAD') |
| 327 | + bar_head = rev_parse(bar_remote, 'HEAD') |
| 328 | + return foo_head, bar_head |
| 329 | + |
| 330 | + def setup_workspace_and_west_update(workspace, foo_head, bar_head): |
| 331 | + setup_cache_workspace( |
| 332 | + workspace, |
| 333 | + foo_remote=foo_remote, |
| 334 | + foo_head=foo_head, |
| 335 | + bar_remote=bar_remote, |
| 336 | + bar_head=bar_head, |
| 337 | + ) |
| 338 | + with chdir(workspace): |
| 339 | + stdout = cmd(['-v', 'update', '--auto-cache', auto_cache_dir]) |
| 340 | + return stdout |
| 341 | + |
| 342 | + create_repo(foo_remote) |
| 343 | + create_repo(bar_remote) |
| 344 | + foo_commit1, bar_commit1 = create_foo_bar_commits() |
| 345 | + foo_commit2, bar_commit2 = create_foo_bar_commits() |
| 346 | + |
| 347 | + # run initial west update to setup auto-cache and get cache directories |
| 348 | + setup_workspace_and_west_update( |
| 349 | + tmpdir / 'workspace1', |
| 350 | + foo_head=foo_commit1, |
| 351 | + bar_head=bar_commit1, |
| 352 | + ) |
| 353 | + |
| 354 | + # read the auto-cache hashes from foo and bar |
| 355 | + (bar_hash,) = [p for p in (auto_cache_dir / 'bar').iterdir() if p.is_dir()] |
| 356 | + auto_cache_dir_bar = auto_cache_dir / 'bar' / bar_hash |
| 357 | + (foo_hash,) = [p for p in (auto_cache_dir / 'foo').iterdir() if p.is_dir()] |
| 358 | + auto_cache_dir_foo = auto_cache_dir / 'foo' / foo_hash |
| 359 | + |
| 360 | + # Imitate that foo remote is temporarily offline by moving it temporarily. |
| 361 | + # Since foo and bar revisions are used which are already contained in the auto-cache,. |
| 362 | + # west update should work with according messages as there is no need to update remotes. |
| 363 | + foo_moved = Path(tmpdir / 'remotes' / 'foo.moved') |
| 364 | + shutil.move(foo_remote, foo_moved) |
| 365 | + stdout = setup_workspace_and_west_update( |
| 366 | + tmpdir / 'workspace2', |
| 367 | + foo_head=foo_commit2, |
| 368 | + bar_head=bar_commit2, |
| 369 | + ) |
| 370 | + shutil.move(foo_moved, foo_remote) |
| 371 | + msgs = [ |
| 372 | + f"foo: auto-cache remote update is skipped as it already contains revision {foo_commit2}", |
| 373 | + f"foo: cloning from {auto_cache_dir_foo}", |
| 374 | + f"bar: auto-cache remote update is skipped as it already contains revision {bar_commit2}", |
| 375 | + f"bar: cloning from {auto_cache_dir_bar}", |
| 376 | + ] |
| 377 | + for msg in msgs: |
| 378 | + assert msg in stdout |
| 379 | + |
| 380 | + |
317 | 381 | def test_update_caches_priorities(tmpdir): |
318 | 382 | # Test that the correct cache is used if multiple caches are specified |
319 | 383 | # e.g. if 'west update --name-cache X --path-cache Y --auto-cache Z' |
|
0 commit comments