import { execFileSync } from "node:child_process";
import type { GitContext } from "../../../progress/schema";

export function getGitContext(cwd: string): GitContext {
  const branch = execFileSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
    cwd,
    encoding: "utf-8",
  }).trim();

  const commit = execFileSync("git", ["rev-parse", "--short", "HEAD"], {
    cwd,
    encoding: "utf-8",
  }).trim();

  return { branch, commit };
}
