Skip to content

Commit bbecd12

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 submodules, 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. Paths are anchored at GIT_REPO -- the value of GIT_PYTHON_TEST_GIT_REPO_BASE, falling back to the source tree -- so any setup already satisfying the existing rorepo-redirection contract automatically satisfies the new test. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ab71d65 commit bbecd12

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

test/test_fixture_health.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import pytest
2626

27+
from test.lib import GIT_REPO
28+
2729
REPO_ROOT = Path(__file__).resolve().parent.parent
2830

2931
# Directories git must trust for the test suite to operate normally. The
@@ -40,6 +42,19 @@
4042
),
4143
]
4244

45+
# Submodule working trees that must be present and initialized for the test
46+
# suite to operate normally. Anchored at ``GIT_REPO`` (the value of
47+
# ``GIT_PYTHON_TEST_GIT_REPO_BASE``, falling back to the source tree) -- the
48+
# same path the rest of the test suite uses for its read-only ``rorepo``
49+
# fixture.
50+
SUBMODULE_DIRS = [
51+
pytest.param(Path(GIT_REPO) / "git" / "ext" / "gitdb", id="gitdb"),
52+
pytest.param(
53+
Path(GIT_REPO) / "git" / "ext" / "gitdb" / "gitdb" / "ext" / "smmap",
54+
id="smmap",
55+
),
56+
]
57+
4358

4459
@pytest.mark.parametrize("fixture_dir", FIXTURE_DIRS)
4560
def test_fixture_dir_is_trusted_by_git(fixture_dir: Path) -> None:
@@ -82,3 +97,26 @@ def test_fixture_dir_is_trusted_by_git(fixture_dir: Path) -> None:
8297
"This usually means the directory is not an initialized git "
8398
"repository (its `.git` marker may be stale or pointing elsewhere)."
8499
)
100+
101+
102+
@pytest.mark.parametrize("submodule_dir", SUBMODULE_DIRS)
103+
def test_required_submodule_is_initialized(submodule_dir: Path) -> None:
104+
"""The vendored submodule's working tree is present and initialized.
105+
106+
Failure means the fixture tree pointed at by
107+
``GIT_PYTHON_TEST_GIT_REPO_BASE`` (or the source tree, if the env var is
108+
unset) is missing this submodule's working tree -- typically because
109+
``init-tests-after-clone.sh`` (or its equivalent) wasn't run.
110+
"""
111+
assert submodule_dir.is_dir(), (
112+
f"Submodule working tree missing: {submodule_dir}.\n"
113+
"Run ./init-tests-after-clone.sh from the repo root, or set "
114+
"GIT_PYTHON_TEST_GIT_REPO_BASE to a tree where submodules have been "
115+
"initialized recursively."
116+
)
117+
assert (submodule_dir / ".git").exists(), (
118+
f"Submodule directory exists but has no .git marker: {submodule_dir}.\n"
119+
"This usually means the directory was created (e.g. by extracting a "
120+
"source tarball) but `git submodule update --init` was never run for "
121+
"it. Run ./init-tests-after-clone.sh from the repo root."
122+
)

0 commit comments

Comments
 (0)