kilocode icon indicating copy to clipboard operation
kilocode copied to clipboard

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

Open lambertjosh opened this issue 7 months ago • 2 comments

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/foo → B/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

lambertjosh avatar Apr 30 '26 21:04 lambertjosh

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

kilo-code-bot[bot] avatar Apr 30 '26 21:04 kilo-code-bot[bot]

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[bot] avatar Jun 13 '26 07:06 github-actions[bot]

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

marius-kilocode avatar Jun 17 '26 08:06 marius-kilocode

image image image image

lambertjosh avatar Jun 18 '26 04:06 lambertjosh