Skip to content

Commit e9a50e6

Browse files
committed
test_pytest_plugin(test[xfail]): Add regression test for git_repo submodule file protocol
why: Document the issue where git_repo fixture lacks set_home dependency, causing submodule operations to fail in isolated build environments what: - Add test_git_repo_fixture_submodule_file_protocol with xfail marker - Test isolates HOME to prove child processes can't find gitconfig - References GitHub issue #509
1 parent 53da824 commit e9a50e6

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

tests/test_pytest_plugin.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import pathlib
1717

1818
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
19+
from libvcs.sync.git import GitSync
1920

2021

2122
@pytest.mark.skipif(not shutil.which("git"), reason="git is not available")
@@ -258,3 +259,54 @@ def test_gitconfig_submodule_file_protocol(
258259
# Verify submodule was actually added
259260
gitmodules = main_repo / ".gitmodules"
260261
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

Comments
 (0)