|
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.cli import cli
|
12 | 14 | from vcspull.cli.sync import EXIT_ON_ERROR_MSG, NO_REPOS_FOR_TERM_MSG
|
13 | 15 |
|
@@ -256,3 +258,67 @@ def test_sync_broken(
|
256 | 258 | expected_not_in_output = [expected_not_in_output]
|
257 | 259 | for needle in expected_not_in_output:
|
258 | 260 | assert needle not in output
|
| 261 | + |
| 262 | + |
| 263 | +# @pytest.mark.skip("No recreation yet, #366") |
| 264 | +def test_broken_submodule( |
| 265 | + home_path: pathlib.Path, |
| 266 | + config_path: pathlib.Path, |
| 267 | + tmp_path: pathlib.Path, |
| 268 | + git_repo: GitSync, |
| 269 | + create_git_dummy_repo: DummyRepoProtocol, |
| 270 | +) -> None: |
| 271 | + runner = CliRunner() |
| 272 | + |
| 273 | + broken_repo = create_git_dummy_repo( |
| 274 | + repo_name="broken_repo", testfile_filename="dummy_file.txt" |
| 275 | + ) |
| 276 | + |
| 277 | + # Try to recreated gitmodules by hand |
| 278 | + |
| 279 | + # gitmodules_file = pathlib.Path(broken_repo) / ".gitmodules" |
| 280 | + # gitmodules_file.write_text( |
| 281 | + # """ |
| 282 | + # [submodule "broken_submodule"] |
| 283 | + # path = broken_submodule |
| 284 | + # url = ./ |
| 285 | + # """, |
| 286 | + # encoding="utf-8", |
| 287 | + # ) |
| 288 | + |
| 289 | + run( |
| 290 | + [ |
| 291 | + "git", |
| 292 | + "submodule", |
| 293 | + "add", |
| 294 | + "--quiet", |
| 295 | + "--force", |
| 296 | + "--", |
| 297 | + "./", |
| 298 | + "broken_submodule", |
| 299 | + ], |
| 300 | + cwd=str(broken_repo), |
| 301 | + ) |
| 302 | + |
| 303 | + with runner.isolated_filesystem(temp_dir=tmp_path): |
| 304 | + config = { |
| 305 | + "~/github_projects/": { |
| 306 | + "my_git_repo": { |
| 307 | + "url": f"git+file://{git_repo.dir}", |
| 308 | + "remotes": {"test_remote": f"git+file://{git_repo.dir}"}, |
| 309 | + }, |
| 310 | + "broken_repo": { |
| 311 | + "url": f"git+file://{broken_repo}", |
| 312 | + }, |
| 313 | + } |
| 314 | + } |
| 315 | + yaml_config = config_path / ".vcspull.yaml" |
| 316 | + yaml_config_data = yaml.dump(config, default_flow_style=False) |
| 317 | + yaml_config.write_text(yaml_config_data, encoding="utf-8") |
| 318 | + |
| 319 | + # CLI can sync |
| 320 | + result = runner.invoke(cli, ["sync", "broken_repo"]) |
| 321 | + output = "".join(list(result.output)) |
| 322 | + |
| 323 | + assert "No url found for submodule" == output |
| 324 | + assert result.exit_code == 1 |
0 commit comments