namespace ClaudeDo.Worker.Git;

/// <summary>Short HEAD of a checkout, stamped into a finding's frontmatter so staleness is visible.</summary>
public static class GitHead
{
    /// <summary>
    /// Never throws — a fresh repo with no commits yet, or a working dir that is not a git repo
    /// at all, must not block a finding save. Callers get "unknown" instead.
    /// </summary>
    public static async Task<string> ShortAsync(string workingDir, CancellationToken ct)
    {
        try
        {
            return await GitExcludeWriter.RevParseAsync(workingDir, ["rev-parse", "--short", "HEAD"], ct);
        }
        catch (InvalidOperationException)
        {
            return "unknown";
        }
    }
}
