Skip to content

feat: display styled output after successful commit#75

Open
lb1192176991-lab wants to merge 2 commits into
404-PF:mainfrom
lb1192176991-lab:feat/styled-commit-output
Open

feat: display styled output after successful commit#75
lb1192176991-lab wants to merge 2 commits into
404-PF:mainfrom
lb1192176991-lab:feat/styled-commit-output

Conversation

@lb1192176991-lab
Copy link
Copy Markdown
Contributor

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() in src/git/diff.ts now returns a CommitResult object with parsed hash and summary fields
  • Auto-commit flow shows styled output with pc.green() and pc.dim()
  • Manual commit flow also shows styled output
  • Falls back to raw output if parsing fails

Testing

  • npm run build passes
  • Styled output shown in both auto-commit and manual-commit flows
  • Error output still shown on failure (unchanged)

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).
Copy link
Copy Markdown
Contributor

@404-Page-Found 404-Page-Found left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the detached HEAD regex issue and extract the duplicated styled output block before merging. Both are straightforward fixes.

Comment thread src/git/diff.ts
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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/commands/suggest.ts
try {
const result = commit(selected.message, selected.body);
console.log(pc.green(result.trim()));
if (result.hash) {
Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants