feat(cli): show commit hash and summary on success
This commit is contained in:
+16
-4
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user