UNPKG

smart-git-commit

Version:

AI-powered smart commit message generator for Git diffs.

32 lines (26 loc) 650 B
import { execSync } from "child_process"; function isGitInstalled() { try { execSync("git --version", { stdio: "ignore" }); return true; } catch { return false; } } export default function getGitDiff() { if (!isGitInstalled()) { console.error("Git is not installed or not found in PATH."); process.exit(1); } try { const output = execSync("git diff --cached", { encoding: "utf-8" }); if (!output.trim()) { console.log("No staged changes found."); process.exit(0); } return output; } catch (err) { console.error("Failed to get git diff:", err.message); process.exit(1); } }