diff --git a/packages/opencode/src/snapshot/index.ts b/packages/opencode/src/snapshot/index.ts index e4fed2d68..2f8661f5e 100644 --- a/packages/opencode/src/snapshot/index.ts +++ b/packages/opencode/src/snapshot/index.ts @@ -10,7 +10,19 @@ import { Instance } from "../project/instance" export namespace Snapshot { const log = Log.create({ service: "snapshot" }) - export function init() {} + export function init() { + Array.fromAsync( + new Bun.Glob("**/snapshot").scan({ + absolute: true, + onlyFiles: false, + cwd: Global.Path.data, + }), + ).then((files) => { + for (const file of files) { + fs.rmdir(file, { recursive: true }) + } + }) + } export async function track() { if (Instance.project.vcs !== "git") return @@ -101,7 +113,8 @@ export namespace Snapshot { log.info("file existed in snapshot but checkout failed, keeping", { file }) } else { log.info("file did not exist in snapshot, deleting", { file }) - await fs.unlink(file).catch(() => {}) + const absolutePath = path.join(Instance.worktree, file) + await fs.unlink(absolutePath).catch(() => {}) } } files.add(file) diff --git a/packages/opencode/test/snapshot/snapshot.test.ts b/packages/opencode/test/snapshot/snapshot.test.ts index ca74389b6..5849a2675 100644 --- a/packages/opencode/test/snapshot/snapshot.test.ts +++ b/packages/opencode/test/snapshot/snapshot.test.ts @@ -549,7 +549,7 @@ test("revert should not delete files that existed but were deleted in snapshot", await Bun.write(`${tmp.path}/a.txt`, "recreated content") const patch = await Snapshot.patch(snapshot2!) - expect(patch.files).toContain(`${tmp.path}/a.txt`) + expect(patch.files).toContain(`a.txt`) await Snapshot.revert([patch]) @@ -573,8 +573,8 @@ test("revert preserves file that existed in snapshot when deleted then recreated await Bun.write(`${tmp.path}/newfile.txt`, "new") const patch = await Snapshot.patch(snapshot!) - expect(patch.files).toContain(`${tmp.path}/existing.txt`) - expect(patch.files).toContain(`${tmp.path}/newfile.txt`) + expect(patch.files).toContain(`existing.txt`) + expect(patch.files).toContain(`newfile.txt`) await Snapshot.revert([patch])