|
7 | 7 | import yaml
|
8 | 8 | from click.testing import CliRunner
|
9 | 9 |
|
| 10 | +from libvcs._internal.run import run |
10 | 11 | from libvcs.sync.git import GitSync
|
| 12 | +from tests.conftest import DummyRepoProtocol |
11 | 13 | from vcspull.__about__ import __version__
|
12 | 14 | from vcspull.cli import cli
|
13 | 15 | from vcspull.cli.sync import EXIT_ON_ERROR_MSG, NO_REPOS_FOR_TERM_MSG
|
@@ -353,3 +355,67 @@ def test_sync_broken(
|
353 | 355 | expected_not_in_output = [expected_not_in_output]
|
354 | 356 | for needle in expected_not_in_output:
|
355 | 357 | assert needle not in output
|
| 358 | + |
| 359 | + |
| 360 | +# @pytest.mark.skip("No recreation yet, #366") |
| 361 | +def test_broken_submodule( |
| 362 | + home_path: pathlib.Path, |
| 363 | + config_path: pathlib.Path, |
| 364 | + tmp_path: pathlib.Path, |
| 365 | + git_repo: GitSync, |
| 366 | + create_git_dummy_repo: DummyRepoProtocol, |
| 367 | +) -> None: |
| 368 | + runner = CliRunner() |
| 369 | + |
| 370 | + broken_repo = create_git_dummy_repo( |
| 371 | + repo_name="broken_repo", testfile_filename="dummy_file.txt" |
| 372 | + ) |
| 373 | + |
| 374 | + # Try to recreated gitmodules by hand |
| 375 | + |
| 376 | + # gitmodules_file = pathlib.Path(broken_repo) / ".gitmodules" |
| 377 | + # gitmodules_file.write_text( |
| 378 | + # """ |
| 379 | + # [submodule "broken_submodule"] |
| 380 | + # path = broken_submodule |
| 381 | + # url = ./ |
| 382 | + # """, |
| 383 | + # encoding="utf-8", |
| 384 | + # ) |
| 385 | + |
| 386 | + run( |
| 387 | + [ |
| 388 | + "git", |
| 389 | + "submodule", |
| 390 | + "add", |
| 391 | + "--quiet", |
| 392 | + "--force", |
| 393 | + "--", |
| 394 | + "./", |
| 395 | + "broken_submodule", |
| 396 | + ], |
| 397 | + cwd=str(broken_repo), |
| 398 | + ) |
| 399 | + |
| 400 | + with runner.isolated_filesystem(temp_dir=tmp_path): |
| 401 | + config = { |
| 402 | + "~/github_projects/": { |
| 403 | + "my_git_repo": { |
| 404 | + "url": f"git+file://{git_repo.dir}", |
| 405 | + "remotes": {"test_remote": f"git+file://{git_repo.dir}"}, |
| 406 | + }, |
| 407 | + "broken_repo": { |
| 408 | + "url": f"git+file://{broken_repo}", |
| 409 | + }, |
| 410 | + } |
| 411 | + } |
| 412 | + yaml_config = config_path / ".vcspull.yaml" |
| 413 | + yaml_config_data = yaml.dump(config, default_flow_style=False) |
| 414 | + yaml_config.write_text(yaml_config_data, encoding="utf-8") |
| 415 | + |
| 416 | + # CLI can sync |
| 417 | + result = runner.invoke(cli, ["sync", "broken_repo"]) |
| 418 | + output = "".join(list(result.output)) |
| 419 | + |
| 420 | + assert "No url found for submodule" == output |
| 421 | + assert result.exit_code == 1 |
0 commit comments