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)
| 203 | |
| 204 | |
| 205 | def _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 | |
| 226 | def _git_config(repo_root: Path, key: str, value: str) -> None: |
no test coverage detected