Skip to content

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

Merged
lambertjosh merged 5 commits into
mainfrom
sleepy-stoplight
Jun 18, 2026
Merged

fix(cli): restore source file when reverting a move across folders#9758
lambertjosh merged 5 commits into
mainfrom
sleepy-stoplight

Conversation

@lambertjosh

@lambertjosh lambertjosh commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

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

kilo-code-bot Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Incremental Review Note

A large upstream merge landed on this branch since the previous review (b92677a). The PR-specific files were re-examined in full:

  • packages/opencode/src/snapshot/index.ts — The core fix (--no-renames flag at line 426) is intact after the upstream restructuring. The kilocode_change-marked diff command now reads: ["diff", "--cached", "--no-ext-diff", "--no-renames", "--name-only", hash, "--", "."]. Fix confirmed present.
  • packages/opencode/test/kilocode/snapshot-revert-move.test.ts — Simplified from 3 tests to 1 (adapted to the testEffect/it.instance framework introduced by the upstream merge). The primary regression case (cross-folder move) is still covered. The multi-step move and in-folder rename cases were dropped as part of test harness migration — not a concern.
  • .changeset/revert-file-moves.md — Unchanged.
Files Reviewed (3 files)
  • .changeset/revert-file-moves.md
  • packages/opencode/src/snapshot/index.ts
  • packages/opencode/test/kilocode/snapshot-revert-move.test.ts

Reviewed by claude-4.6-sonnet-20260217 · 674,187 tokens

Review guidance: REVIEW.md from base branch main

@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
Comment thread packages/kilo-docs/source-links.md Outdated
@github-actions

Copy link
Copy Markdown
Contributor

To stay organized pull requests are automatically closed after 30 days of inactivity. If the pull request is still relevant please reopen it or create a fresh new one.

@github-actions github-actions Bot closed this Jun 13, 2026
@lambertjosh lambertjosh reopened this Jun 14, 2026
@marius-kilocode

Copy link
Copy Markdown
Collaborator

@lambertjosh do you want to go ahead with this? Did you test it and is it ready to merge?

@lambertjosh

Copy link
Copy Markdown
Contributor Author
image image image image

@lambertjosh
lambertjosh merged commit 390de4b into main Jun 18, 2026
22 checks passed
@lambertjosh
lambertjosh deleted the sleepy-stoplight branch June 18, 2026 04:12
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
fix(cli): restore source file when reverting a move across folders
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

2 participants