MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / _run_git

Function _run_git

src/codegraphcontext/cli/hook_manager.py:205–223  ·  view source on GitHub ↗

Run a git command, translating a missing/failed git into HookError. Callers only handle ``HookError``; without this a missing ``git`` binary (``FileNotFoundError``) or a failed ``config`` call (``CalledProcessError``) would crash the ``cgc hook`` commands with an uncaught exception.

(repo_root: Path, args: list[str], *, check: bool, **kwargs)

Source from the content-addressed store, hash-verified

203
204
205def _run_git(repo_root: Path, args: list[str], *, check: bool, **kwargs):
206 """Run a git command, translating a missing/failed git into HookError.
207
208 Callers only handle ``HookError``; without this a missing ``git`` binary
209 (``FileNotFoundError``) or a failed ``config`` call (``CalledProcessError``)
210 would crash the ``cgc hook`` commands with an uncaught exception.
211 """
212 try:
213 return subprocess.run(
214 ["git", "-C", str(repo_root), *args],
215 check=check,
216 **kwargs,
217 )
218 except FileNotFoundError as exc:
219 raise HookError(
220 "Git executable not found. Install Git and ensure it is on PATH."
221 ) from exc
222 except subprocess.CalledProcessError as exc:
223 raise HookError(f"git {' '.join(args)} failed: {exc}") from exc
224
225
226def _git_config(repo_root: Path, key: str, value: str) -> None:

Callers 3

_git_configFunction · 0.85
_unset_git_configFunction · 0.85
_has_git_configFunction · 0.85

Calls 2

HookErrorClass · 0.85
runMethod · 0.45

Tested by

no test coverage detected