Skip to content

Commit 4cb1c74

Browse files
EliahKaganclaude
andcommitted
Add a check that required submodules are initialized
Adds test_required_submodule_is_initialized to test/test_fixture_health.py. For each of the gitdb and smmap submodule working trees -- anchored at the GitPython source tree, since submodule paths are recorded in .gitmodules and are properties of the source tree itself -- asserts that the working tree directory exists and contains a .git marker (file or directory). Failure prints an actionable message naming init-tests-after-clone.sh as the remedy. This is a regression test for a different contract than the existing test_fixture_dir_is_trusted_by_git in this module. That test verifies git's willingness to operate in each fixture directory (the safe.directory / dubious-ownership contract). The new test verifies that the directories are populated at all (the init-tests-after-clone.sh contract). A bug class along these lines affected Arch Linux in gitpython-developers#1713 when init-tests-after-clone.sh stopped running git submodule update on CI -- if a similar regression returns, this test catches it loudly with a message naming the cause, instead of producing a cascade of opaque downstream failures. The test skips when the source tree is not a git clone (no .git at REPO_ROOT). This accommodates setups that run pytest from an extracted release tarball and prepare submodules in a separately-pointed tree via GIT_PYTHON_TEST_GIT_REPO_BASE (e.g. OpenIndiana's package build): in such setups, `git submodule update` cannot operate on the source tree, and the submodule paths checked here would never be populated there -- but the test suite still works because rorepo points elsewhere. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 89c1104 commit 4cb1c74

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

test/test_fixture_health.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@
4040
),
4141
]
4242

43+
# Submodule working trees that must be present and initialized for the test
44+
# suite to operate normally. Anchored at the source tree (where this test
45+
# file lives), since submodule paths are properties of the GitPython source
46+
# tree itself -- recorded in ``.gitmodules`` -- and not of any rorepo
47+
# redirection target.
48+
SUBMODULE_DIRS = [
49+
pytest.param(REPO_ROOT / "git" / "ext" / "gitdb", id="gitdb"),
50+
pytest.param(
51+
REPO_ROOT / "git" / "ext" / "gitdb" / "gitdb" / "ext" / "smmap",
52+
id="smmap",
53+
),
54+
]
55+
4356

4457
@pytest.mark.parametrize("fixture_dir", FIXTURE_DIRS)
4558
def test_fixture_dir_is_trusted_by_git(fixture_dir: Path) -> None:
@@ -82,3 +95,32 @@ def test_fixture_dir_is_trusted_by_git(fixture_dir: Path) -> None:
8295
"This usually means the directory is not an initialized git "
8396
"repository (its `.git` marker may be stale or pointing elsewhere)."
8497
)
98+
99+
100+
@pytest.mark.parametrize("submodule_dir", SUBMODULE_DIRS)
101+
def test_required_submodule_is_initialized(submodule_dir: Path) -> None:
102+
"""The vendored submodule's working tree is present and initialized.
103+
104+
Failure means the source tree is a git clone but ``init-tests-after-clone.sh``
105+
(or its equivalent) hasn't been run, so the submodule's working tree has
106+
not been populated. Skipped when the source tree itself isn't a git clone
107+
(e.g. an extracted release tarball), since ``git submodule update`` cannot
108+
operate there; setups that handle submodules in a separately-prepared
109+
tree (via ``GIT_PYTHON_TEST_GIT_REPO_BASE``) are exempted from this check.
110+
"""
111+
if not (REPO_ROOT / ".git").exists():
112+
pytest.skip(
113+
"Source tree is not a git clone (no .git in REPO_ROOT); submodules "
114+
"cannot be initialized via `git submodule update` here. Setups "
115+
"that prepare submodules in a separately-pointed tree (via "
116+
"GIT_PYTHON_TEST_GIT_REPO_BASE) are exempted from this check."
117+
)
118+
assert submodule_dir.is_dir(), (
119+
f"Submodule working tree missing: {submodule_dir}.\nRun ./init-tests-after-clone.sh from the repo root."
120+
)
121+
assert (submodule_dir / ".git").exists(), (
122+
f"Submodule directory exists but has no .git marker: {submodule_dir}.\n"
123+
"This usually means the directory was created (e.g. by extracting a "
124+
"source tarball) but `git submodule update --init` was never run for "
125+
"it. Run ./init-tests-after-clone.sh from the repo root."
126+
)

0 commit comments

Comments
 (0)