Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/opencode/src/tool/apply_patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ export const ApplyPatchTool = Tool.define(

case "move":
if (change.movePath) {
// Move to the same path degenerates to an update — otherwise write+remove would delete the file just written.
if (change.movePath === change.filePath) {
yield* afs.writeWithDirs(change.filePath, Bom.join(change.newContent, change.bom))
updates.push({ file: change.filePath, event: "change" })
break
}

// Create parent directories (recursive: true is safe on existing/root dirs)

yield* afs.writeWithDirs(change.movePath!, Bom.join(change.newContent, change.bom))
Expand Down
15 changes: 15 additions & 0 deletions packages/opencode/test/tool/apply_patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,21 @@ describe("tool.apply_patch freeform", () => {
}),
)

it.instance("treats move-to-same-path as an update", () =>
Effect.gen(function* () {
const test = yield* TestInstance
const { ctx } = makeCtx()
const target = path.join(test.directory, "same.txt")
yield* writeText(target, "old content\n")

const patchText =
"*** Begin Patch\n*** Update File: same.txt\n*** Move to: same.txt\n@@\n-old content\n+new content\n*** End Patch"

yield* execute({ patchText }, ctx)
expect(yield* readText(target)).toBe("new content\n")
}),
)

it.instance("adds file overwriting existing file", () =>
Effect.gen(function* () {
const test = yield* TestInstance
Expand Down
Loading