Skip to content

fix(cli): restore source file when reverting a move across folders#9758

Open
lambertjosh wants to merge 1 commit intomainfrom
sleepy-stoplight
Open

fix(cli): restore source file when reverting a move across folders#9758
lambertjosh wants to merge 1 commit intomainfrom
sleepy-stoplight

Conversation

@lambertjosh
Copy link
Copy Markdown
Contributor

@lambertjosh lambertjosh commented Apr 30, 2026

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() in snapshot/index.ts computed the file list via git diff --cached --name-only without --no-renames. Git's default rename detection collapsed a move (A/fooB/foo) into a single destination entry, so the source path never entered the revert list.

Fix: Pass --no-renames, matching diffFull()'s behavior. Both source and destination now appear, so revert deletes the new location and restores the original.

Changes

  • One-line fix in patch() to add --no-renames
  • Regression tests in test/kilocode/snapshot-revert-move.test.ts covering folder-to-folder moves and in-folder renames
  • Docs update in checkpoints.md and whats-new.md (the limitation note now documents expected behavior; kept in case there are edge cases we haven't surfaced)
  • Changeset

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Apr 30, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • .changeset/revert-file-moves.md
  • packages/kilo-docs/source-links.md
  • packages/opencode/src/snapshot/index.ts
  • packages/opencode/test/kilocode/snapshot-revert-move.test.ts

Reviewed by gpt-5.5-20260423 · 425,629 tokens

@lambertjosh lambertjosh changed the title docs: document revert file move/rename limitation fix(cli): restore source file when reverting a move across folders Apr 30, 2026
@lambertjosh lambertjosh force-pushed the sleepy-stoplight branch 2 times, most recently from 0eb5256 to dda8f9c Compare May 1, 2026 18:15
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
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.

[Critical Bug] Revert Fails to Restore Files After AI Moves Them Between Folders — Files Deleted Not Restored

1 participant