summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-07-24 17:49:23 -0400
committerDax Raad <[email protected]>2025-07-24 17:49:23 -0400
commit4306f1a339e6ef811506c57615551d0d0058cf75 (patch)
treee354072c617d872af1addb5d749a1e19eafef116
parentaa2a5057ac8b5b0c3b9120b064f738424921d6d6 (diff)
downloadopencode-4306f1a339e6ef811506c57615551d0d0058cf75.tar.gz
opencode-4306f1a339e6ef811506c57615551d0d0058cf75.zip
wip: handle deleting file
-rw-r--r--packages/opencode/src/snapshot/index.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/packages/opencode/src/snapshot/index.ts b/packages/opencode/src/snapshot/index.ts
index cd1972aaf..a2203ecbc 100644
--- a/packages/opencode/src/snapshot/index.ts
+++ b/packages/opencode/src/snapshot/index.ts
@@ -52,6 +52,7 @@ export namespace Snapshot {
export async function patch(hash: string): Promise<Patch> {
const app = App.info()
const git = gitdir()
+ await $`git --git-dir ${git} add .`.quiet().cwd(app.path.cwd).nothrow()
const files = await $`git --git-dir ${git} diff --name-only ${hash} -- .`.cwd(app.path.cwd).text()
return {
hash,
@@ -80,7 +81,14 @@ export namespace Snapshot {
for (const file of item.files) {
if (files.has(file)) continue
log.info("reverting", { file, hash: item.hash })
- await $`git --git-dir=${git} checkout ${item.hash} -- ${file}`.quiet().cwd(App.info().path.root)
+ const result = await $`git --git-dir=${git} checkout ${item.hash} -- ${file}`
+ .quiet()
+ .cwd(App.info().path.root)
+ .nothrow()
+ if (result.exitCode !== 0) {
+ log.info("file not found in history, deleting", { file })
+ await fs.unlink(file).catch(() => {})
+ }
files.add(file)
}
}