"""Run one git command and return its result. The caller owns everything that makes the call safe for a given repository: the argv hardening and the environment (``hermes_cli._subprocess_compat`` builds both), and which ``git`` executable to run. """ from __future__ import annotations import os import subprocess from collections.abc import Mapping, Sequence def run_git( args: Sequence[str], *, cwd: str | os.PathLike[str] | None, env: Mapping[str, str] | None, timeout: float, git: str = "git", ) -> subprocess.CompletedProcess[str]: """Run ``git *args`` with output captured as UTF-8 text and stdin closed. A non-zero exit is returned, not raised. ``OSError`` (git missing, ``cwd`` gone) and ``subprocess.TimeoutExpired`` propagate to the caller. """ return subprocess.run( [git, *args], cwd=cwd, env=env, capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=timeout, stdin=subprocess.DEVNULL, check=False, )