Skip to content

Commit 3667b32

Browse files
cliffhallclaude
andcommitted
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
1 parent 13a14ce commit 3667b32

3 files changed

Lines changed: 30 additions & 12 deletions

File tree

‎src/git/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ A repository's configuration and hooks travel with it (an unpacked archive, a sh
190190
- `diff.submodule` is `short`, so a diff reports a submodule whose commit moved as a `Subproject commit` line rather than running a nested `git diff` inside it, which would not carry the flags above.
191191
- `git_add` lets Git check whether a checked-out submodule changed, which runs Git inside it under its own configuration, so the filter and merge drivers each checked-out submodule (and each submodule inside one) defines are emptied too, the same way as the repository's own. `git_checkout` passes `--quiet`, which skips that check.
192192

193-
This needs Git 2.33 or later; with an older Git every tool call fails with an error saying so, rather than run unprotected.
193+
This needs Git 2.31 or later, and 2.33 or later for a repository with a checked-out submodule (older Git does not pass the overrides to the Git it runs inside one); with an older Git every tool call on such a repository fails with an error saying so, rather than run unprotected.
194194

195195
### Commit identity
196196

‎src/git/src/mcp_server_git/server.py‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ def _git_text(repo: git.Repo, command: str, *args: str) -> str:
118118
# honoring it would let the repository run code as the server's user on a
119119
# read-only call such as git_status. The overrides go in through
120120
# GIT_CONFIG_COUNT (git 2.31+), which outranks every config file and is
121-
# inherited by the git processes git itself starts, submodules included from
122-
# git 2.33 (`_MIN_SUBMODULE_GIT`).
121+
# inherited by the git processes git itself starts, inside a submodule only
122+
# from git 2.33 (`_MIN_SUBMODULE_GIT`, required where one is checked out).
123123
#
124124
# - `core.fsmonitor` is run on every index refresh (status, diff, add).
125125
# - `core.hooksPath` pointing at the null device leaves no hook to find, so
@@ -214,14 +214,11 @@ def _submodule_drivers(repo: git.Repo) -> set[str]:
214214
cannot read is skipped: the nested git cannot read it either, and stops
215215
before it runs anything there.
216216
217-
Raises `git.GitError` on git older than `_MIN_SUBMODULE_GIT`, whose
218-
nested git would not inherit the overrides.
217+
Raises `git.GitError` when a checked-out submodule is found and git is
218+
older than `_MIN_SUBMODULE_GIT`, whose nested git would not inherit the
219+
overrides. Without one, git never runs inside a submodule, so older git
220+
is fine.
219221
"""
220-
if repo.git.version_info[:2] < _MIN_SUBMODULE_GIT:
221-
raise git.GitError(
222-
"Git 2.33 or later is required: older git does not pass the "
223-
"configuration overrides to the git it runs inside a submodule"
224-
)
225222
drivers: set[str] = set()
226223
if repo.working_tree_dir is None:
227224
return drivers
@@ -242,6 +239,12 @@ def _submodule_drivers(repo: git.Repo) -> set[str]:
242239
submodule = top / path
243240
if not (submodule / ".git").exists():
244241
continue # not checked out: git does not look inside
242+
if repo.git.version_info[:2] < _MIN_SUBMODULE_GIT:
243+
raise git.GitError(
244+
"Git 2.33 or later is required for a repository with a "
245+
"checked-out submodule: older git does not pass the "
246+
"configuration overrides to the git it runs inside one"
247+
)
245248
resolved = submodule.resolve()
246249
if resolved in seen:
247250
continue
@@ -272,7 +275,8 @@ def harden_repo(repo: git.Repo) -> None:
272275
a worktree's `config.worktree`, and files they include) defines, and
273276
overrides each with an empty command. The same read checks that git
274277
applied the overrides: git older than 2.31 ignores GIT_CONFIG_COUNT, and
275-
is refused rather than run unprotected.
278+
is refused rather than run unprotected; so is git older than 2.33 for a
279+
repository with a checked-out submodule (`_submodule_drivers`).
276280
"""
277281
entries = list(HARDENED_CONFIG)
278282
repo.git.update_environment(**_config_env(entries))

‎src/git/tests/test_submodule_config.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,23 @@ def test_opens_a_submodule_as_the_nested_git_does(
382382
assert _submodule_drivers(repo) == {"filter.evil.clean"}
383383

384384

385-
def test_refuses_git_older_than_2_33(repo: git.Repo, monkeypatch: pytest.MonkeyPatch):
385+
def test_refuses_git_older_than_2_33_with_a_checked_out_submodule(
386+
repo: git.Repo, monkeypatch: pytest.MonkeyPatch
387+
):
386388
# Git 2.31 and 2.32 do not pass GIT_CONFIG_COUNT to the git they run
387389
# inside a submodule, so the overrides would not reach it.
390+
embed(repo, "sm").close()
388391
monkeypatch.setattr(git.Git, "version_info", property(lambda self: (2, 32, 0)))
389392
with pytest.raises(git.GitError, match="Git 2.33 or later is required"):
390393
harden_repo(repo)
394+
395+
396+
def test_older_git_works_without_a_checked_out_submodule(
397+
repo: git.Repo, monkeypatch: pytest.MonkeyPatch
398+
):
399+
# Without a checked-out submodule git never runs inside one, so 2.31 and
400+
# 2.32 are still served; a gitlink with nothing checked out is fine too.
401+
record_gitlink(repo, "absent", repo.head.commit.hexsha)
402+
monkeypatch.setattr(git.Git, "version_info", property(lambda self: (2, 32, 0)))
403+
harden_repo(repo)
404+
assert repo.git.config("--get", "core.hooksPath") == os.devnull

0 commit comments

Comments
 (0)