import { useState, useEffect } from "react";
import { execSync } from "child_process";
function useGitBranch(cwd) {
  const [branchName, setBranchName] = useState(void 0);
  useEffect(() => {
    const workingDir = cwd || process.cwd();
    try {
      const result = execSync("git rev-parse --abbrev-ref HEAD", {
        cwd: workingDir,
        encoding: "utf-8",
        stdio: ["pipe", "pipe", "pipe"]
      });
      const branch = result.trim();
      setBranchName(branch || void 0);
    } catch {
      setBranchName(void 0);
    }
  }, [cwd]);
  return branchName;
}
export {
  useGitBranch
};
