Skip to content

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

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

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.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apply_patch move to same path deletes the file

1 participant