fix(review-diff): discard fully-staged file reverts to HEAD (#2318)#2334
Open
sinelaw wants to merge 2 commits into
Open
fix(review-diff): discard fully-staged file reverts to HEAD (#2318)#2334sinelaw wants to merge 2 commits into
sinelaw wants to merge 2 commits into
Conversation
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
43517df to
047de17
Compare
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2318.
In Review Diff, the file-level Discard action (
D) rangit 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 reportedDiscarded:, 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:git 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).A, no HEAD version) →git rm -f -- <path>, since their HEAD state is "does not exist".rm).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
test_issue2318_discard_fully_staged_file_reverts_to_headinreview_diff_ux_bugs.rs: stages a modification, opens Review Diff, discards the file withD, and assertsgit statusis clean and the file is reverted to HEAD.git statusstill showsM src/main.rs) and passes with the fix.cargo fmtclean; plugin TypeScript type-checks clean.https://claude.ai/code/session_01RTzPYNCg1VbVbYEedz7PWs
Generated by Claude Code