"""Minimal read-only Git helpers used by adoption assess/plan/apply/verify. Adoption never commits, pushes, clones or touches remotes; these helpers only ever call read-only `git` subcommands, plus `git init` for `repoctl init --git-init`. """ from __future__ import annotations import subprocess from pathlib import Path def _run(args: list[str], cwd: Path) -> subprocess.CompletedProcess[str]: return subprocess.run( ["git", *args], cwd=cwd, capture_output=True, text=True, check=False ) def head_revision(root: Path) -> str: result = _run(["rev-parse", "HEAD"], root) if result.returncode != 0: return "unborn" return result.stdout.strip() def is_dirty(root: Path) -> bool: result = _run(["status", "--porcelain"], root) return bool(result.stdout.strip()) def tracked_files(root: Path) -> set[str]: result = _run(["ls-files"], root) if result.returncode != 0: return set() return {line.strip() for line in result.stdout.splitlines() if line.strip()}