Skip to content

Commit dac1815

Browse files
authored
Fix git_repo fixture for submodule file:// protocol (#511)
## Summary - Add `set_home` dependency to `git_repo` fixture so child processes (e.g., spawned by `git submodule add`) can find `$HOME/.gitconfig` with `protocol.file.allow=always` - Add regression test `test_git_repo_fixture_submodule_file_protocol` ## Root Cause The `git_repo` fixture had `set_gitconfig` (which sets `GIT_CONFIG` env var) but not `set_home`. Child processes spawned by `git submodule add` don't inherit `GIT_CONFIG` and need `$HOME/.gitconfig` to find the protocol configuration.
2 parents 53da824 + 54d3187 commit dac1815

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

CHANGES

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ $ uv add libvcs --prerelease allow
2020
_Notes on the upcoming release will go here._
2121
<!-- END PLACEHOLDER - ADD NEW CHANGELOG ENTRIES BELOW THIS LINE -->
2222

23+
### Tests
24+
25+
- pytest plugin: Add `set_home` dependency to `git_repo` fixture (#511)
26+
27+
Follow-up to #510 for #509: Ensures child processes spawned by git submodule
28+
operations can find `$HOME/.gitconfig` with `protocol.file.allow=always`.
29+
2330
## libvcs 0.38.3 (2026-01-25)
2431

2532
### Tests

src/libvcs/pytest_plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ def git_repo(
701701
projects_path: pathlib.Path,
702702
git_remote_repo: pathlib.Path,
703703
set_gitconfig: pathlib.Path,
704+
set_home: None, # Needed for child processes (e.g. submodules)
704705
) -> GitSync:
705706
"""Pre-made git clone of remote repo checked out to user's projects dir."""
706707
remote_repo_name = unique_repo_name(remote_repos_path=projects_path)

tests/test_pytest_plugin.py

Lines changed: 53 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,55 @@ 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+
def test_git_repo_fixture_submodule_file_protocol(
266+
git_repo: GitSync,
267+
create_git_remote_repo: CreateRepoPytestFixtureFn,
268+
git_commit_envvars: dict[str, str],
269+
user_path: pathlib.Path,
270+
monkeypatch: pytest.MonkeyPatch,
271+
) -> None:
272+
"""Test that git_repo fixture allows file:// protocol for submodule operations.
273+
274+
This validates that the git_repo fixture has proper HOME setup so child
275+
processes (spawned by git submodule add) can find $HOME/.gitconfig with
276+
protocol.file.allow=always.
277+
278+
The git_repo fixture depends on set_home to ensure child processes
279+
(like git clone spawned by git submodule add) can find the test gitconfig.
280+
281+
See: https://github.com/vcs-python/libvcs/issues/509
282+
"""
283+
from libvcs.pytest_plugin import git_remote_repo_single_commit_post_init
284+
285+
# Verify that HOME is set to user_path where test gitconfig resides
286+
assert os.environ.get("HOME") == str(user_path), (
287+
f"git_repo fixture should set HOME to user_path.\n"
288+
f"Expected: {user_path}\n"
289+
f"Actual: {os.environ.get('HOME')}\n"
290+
"git_repo fixture is missing set_home dependency"
291+
)
292+
293+
# Block system config to prevent interference
294+
monkeypatch.setenv("GIT_CONFIG_SYSTEM", os.devnull)
295+
296+
# Create a repo to use as submodule source (with a commit so it can be cloned)
297+
submodule_source = create_git_remote_repo()
298+
git_remote_repo_single_commit_post_init(
299+
remote_repo_path=submodule_source,
300+
env=git_commit_envvars,
301+
)
302+
303+
# Add submodule - this spawns child git clone that needs HOME set correctly
304+
# NOTE: We do NOT use the local config workaround here
305+
result = git_repo.cmd.submodules.add(
306+
repository=f"file://{submodule_source}",
307+
path="vendor/lib",
308+
)
309+
310+
assert "fatal" not in result.lower(), (
311+
f"git submodule add failed: {result}\n"
312+
"git_repo fixture needs set_home dependency for child processes"
313+
)

0 commit comments

Comments
 (0)