|
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
|
13 | 15 |
|
@@ -183,3 +185,67 @@ def test_sync_broken(
|
183 | 185 | expected_not_in_output = [expected_not_in_output]
|
184 | 186 | for needle in expected_not_in_output:
|
185 | 187 | assert needle not in output
|
| 188 | + |
| 189 | + |
| 190 | +# @pytest.mark.skip("No recreation yet, #366") |
| 191 | +def test_broken_submodule( |
| 192 | + home_path: pathlib.Path, |
| 193 | + config_path: pathlib.Path, |
| 194 | + tmp_path: pathlib.Path, |
| 195 | + git_repo: GitSync, |
| 196 | + create_git_dummy_repo: DummyRepoProtocol, |
| 197 | +) -> None: |
| 198 | + runner = CliRunner() |
| 199 | + |
| 200 | + broken_repo = create_git_dummy_repo( |
| 201 | + repo_name="broken_repo", testfile_filename="dummy_file.txt" |
| 202 | + ) |
| 203 | + |
| 204 | + # Try to recreated gitmodules by hand |
| 205 | + |
| 206 | + # gitmodules_file = pathlib.Path(broken_repo) / ".gitmodules" |
| 207 | + # gitmodules_file.write_text( |
| 208 | + # """ |
| 209 | + # [submodule "broken_submodule"] |
| 210 | + # path = broken_submodule |
| 211 | + # url = ./ |
| 212 | + # """, |
| 213 | + # encoding="utf-8", |
| 214 | + # ) |
| 215 | + |
| 216 | + run( |
| 217 | + [ |
| 218 | + "git", |
| 219 | + "submodule", |
| 220 | + "add", |
| 221 | + "--quiet", |
| 222 | + "--force", |
| 223 | + "--", |
| 224 | + "./", |
| 225 | + "broken_submodule", |
| 226 | + ], |
| 227 | + cwd=str(broken_repo), |
| 228 | + ) |
| 229 | + |
| 230 | + with runner.isolated_filesystem(temp_dir=tmp_path): |
| 231 | + config = { |
| 232 | + "~/github_projects/": { |
| 233 | + "my_git_repo": { |
| 234 | + "url": f"git+file://{git_repo.dir}", |
| 235 | + "remotes": {"test_remote": f"git+file://{git_repo.dir}"}, |
| 236 | + }, |
| 237 | + "broken_repo": { |
| 238 | + "url": f"git+file://{broken_repo}", |
| 239 | + }, |
| 240 | + } |
| 241 | + } |
| 242 | + yaml_config = config_path / ".vcspull.yaml" |
| 243 | + yaml_config_data = yaml.dump(config, default_flow_style=False) |
| 244 | + yaml_config.write_text(yaml_config_data, encoding="utf-8") |
| 245 | + |
| 246 | + # CLI can sync |
| 247 | + result = runner.invoke(cli, ["sync", "broken_repo"]) |
| 248 | + output = "".join(list(result.output)) |
| 249 | + |
| 250 | + assert "No url found for submodule" == output |
| 251 | + assert result.exit_code == 1 |
0 commit comments