Skip to content

fix: apply_patch move to same path deletes the file - #45316

Open
wzsxxa wants to merge 2 commits into
anomalyco:devfrom
wzsxxa:fix/apply-patch-move-same-path
Open

fix: apply_patch move to same path deletes the file#45316
wzsxxa wants to merge 2 commits into
anomalyco:devfrom
wzsxxa:fix/apply-patch-move-same-path

Conversation

@wzsxxa

@wzsxxa wzsxxa commented Aug 26, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #45310

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When apply_patch receives a patch that updates a file and moves it to the same path, the case "move" branch executes write(movePath, newContent) then remove(filePath). Because both paths resolve to the same absolute path, the remove deletes the file just written — the file ends up missing instead of updated.

The fix adds an early check at the top of the case "move" branch: when movePath === filePath, the move degenerates to an update (write + emit a single "change" event, then break). This skips the remove step that would undo the write.

How did you verify your code works?

  • Added a regression test treats move-to-same-path as an update in packages/opencode/test/tool/apply_patch.test.ts covering the same-path move scenario.
  • Ran the full apply_patch.test.ts suite: 28 pass, 0 fail. No regressions in existing move / update / add / delete tests.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

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.

apply_patch move to same path deletes the file

1 participant