Move worktrees to ~/.sandlot/<repo>/<branch> outside the project directory

This commit is contained in:
Chris Wanstrath 2026-02-18 16:03:37 -08:00
parent a438391d70
commit 8874885250
2 changed files with 9 additions and 10 deletions

View File

@ -1,7 +1,8 @@
#!/usr/bin/env bun
import { Command } from "commander"
import { join } from "path"
import { basename, join } from "path"
import { homedir } from "os"
import * as git from "./git.ts"
import * as vm from "./vm.ts"
import * as state from "./state.ts"
@ -22,8 +23,7 @@ program
.description("Create a new session and launch Claude")
.action(async (branch: string, prompt?: string) => {
const root = await git.repoRoot()
const worktreeRel = `.sandlot/${branch}`
const worktreeAbs = join(root, worktreeRel)
const worktreeAbs = join(homedir(), '.sandlot', basename(root), branch)
const existing = await state.getSession(root, branch)
if (existing) {
@ -40,7 +40,7 @@ program
await state.setSession(root, {
branch,
worktree: worktreeRel,
worktree: worktreeAbs,
created_at: new Date().toISOString(),
})
@ -94,7 +94,7 @@ program
await vm.ensure()
spin.succeed("Session ready")
await vm.claude(join(root, session.worktree))
await vm.claude(session.worktree)
})
// ── sandlot close <branch> ───────────────────────────────────────────
@ -102,11 +102,10 @@ program
const closeAction = async (branch: string) => {
const root = await git.repoRoot()
const session = await state.getSession(root, branch)
const worktreeRel = session?.worktree ?? `.sandlot/${branch}`
const worktreeAbs = join(root, worktreeRel)
const worktreeAbs = session?.worktree ?? join(homedir(), '.sandlot', basename(root), branch)
await git.removeWorktree(worktreeAbs, root)
console.log(`Removed worktree ${worktreeRel}/`)
console.log(`Removed worktree ${worktreeAbs}/`)
await git.deleteLocalBranch(branch, root)
console.log(`Deleted local branch ${branch}`)
@ -157,7 +156,7 @@ program
process.exit(1)
}
const worktreeAbs = join(root, session.worktree)
const worktreeAbs = session.worktree
const spin = spinner("Starting VM")
await vm.ensure()

View File

@ -15,7 +15,7 @@ export async function ensure(): Promise<void> {
// Create from scratch
const home = homedir()
await $`limactl create --name=${VM_NAME} --mount=${home}/dev:w template:ubuntu-24.04`.quiet()
await $`limactl create --name=${VM_NAME} --mount=${home}/dev --mount=${home}/.sandlot:w template:ubuntu-24.04`.quiet()
await $`limactl start ${VM_NAME}`.quiet()
// Provision