Skip to content

fix(review-diff): discard fully-staged file reverts to HEAD (#2318)#2334

Open
sinelaw wants to merge 2 commits into
masterfrom
claude/upbeat-maxwell-sb7kt6
Open

fix(review-diff): discard fully-staged file reverts to HEAD (#2318)#2334
sinelaw wants to merge 2 commits into
masterfrom
claude/upbeat-maxwell-sb7kt6

Conversation

@sinelaw

@sinelaw sinelaw commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #2318.

In Review Diff, the file-level Discard action (D) ran git checkout -- <path>, which only reverts a file's working-tree changes from the index. When a file's changes were entirely staged (clean working tree), the discard was a no-op — but the status bar still reported Discarded:, telling the user an irreversible discard had succeeded while their staged change remained in the index and on disk.

Fix

crates/fresh-editor/plugins/audit_mode.ts — the discard confirm handler now:

  • Tracked filesgit checkout HEAD -- <path>, restoring both the index and the working tree to HEAD. This discards staged, partially-staged, and unstaged changes consistently (the full-discard intent of the "This cannot be undone" dialog).
  • Staged additions (status A, no HEAD version) → git rm -f -- <path>, since their HEAD state is "does not exist".
  • Untracked files → unchanged (rm).
  • The Discarded: message is now gated on the command's exit code, so a failed discard reports the error instead of falsely claiming success (issue requirement: must not report "Discarded" when nothing was discarded).

Testing

  • New e2e regression test test_issue2318_discard_fully_staged_file_reverts_to_head in review_diff_ux_bugs.rs: stages a modification, opens Review Diff, discards the file with D, and asserts git status is clean and the file is reverted to HEAD.
  • Verified fails without the fix (git status still shows M src/main.rs) and passes with the fix.
  • cargo fmt clean; plugin TypeScript type-checks clean.

https://claude.ai/code/session_01RTzPYNCg1VbVbYEedz7PWs


Generated by Claude Code

File-level Discard (`D`) in Review Diff ran `git checkout -- <path>`,
which only reverts the working tree from the index. For a file whose
changes are entirely staged (clean working tree) this was a no-op, yet
the status bar still reported "Discarded" — telling the user an
irreversible discard had succeeded while their staged change was
untouched.

Discard now reverts tracked files to HEAD (`git checkout HEAD -- <path>`),
which restores both the index and the working tree, so a fully-staged,
partially-staged, or unstaged change is discarded consistently. Staged
additions (no HEAD version) are unstaged and removed, and the success
message is now gated on the command's exit code so a failed discard no
longer reports success.

Adds an e2e regression test that stages a modification, discards it via
`D` in Review Diff, and asserts the working tree is clean and the file
reverted to HEAD.

https://claude.ai/code/session_01RTzPYNCg1VbVbYEedz7PWs
@sinelaw sinelaw force-pushed the claude/upbeat-maxwell-sb7kt6 branch from 43517df to 047de17 Compare June 22, 2026 18:27
…2318)

The discard handler spawns `git` asynchronously and only sets its status
message after the process and the follow-up refresh complete. The test
previously pumped a fixed number of render ticks before reading git
state, which races on slower machines and can observe a half-applied
index/worktree. Wait for the "Discarded"/"Discard failed" status signal
instead, so the assertion runs only once the discard has fully landed.

https://claude.ai/code/session_01RTzPYNCg1VbVbYEedz7PWs
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.

Review Diff: file-level Discard (D) reports "Discarded" but leaves staged changes intact for a fully-staged file

2 participants