"""Git helpers — keeps git logic out of store/tools."""

from __future__ import annotations

import subprocess


def get_head_sha(project_dir: str) -> str | None:
    """Return current git HEAD SHA, or None if not in a repo."""
    try:
        result = subprocess.run(
            ["git", "rev-parse", "HEAD"],
            cwd=project_dir,
            capture_output=True,
            text=True,
            timeout=5,
        )
        if result.returncode == 0:
            return result.stdout.strip()
    except (OSError, subprocess.TimeoutExpired):
        pass
    return None
