feat(cli): show commit hash and summary on success

This commit is contained in:
2026-06-09 17:38:00 +08:00
parent 68e98be653
commit 6d007698f9
2 changed files with 36 additions and 8 deletions
+16 -4
View File
@@ -98,13 +98,25 @@ export async function stageFiles(paths: string[]): Promise<void> {
await Bun.$`git add -- ${paths}`;
}
export async function commit(message: string): Promise<void> {
export async function commit(
message: string,
): Promise<{ hash: string; summary: string }> {
const proc = Bun.spawn(["git", "commit", "-m", message], {
stdout: "inherit",
stderr: "inherit",
stdout: "pipe",
stderr: "pipe",
});
const exitCode = await proc.exited;
const stdout = await new Response(proc.stdout).text();
const stderr = await new Response(proc.stderr).text();
if (exitCode !== 0) {
throw new Error(`git commit failed (exit code ${exitCode})`);
throw new Error(stderr.trim() || `git commit failed (exit code ${exitCode})`);
}
const hashMatch = stdout.match(/\[\w[^\s]*\s+([0-9a-f]{7,})/);
const hash = hashMatch?.[1] ?? "";
const summaryMatch = stdout.match(/(\d+\s+file[s]?\s+changed.*)/);
const summary = summaryMatch?.[1] ?? "";
return { hash, summary };
}