feat(cli): show commit hash and summary on success
This commit is contained in:
@@ -359,8 +359,16 @@ async function main() {
|
|||||||
|
|
||||||
if (action === "y") {
|
if (action === "y") {
|
||||||
try {
|
try {
|
||||||
await commit(message);
|
const result = await commit(message);
|
||||||
console.log(`\n ${GREEN}Committed successfully!${RESET}`);
|
console.log(
|
||||||
|
`\n ${GREEN}${BOLD}✔ Committed successfully!${RESET}`,
|
||||||
|
);
|
||||||
|
if (result.hash) {
|
||||||
|
console.log(` ${YELLOW}${result.hash}${RESET} ${message}`);
|
||||||
|
}
|
||||||
|
if (result.summary) {
|
||||||
|
console.log(` ${DIM}${result.summary}${RESET}`);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(
|
console.error(
|
||||||
` ${RED}Commit failed: ${err instanceof Error ? err.message : err}${RESET}`,
|
` ${RED}Commit failed: ${err instanceof Error ? err.message : err}${RESET}`,
|
||||||
@@ -371,8 +379,16 @@ async function main() {
|
|||||||
const edited = await editMessage(message);
|
const edited = await editMessage(message);
|
||||||
if (edited) {
|
if (edited) {
|
||||||
try {
|
try {
|
||||||
await commit(edited);
|
const result = await commit(edited);
|
||||||
console.log(`\n ${GREEN}Committed successfully!${RESET}`);
|
console.log(
|
||||||
|
`\n ${GREEN}${BOLD}✔ Committed successfully!${RESET}`,
|
||||||
|
);
|
||||||
|
if (result.hash) {
|
||||||
|
console.log(` ${YELLOW}${result.hash}${RESET} ${edited}`);
|
||||||
|
}
|
||||||
|
if (result.summary) {
|
||||||
|
console.log(` ${DIM}${result.summary}${RESET}`);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(
|
console.error(
|
||||||
` ${RED}Commit failed: ${err instanceof Error ? err.message : err}${RESET}`,
|
` ${RED}Commit failed: ${err instanceof Error ? err.message : err}${RESET}`,
|
||||||
|
|||||||
+16
-4
@@ -98,13 +98,25 @@ export async function stageFiles(paths: string[]): Promise<void> {
|
|||||||
await Bun.$`git add -- ${paths}`;
|
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], {
|
const proc = Bun.spawn(["git", "commit", "-m", message], {
|
||||||
stdout: "inherit",
|
stdout: "pipe",
|
||||||
stderr: "inherit",
|
stderr: "pipe",
|
||||||
});
|
});
|
||||||
const exitCode = await proc.exited;
|
const exitCode = await proc.exited;
|
||||||
|
const stdout = await new Response(proc.stdout).text();
|
||||||
|
const stderr = await new Response(proc.stderr).text();
|
||||||
|
|
||||||
if (exitCode !== 0) {
|
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