Skip to content

fix(review-diff): discard a fully-staged file back to HEAD (#2318) - #2332

Open
sinelaw wants to merge 1 commit into
masterfrom
claude/upbeat-maxwell-8ohgr0
Open

fix(review-diff): discard a fully-staged file back to HEAD (#2318)#2332
sinelaw wants to merge 1 commit into
masterfrom
claude/upbeat-maxwell-8ohgr0

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 rewrites the working tree from the index. When a file's change is entirely staged (clean working tree), that command is a no-op — yet the status bar still reported Discarded: <file>, telling the user an irreversible discard succeeded while the staged change remained in the index, on disk, and in the diff.

Fix

  • Reset the file all the way back to its committed state with git checkout HEAD -- <path>, which restores both the index entry and the working tree to HEAD, so staged and unstaged edits alike are dropped (the obvious meaning of the "this cannot be undone" discard dialog).
  • Honor the command's exit code: only report Discarded when it actually succeeded; otherwise surface Discard failed: … instead of a false success.

The untracked-file branch (rm) is unchanged.

Testing

  • New e2e test test_issue2318_discard_fully_staged_file_reverts_to_head: stages a change so the working tree is clean, opens Review Diff, discards the file via D, and asserts the change disappears from the diff and that neither the working tree nor the index retains it. The test times out against the old git checkout -- <path> path (the change is never discarded) and passes with the fix.
  • All 9 existing discard-related e2e tests pass, including the pre-existing hunk-discard regression test (Review Diff: "Discard hunk" fails with "patch does not apply" even when patch is valid #2117) — no regression.
  • Plugin type-check (tsc --strict) passes.

Manual validation

Built the fresh binary and reproduced the issue's exact scenario in tmux (commit a file, stage a one-line change, Review DiffD → confirm):

  • Before: staged change survived, status falsely said Discarded.
  • After: UI shows "No changes to review", status shows a truthful Discarded: calc.py, git status --short is empty, git diff --cached --quiet returns 0, and calc.py on disk is back to its committed contents.

https://claude.ai/code/session_01FqagsaYk1AERmbNY5GbnK2


Generated by Claude Code

@sinelaw
sinelaw force-pushed the claude/upbeat-maxwell-8ohgr0 branch from 2eea4f3 to da0a545 Compare June 22, 2026 18:39
File-level Discard (`D`) in Review Diff ran `git checkout -- <path>`,
which only rewrites the working tree from the index. When a file's
change is entirely staged (clean working tree), that command is a no-op,
yet the status bar still reported `Discarded: <file>` — telling the user
an irreversible discard succeeded while the staged change remained in the
index, on disk, and in the diff.

Reset the file all the way back to its committed state with
`git checkout HEAD -- <path>`, which restores both the index entry and
the working tree to HEAD, so staged and unstaged edits alike are dropped.
Also honor the command's exit code: only claim "Discarded" when it
actually succeeded, otherwise surface "Discard failed" rather than a
false success.

Adds an e2e test that stages a change (clean working tree), discards the
file via `D`, and asserts the change disappears from the review diff and
that neither the working tree nor the index retains it. The test times
out against the old `git checkout -- <path>` path.

Fixes #2318
@sinelaw
sinelaw force-pushed the claude/upbeat-maxwell-8ohgr0 branch from da0a545 to 6685926 Compare July 17, 2026 11:54
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