Add symlink in .sandlot/<branch> pointing to worktree on create, remove on close

This commit is contained in:
Chris Wanstrath 2026-02-18 16:04:49 -08:00
parent 8874885250
commit f90cd3a38d

View File

@ -3,6 +3,7 @@
import { Command } from "commander"
import { basename, join } from "path"
import { homedir } from "os"
import { mkdir, symlink, unlink } from "fs/promises"
import * as git from "./git.ts"
import * as vm from "./vm.ts"
import * as state from "./state.ts"
@ -33,6 +34,8 @@ program
const spin = spinner("Creating worktree")
await git.createWorktree(branch, worktreeAbs, root)
await mkdir(join(root, '.sandlot'), { recursive: true })
await symlink(worktreeAbs, join(root, '.sandlot', branch))
spin.text = "Starting VM"
await vm.ensure()
@ -105,6 +108,7 @@ const closeAction = async (branch: string) => {
const worktreeAbs = session?.worktree ?? join(homedir(), '.sandlot', basename(root), branch)
await git.removeWorktree(worktreeAbs, root)
await unlink(join(root, '.sandlot', branch)).catch(() => {})
console.log(`Removed worktree ${worktreeAbs}/`)
await git.deleteLocalBranch(branch, root)