feat: display styled output after successful commit#75
feat: display styled output after successful commit#75lb1192176991-lab wants to merge 2 commits into
Conversation
Parse git commit output to extract the abbreviated commit hash and summary line, then display a styled success message (green checkmark, bold hash, dimmed summary) instead of raw git output.
The regex for parsing git commit output now also matches '[master (root-commit) abc1234] summary' format (initial commits).
404-Page-Found
left a comment
There was a problem hiding this comment.
Please address the detached HEAD regex issue and extract the duplicated styled output block before merging. Both are straightforward fixes.
| 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 { |
There was a problem hiding this comment.
The regex \S+ only matches a single word for the branch ref. In detached HEAD state, git commit outputs [detached HEAD abc1234] — \S+ captures only detached, leaving HEAD unmatched by [a-f0-9]+. This causes the regex to fail, falling back to raw output.
Fix: Use [\w-]+(?:\s+[\w-]+)? or similar to capture multi-word refs like detached HEAD. Alternatively, use a more robust approach: match the hash after the last ] bracket, or use git rev-parse HEAD to get the hash directly instead of parsing the output string.
| try { | ||
| const result = commit(selected.message, selected.body); | ||
| console.log(pc.green(result.trim())); | ||
| if (result.hash) { |
There was a problem hiding this comment.
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.
What
After a successful commit, users now see a styled success message showing the abbreviated commit hash and first line of the commit message, instead of raw git output.
Why
Raw git commit output is noisy and inconsistent. A styled summary (green checkmark + bold hash + dimmed summary) provides immediate feedback that's consistent with the rest of commit-echo's UX.
Changes
commit()insrc/git/diff.tsnow returns aCommitResultobject with parsedhashandsummaryfieldspc.green()andpc.dim()Testing
npm run buildpasses