diff --git a/src/commands/suggest.ts b/src/commands/suggest.ts index 769a05a..8019fc8 100644 --- a/src/commands/suggest.ts +++ b/src/commands/suggest.ts @@ -147,7 +147,11 @@ async function acceptAndCommit(selected: Suggestion, config: Config, diff: strin if (auto) { try { const result = commit(selected.message, selected.body); - console.log(pc.green(result.trim())); + if (result.hash) { + console.log(` ${pc.green('✓')} ${pc.bold(pc.green(result.hash))} ${pc.dim(result.summary ?? '')}`); + } else { + console.log(pc.green(result.raw.trim())); + } } catch (err) { const msg = err instanceof Error ? err.message : 'Unknown error'; outro(pc.red(`Commit failed: ${msg}`)); @@ -208,7 +212,11 @@ async function acceptAndCommit(selected: Suggestion, config: Config, diff: strin try { const result = commit(finalMessage, finalBody); - console.log(pc.green(result.trim())); + if (result.hash) { + console.log(` ${pc.green('✓')} ${pc.bold(pc.green(result.hash))} ${pc.dim(result.summary ?? '')}`); + } else { + console.log(pc.green(result.raw.trim())); + } await appendEntry({ timestamp: new Date().toISOString(), diff --git a/src/git/diff.ts b/src/git/diff.ts index cef64af..d5195d2 100644 --- a/src/git/diff.ts +++ b/src/git/diff.ts @@ -37,7 +37,13 @@ export function getUnstagedDiff(): DiffResult { } -export function commit(message: string, body?: string): string { +export interface CommitResult { + raw: string; + hash?: string; + summary?: string; +} + +export function commit(message: string, body?: string): CommitResult { const fullMessage = body ? `${message}\n\n${body}` : message; const tmpFile = join(tmpdir(), `commit-echo-msg-${process.pid}-${Date.now()}.txt`); try { @@ -51,7 +57,14 @@ export function commit(message: string, body?: string): string { const detail = [result.stderr, result.stdout].filter(Boolean).join('\n').trim(); throw new Error(detail || `git commit exited with code ${result.status}`); } - return result.stdout; + const raw = result.stdout; + // Parse "[branch hash] summary" or "[branch (extra) hash] summary" pattern + const match = raw.match(/\[\S+(?:\s+\([^)]+\))?\s+([a-f0-9]+)\]\s+(.+)/); + return { + raw, + hash: match?.[1], + summary: match?.[2], + }; } finally { try { unlinkSync(tmpFile); } catch {} }