-
Notifications
You must be signed in to change notification settings - Fork 12
feat: display styled output after successful commit #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The regex Fix: Use |
||
| raw, | ||
| hash: match?.[1], | ||
| summary: match?.[2], | ||
| }; | ||
| } finally { | ||
| try { unlinkSync(tmpFile); } catch {} | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This styled output block is duplicated with the one in the manual-commit path below. Please extract it into a helper function like
printCommitResult(result: CommitResult)to keep the code DRY.