add cleanup command to remove stale sessions with missing worktrees
This commit is contained in:
parent
3888876ed5
commit
1cd4e7f668
30
src/cli.ts
30
src/cli.ts
|
|
@ -4,6 +4,7 @@ import { Command } from "commander"
|
||||||
import { $} from "bun"
|
import { $} from "bun"
|
||||||
import { basename, join } from "path"
|
import { basename, join } from "path"
|
||||||
import { homedir } from "os"
|
import { homedir } from "os"
|
||||||
|
import { existsSync } from "fs"
|
||||||
import { mkdir, symlink, unlink } from "fs/promises"
|
import { mkdir, symlink, unlink } from "fs/promises"
|
||||||
import * as git from "./git.ts"
|
import * as git from "./git.ts"
|
||||||
import * as vm from "./vm.ts"
|
import * as vm from "./vm.ts"
|
||||||
|
|
@ -598,6 +599,35 @@ program
|
||||||
process.stdout.write(session.worktree + "\n")
|
process.stdout.write(session.worktree + "\n")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// ── sandlot cleanup ─────────────────────────────────────────────────
|
||||||
|
|
||||||
|
program
|
||||||
|
.command("cleanup")
|
||||||
|
.description("Remove stale sessions whose worktrees no longer exist")
|
||||||
|
.action(async () => {
|
||||||
|
const root = await git.repoRoot()
|
||||||
|
const st = await state.load(root)
|
||||||
|
const sessions = Object.values(st.sessions)
|
||||||
|
|
||||||
|
if (sessions.length === 0) {
|
||||||
|
console.log("No sessions to clean up.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const stale = sessions.filter(s => !existsSync(s.worktree))
|
||||||
|
|
||||||
|
if (stale.length === 0) {
|
||||||
|
console.log("No stale sessions found.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const s of stale) {
|
||||||
|
await state.removeSession(root, s.branch)
|
||||||
|
await unlink(join(root, '.sandlot', s.branch)).catch(() => {})
|
||||||
|
console.log(`✔ Removed stale session: ${s.branch}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// ── sandlot vm ───────────────────────────────────────────────────────
|
// ── sandlot vm ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
const vmCmd = program.command("vm").description("Manage the sandlot VM")
|
const vmCmd = program.command("vm").description("Manage the sandlot VM")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user