Skip to content

Commit 6205d00

Browse files
committed
test_pytest_plugin(test): Add regression test for submodule file:// protocol (#509)
why: Reproduce the "transport 'file' not allowed" error that occurs in strict build environments when git submodule operations spawn child processes that don't inherit local repo config what: - Add test_gitconfig_submodule_file_protocol test - Uses monkeypatch to simulate isolated git environment - Marked xfail until gitconfig fixture is fixed
1 parent 25dc853 commit 6205d00

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

tests/test_pytest_plugin.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
from __future__ import annotations
44

5+
import os
56
import shutil
7+
import subprocess
68
import textwrap
79
import typing as t
810

@@ -176,3 +178,86 @@ def test_git_bare_repo_sync_and_commit(
176178
# Test
177179
result = pytester.runpytest(str(first_test_filename))
178180
result.assert_outcomes(passed=2)
181+
182+
183+
@pytest.mark.skipif(not shutil.which("git"), reason="git is not available")
184+
@pytest.mark.xfail(
185+
reason="gitconfig fixture lacks protocol.file.allow=always for submodules (#509)",
186+
)
187+
def test_gitconfig_submodule_file_protocol(
188+
gitconfig: pathlib.Path,
189+
user_path: pathlib.Path,
190+
tmp_path: pathlib.Path,
191+
monkeypatch: pytest.MonkeyPatch,
192+
) -> None:
193+
"""Test that gitconfig fixture allows file:// protocol for git submodule operations.
194+
195+
Git submodule operations spawn child processes that don't inherit local repo config.
196+
The child `git clone` process needs protocol.file.allow=always in global config.
197+
198+
Without this setting, submodule operations fail with:
199+
fatal: transport 'file' not allowed
200+
201+
This reproduces GitHub issue #509 where tests fail in strict build environments
202+
(like Arch Linux packaging) that don't have protocol.file.allow set globally.
203+
204+
See: https://github.com/vcs-python/libvcs/issues/509
205+
"""
206+
# Isolate git config: use fixture's gitconfig via HOME, block only system config
207+
# Note: We don't block GIT_CONFIG_GLOBAL because git falls back to $HOME/.gitconfig
208+
# when GIT_CONFIG_GLOBAL is unset, which is where our fixture puts the config
209+
monkeypatch.setenv("HOME", str(user_path))
210+
monkeypatch.setenv("GIT_CONFIG_SYSTEM", os.devnull)
211+
monkeypatch.delenv("GIT_CONFIG_GLOBAL", raising=False)
212+
213+
# Create a source repository to use as submodule
214+
submodule_source = tmp_path / "submodule_source"
215+
submodule_source.mkdir()
216+
subprocess.run(
217+
["git", "init"],
218+
cwd=submodule_source,
219+
check=True,
220+
capture_output=True,
221+
)
222+
subprocess.run(
223+
["git", "commit", "--allow-empty", "-m", "initial"],
224+
cwd=submodule_source,
225+
check=True,
226+
capture_output=True,
227+
)
228+
229+
# Create a main repository
230+
main_repo = tmp_path / "main_repo"
231+
main_repo.mkdir()
232+
subprocess.run(
233+
["git", "init"],
234+
cwd=main_repo,
235+
check=True,
236+
capture_output=True,
237+
)
238+
subprocess.run(
239+
["git", "commit", "--allow-empty", "-m", "initial"],
240+
cwd=main_repo,
241+
check=True,
242+
capture_output=True,
243+
)
244+
245+
# Try to add submodule using file:// protocol
246+
# This spawns a child git clone that needs protocol.file.allow=always
247+
result = subprocess.run(
248+
["git", "submodule", "add", str(submodule_source), "vendor/lib"],
249+
cwd=main_repo,
250+
capture_output=True,
251+
text=True,
252+
)
253+
254+
# Assert: submodule add should succeed (no "fatal" errors)
255+
assert "fatal" not in result.stderr.lower(), (
256+
f"git submodule add failed with: {result.stderr}\n"
257+
'This indicates gitconfig fixture is missing [protocol "file"] allow = always'
258+
)
259+
assert result.returncode == 0, f"git submodule add failed: {result.stderr}"
260+
261+
# Verify submodule was actually added
262+
gitmodules = main_repo / ".gitmodules"
263+
assert gitmodules.exists(), "Submodule should create .gitmodules file"

0 commit comments

Comments
 (0)