|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +import logging |
5 | 6 | import typing as t |
6 | 7 |
|
7 | 8 | import pytest |
@@ -143,3 +144,65 @@ def test_extract_repos_injects_workspace_root( |
143 | 144 | assert repo["workspace_root"] == expected_root |
144 | 145 | expected_path = config.expand_dir(pl.Path(expected_root), cwd=tmp_path) / name |
145 | 146 | assert repo["path"] == expected_path |
| 147 | + |
| 148 | + |
| 149 | +def _write_duplicate_config(tmp_path: pathlib.Path) -> pathlib.Path: |
| 150 | + config_path = tmp_path / "config.yaml" |
| 151 | + config_path.write_text( |
| 152 | + ( |
| 153 | + "~/workspace/:\n" |
| 154 | + " alpha:\n" |
| 155 | + " repo: git+https://example.com/alpha.git\n" |
| 156 | + "~/workspace/:\n" |
| 157 | + " beta:\n" |
| 158 | + " repo: git+https://example.com/beta.git\n" |
| 159 | + ), |
| 160 | + encoding="utf-8", |
| 161 | + ) |
| 162 | + return config_path |
| 163 | + |
| 164 | + |
| 165 | +def test_load_configs_merges_duplicate_workspace_roots( |
| 166 | + tmp_path: pathlib.Path, |
| 167 | + caplog: pytest.LogCaptureFixture, |
| 168 | + monkeypatch: pytest.MonkeyPatch, |
| 169 | +) -> None: |
| 170 | + """Duplicate workspace roots are merged to keep every repository.""" |
| 171 | + monkeypatch.setenv("HOME", str(tmp_path)) |
| 172 | + caplog.set_level(logging.INFO, logger="vcspull.config") |
| 173 | + |
| 174 | + config_path = _write_duplicate_config(tmp_path) |
| 175 | + |
| 176 | + repos = config.load_configs([config_path], cwd=tmp_path) |
| 177 | + |
| 178 | + repo_names = {repo["name"] for repo in repos} |
| 179 | + assert repo_names == {"alpha", "beta"} |
| 180 | + |
| 181 | + merged_messages = [message for message in caplog.messages if "merged" in message] |
| 182 | + assert merged_messages, "Expected a merge log entry for duplicate roots" |
| 183 | + |
| 184 | + |
| 185 | +def test_load_configs_can_skip_merging_duplicates( |
| 186 | + tmp_path: pathlib.Path, |
| 187 | + caplog: pytest.LogCaptureFixture, |
| 188 | + monkeypatch: pytest.MonkeyPatch, |
| 189 | +) -> None: |
| 190 | + """The merge step can be skipped while still warning about duplicates.""" |
| 191 | + monkeypatch.setenv("HOME", str(tmp_path)) |
| 192 | + caplog.set_level(logging.WARNING, logger="vcspull.config") |
| 193 | + |
| 194 | + config_path = _write_duplicate_config(tmp_path) |
| 195 | + |
| 196 | + repos = config.load_configs( |
| 197 | + [config_path], |
| 198 | + cwd=tmp_path, |
| 199 | + merge_duplicates=False, |
| 200 | + ) |
| 201 | + |
| 202 | + repo_names = {repo["name"] for repo in repos} |
| 203 | + assert repo_names == {"beta"} |
| 204 | + |
| 205 | + warning_messages = [ |
| 206 | + message for message in caplog.messages if "duplicate" in message |
| 207 | + ] |
| 208 | + assert warning_messages, "Expected a warning about duplicate workspace roots" |
0 commit comments