fix(cli): restore source file when reverting a move across folders#9758
Open
lambertjosh wants to merge 1 commit intomainfrom
Open
fix(cli): restore source file when reverting a move across folders#9758lambertjosh wants to merge 1 commit intomainfrom
lambertjosh wants to merge 1 commit intomainfrom
Conversation
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (4 files)
Reviewed by gpt-5.5-20260423 · 425,629 tokens |
0eb5256 to
dda8f9c
Compare
Git's default rename detection in 'diff --cached --name-only' collapses a file move (A/foo -> B/foo) into a single destination entry. The snapshot revert iterates this list and deletes files that aren't in the pre-step tree — so B/foo was removed but A/foo was never restored, losing data. Pass --no-renames so both the source and destination paths appear in the patch, matching diffFull()'s behavior. Revert now deletes the new location and restores the original. Fixes #9741
dda8f9c to
b92677a
Compare
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 #9741. When the agent moved a file between folders during a task, clicking Revert would delete the file from its new location without restoring the original — resulting in data loss.
Root cause:
patch()insnapshot/index.tscomputed the file list viagit diff --cached --name-onlywithout--no-renames. Git's default rename detection collapsed a move (A/foo→B/foo) into a single destination entry, so the source path never entered the revert list.Fix: Pass
--no-renames, matchingdiffFull()'s behavior. Both source and destination now appear, so revert deletes the new location and restores the original.Changes
patch()to add--no-renamestest/kilocode/snapshot-revert-move.test.tscovering folder-to-folder moves and in-folder renamescheckpoints.mdandwhats-new.md(the limitation note now documents expected behavior; kept in case there are edge cases we haven't surfaced)