|
16 | 16 | import pathlib |
17 | 17 |
|
18 | 18 | from libvcs.pytest_plugin import CreateRepoPytestFixtureFn |
| 19 | + from libvcs.sync.git import GitSync |
19 | 20 |
|
20 | 21 |
|
21 | 22 | @pytest.mark.skipif(not shutil.which("git"), reason="git is not available") |
@@ -258,3 +259,54 @@ def test_gitconfig_submodule_file_protocol( |
258 | 259 | # Verify submodule was actually added |
259 | 260 | gitmodules = main_repo / ".gitmodules" |
260 | 261 | assert gitmodules.exists(), "Submodule should create .gitmodules file" |
| 262 | + |
| 263 | + |
| 264 | +@pytest.mark.skipif(not shutil.which("git"), reason="git is not available") |
| 265 | +@pytest.mark.xfail(reason="git_repo fixture missing set_home dependency") |
| 266 | +def test_git_repo_fixture_submodule_file_protocol( |
| 267 | + git_repo: GitSync, |
| 268 | + create_git_remote_repo: CreateRepoPytestFixtureFn, |
| 269 | + git_commit_envvars: dict[str, str], |
| 270 | + user_path: pathlib.Path, |
| 271 | + tmp_path: pathlib.Path, |
| 272 | + monkeypatch: pytest.MonkeyPatch, |
| 273 | +) -> None: |
| 274 | + """Test that git_repo fixture allows file:// protocol for submodule operations. |
| 275 | +
|
| 276 | + This validates that the git_repo fixture has proper HOME setup so child |
| 277 | + processes (spawned by git submodule add) can find $HOME/.gitconfig with |
| 278 | + protocol.file.allow=always. |
| 279 | +
|
| 280 | + Without set_home in git_repo, this test fails with: |
| 281 | + fatal: transport 'file' not allowed |
| 282 | +
|
| 283 | + See: https://github.com/vcs-python/libvcs/issues/509 |
| 284 | + """ |
| 285 | + from libvcs.pytest_plugin import git_remote_repo_single_commit_post_init |
| 286 | + |
| 287 | + # Isolate git config: set HOME to a clean path without protocol.file.allow |
| 288 | + # This simulates what happens on a fresh build system like Arch Linux packaging |
| 289 | + clean_home = tmp_path / "clean_home" |
| 290 | + clean_home.mkdir() |
| 291 | + monkeypatch.setenv("HOME", str(clean_home)) |
| 292 | + monkeypatch.setenv("GIT_CONFIG_SYSTEM", os.devnull) |
| 293 | + monkeypatch.delenv("GIT_CONFIG_GLOBAL", raising=False) |
| 294 | + |
| 295 | + # Create a repo to use as submodule source (with a commit so it can be cloned) |
| 296 | + submodule_source = create_git_remote_repo() |
| 297 | + git_remote_repo_single_commit_post_init( |
| 298 | + remote_repo_path=submodule_source, |
| 299 | + env=git_commit_envvars, |
| 300 | + ) |
| 301 | + |
| 302 | + # Add submodule - this spawns child git clone that needs HOME set |
| 303 | + # NOTE: We do NOT use the local config workaround here |
| 304 | + result = git_repo.cmd.submodules.add( |
| 305 | + repository=f"file://{submodule_source}", |
| 306 | + path="vendor/lib", |
| 307 | + ) |
| 308 | + |
| 309 | + assert "fatal" not in result.lower(), ( |
| 310 | + f"git submodule add failed: {result}\n" |
| 311 | + "git_repo fixture needs set_home dependency for child processes" |
| 312 | + ) |
0 commit comments