Skip to content

Commit 9dfe132

Browse files
bercedevsafishamsi
authored andcommitted
fix(mcp): don't hand git the server's stdin in _git_head (#4440)
graph_stats asks git for HEAD to report staleness. The child inherited the MCP stdio pipe, and on Windows git blocks on it: the call sat on the 3s timeout, or hung under Claude Code. prs.py already isolates stdin (#3318); these two _git_head copies were missed. (cherry picked from commit 7092f98)
1 parent fe085ce commit 9dfe132

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎graphify/export.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ def _git_head(cwd: "str | Path | None" = None) -> str | None:
226226
import subprocess as _sp
227227
try:
228228
r = _sp.run(
229-
["git", "rev-parse", "HEAD"], capture_output=True, text=True, timeout=3,
229+
["git", "rev-parse", "HEAD"], stdin=_sp.DEVNULL,
230+
capture_output=True, text=True, timeout=3,
230231
cwd=str(cwd) if cwd is not None else None,
231232
)
232233
return r.stdout.strip() if r.returncode == 0 else None

‎graphify/watch.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ def _git_head(cwd: Path | str | None = None) -> str | None:
376376
import subprocess as _sp
377377
try:
378378
r = _sp.run(
379-
["git", "rev-parse", "HEAD"], capture_output=True, text=True, timeout=3,
379+
["git", "rev-parse", "HEAD"], stdin=_sp.DEVNULL,
380+
capture_output=True, text=True, timeout=3,
380381
cwd=str(cwd) if cwd is not None else None,
381382
)
382383
return r.stdout.strip() if r.returncode == 0 else None

‎tests/test_git_head_stdin.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""_git_head must not hand git the caller's stdin (#4440).
2+
3+
Under an MCP stdio host, stdin is the protocol pipe. On Windows a git child that
4+
inherits it blocks, so `graph_stats` stalls on the timeout or hangs. Same class
5+
as the prs.py isolation in #3318.
6+
"""
7+
import subprocess
8+
from unittest.mock import MagicMock, patch
9+
10+
import pytest
11+
12+
from graphify import export, watch
13+
14+
15+
@pytest.mark.parametrize("module", [export, watch], ids=["export", "watch"])
16+
def test_git_head_passes_devnull_stdin(module, tmp_path):
17+
completed = MagicMock(returncode=0, stdout="abc123\n", stderr="")
18+
with patch("subprocess.run", return_value=completed) as mock_run:
19+
assert module._git_head(tmp_path) == "abc123"
20+
_args, kwargs = mock_run.call_args
21+
assert kwargs.get("stdin") == subprocess.DEVNULL

0 commit comments

Comments
 (0)