wip: snapshot

This commit is contained in:
Dax Raad
2025-07-28 13:00:09 -04:00
parent 99dfe65862
commit c24fbb4292
3 changed files with 25 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ import { cmd } from "../cmd"
export const SnapshotCommand = cmd({ export const SnapshotCommand = cmd({
command: "snapshot", command: "snapshot",
builder: (yargs) => yargs.command(TrackCommand).command(PatchCommand).demandCommand(), builder: (yargs) => yargs.command(TrackCommand).command(PatchCommand).command(DiffCommand).demandCommand(),
async handler() {}, async handler() {},
}) })
@@ -31,3 +31,18 @@ const PatchCommand = cmd({
}) })
}, },
}) })
const DiffCommand = cmd({
command: "diff <hash>",
builder: (yargs) =>
yargs.positional("hash", {
type: "string",
description: "hash",
demandOption: true,
}),
async handler(args) {
await bootstrap({ cwd: process.cwd() }, async () => {
console.log(await Snapshot.diff(args.hash))
})
},
})

View File

@@ -67,6 +67,7 @@ export namespace Session {
messageID: z.string(), messageID: z.string(),
partID: z.string().optional(), partID: z.string().optional(),
snapshot: z.string().optional(), snapshot: z.string().optional(),
diff: z.string().optional(),
}) })
.optional(), .optional(),
}) })
@@ -1160,6 +1161,7 @@ export namespace Session {
const session = await get(input.sessionID) const session = await get(input.sessionID)
revert.snapshot = session.revert?.snapshot ?? (await Snapshot.track()) revert.snapshot = session.revert?.snapshot ?? (await Snapshot.track())
await Snapshot.revert(patches) await Snapshot.revert(patches)
if (revert.snapshot) revert.diff = await Snapshot.diff(revert.snapshot)
return update(input.sessionID, (draft) => { return update(input.sessionID, (draft) => {
draft.revert = revert draft.revert = revert
}) })

View File

@@ -94,6 +94,13 @@ export namespace Snapshot {
} }
} }
export async function diff(hash: string) {
const app = App.info()
const git = gitdir()
const result = await $`git --git-dir=${git} diff ${hash} -- .`.quiet().cwd(app.path.root).text()
return result.trim()
}
function gitdir() { function gitdir() {
const app = App.info() const app = App.info()
return path.join(app.path.data, "snapshots") return path.join(app.path.data, "snapshots")