diff --git a/CHANGES b/CHANGES index 2dafad36..7223b891 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,13 @@ $ uv add libvcs --prerelease allow _Notes on the upcoming release will go here._ +### Tests + +- pytest plugin: Add `set_home` dependency to `git_repo` fixture (#511) + + Follow-up to #510 for #509: Ensures child processes spawned by git submodule + operations can find `$HOME/.gitconfig` with `protocol.file.allow=always`. + ## libvcs 0.38.3 (2026-01-25) ### Tests diff --git a/src/libvcs/pytest_plugin.py b/src/libvcs/pytest_plugin.py index 8930ceb6..cf213fd2 100644 --- a/src/libvcs/pytest_plugin.py +++ b/src/libvcs/pytest_plugin.py @@ -701,6 +701,7 @@ def git_repo( projects_path: pathlib.Path, git_remote_repo: pathlib.Path, set_gitconfig: pathlib.Path, + set_home: None, # Needed for child processes (e.g. submodules) ) -> GitSync: """Pre-made git clone of remote repo checked out to user's projects dir.""" remote_repo_name = unique_repo_name(remote_repos_path=projects_path) diff --git a/tests/test_pytest_plugin.py b/tests/test_pytest_plugin.py index 6289b7a3..aa0896a3 100644 --- a/tests/test_pytest_plugin.py +++ b/tests/test_pytest_plugin.py @@ -16,6 +16,7 @@ import pathlib from libvcs.pytest_plugin import CreateRepoPytestFixtureFn + from libvcs.sync.git import GitSync @pytest.mark.skipif(not shutil.which("git"), reason="git is not available") @@ -258,3 +259,55 @@ def test_gitconfig_submodule_file_protocol( # Verify submodule was actually added gitmodules = main_repo / ".gitmodules" assert gitmodules.exists(), "Submodule should create .gitmodules file" + + +@pytest.mark.skipif(not shutil.which("git"), reason="git is not available") +def test_git_repo_fixture_submodule_file_protocol( + git_repo: GitSync, + create_git_remote_repo: CreateRepoPytestFixtureFn, + git_commit_envvars: dict[str, str], + user_path: pathlib.Path, + monkeypatch: pytest.MonkeyPatch, +) -> None: + """Test that git_repo fixture allows file:// protocol for submodule operations. + + This validates that the git_repo fixture has proper HOME setup so child + processes (spawned by git submodule add) can find $HOME/.gitconfig with + protocol.file.allow=always. + + The git_repo fixture depends on set_home to ensure child processes + (like git clone spawned by git submodule add) can find the test gitconfig. + + See: https://github.com/vcs-python/libvcs/issues/509 + """ + from libvcs.pytest_plugin import git_remote_repo_single_commit_post_init + + # Verify that HOME is set to user_path where test gitconfig resides + assert os.environ.get("HOME") == str(user_path), ( + f"git_repo fixture should set HOME to user_path.\n" + f"Expected: {user_path}\n" + f"Actual: {os.environ.get('HOME')}\n" + "git_repo fixture is missing set_home dependency" + ) + + # Block system config to prevent interference + monkeypatch.setenv("GIT_CONFIG_SYSTEM", os.devnull) + + # Create a repo to use as submodule source (with a commit so it can be cloned) + submodule_source = create_git_remote_repo() + git_remote_repo_single_commit_post_init( + remote_repo_path=submodule_source, + env=git_commit_envvars, + ) + + # Add submodule - this spawns child git clone that needs HOME set correctly + # NOTE: We do NOT use the local config workaround here + result = git_repo.cmd.submodules.add( + repository=f"file://{submodule_source}", + path="vendor/lib", + ) + + assert "fatal" not in result.lower(), ( + f"git submodule add failed: {result}\n" + "git_repo fixture needs set_home dependency for child processes" + )