Skip to content

Commit 5307ea0

Browse files
paddymulclaude
andcommitted
fix(#132): route version git through git_util.run_git (no bare subprocess in src)
git_revision shelled out via subprocess.run(["git", ...]), which the no-bare-subprocess-git guard (test_no_bare_subprocess_git_in_src, #25/G1) forbids: bare git forks, and forking from the multithreaded server can crash on macOS. Use the sanctioned fork-safe git_util.run_git (posix_spawn). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 216f82a commit 5307ea0

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

src/tallyman_core/version.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
from __future__ import annotations
1313

1414
import functools
15-
import subprocess
1615
from pathlib import Path
1716

17+
from tallyman_core.git_util import run_git
18+
1819
# version.py lives at <repo>/src/tallyman_core/version.py.
1920
_REPO_ROOT = Path(__file__).resolve().parents[2]
2021

@@ -27,20 +28,20 @@ def git_revision() -> str:
2728
actually running, not wherever ``HEAD`` moves later in the process's life.
2829
``git describe --always --dirty`` yields the abbreviated commit, suffixed
2930
``-dirty`` when there are *tracked* working-tree changes (untracked files are
30-
ignored, so a stray scratch file doesn't flag drift). Returns ``"unknown"``
31-
when git or the repo isn't available — versioning must never break a start.
31+
ignored, so a stray scratch file doesn't flag drift). Routed through
32+
``git_util.run_git`` (fork-safe ``posix_spawn``, the sanctioned primitive —
33+
no bare ``subprocess`` git in src/). Returns ``"unknown"`` when git or the
34+
repo isn't available — versioning must never break a start.
3235
"""
3336
try:
34-
out = subprocess.run(
35-
["git", "-C", str(_REPO_ROOT), "describe", "--always", "--dirty", "--abbrev=7"],
36-
capture_output=True,
37-
text=True,
38-
timeout=2,
39-
check=True,
40-
).stdout.strip()
41-
except (OSError, subprocess.SubprocessError):
37+
rc, out, _ = run_git(
38+
["describe", "--always", "--dirty", "--abbrev=7"],
39+
cwd=_REPO_ROOT,
40+
timeout=2.0,
41+
)
42+
except OSError:
4243
return "unknown"
43-
return out or "unknown"
44+
return out if (rc == 0 and out) else "unknown"
4445

4546

4647
def version_info() -> dict:

0 commit comments

Comments
 (0)