Skip to content

[Bug] Interactive suggest --commit with only unstaged changes attempts commit on an empty index #280

Description

@404-Page-Found

Description

When commit-echo suggest --commit runs with no staged changes, the user is offered to use unstaged changes. The auto-commit (--yes) path guards this with if (!diffResult.staged) and errors out, but the interactive path does not. The user then selects a suggestion and confirms the commit, and git commit -F runs against an empty index → confusing nothing to commit failure (or, if unrelated files got staged meanwhile, a commit whose content doesn't match the diff the LLM analyzed).

Location

src/commands/suggest.ts lines 334–341 (auto-commit guard) vs. lines 391–392 (interactive path, missing guard)

Code

// Guarded path (autoCommit):
if (!diffResult.staged) {
  outro(pc.red('Auto-commit requires staged changes. Stage your changes with `git add` and try again.'));
  process.exit(1);
}
await acceptAndCommit(first, config, diffResult.diff, true);

// Unguarded path (interactive):
if (shouldCommit) {
  await acceptAndCommit(selected, config, diffResult.diff); // diffResult.staged === false here
}

Suggested fix

Add the same diffResult.staged check before acceptAndCommit in the interactive shouldCommit branch, and return without exiting (or exit cleanly) with a message telling the user to stage changes.

Impact

Users running suggest --commit interactively on unstaged work hit a git error mid-flow, or worse, commit the wrong content if the index changes between the diff snapshot and the commit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions