Move worktrees to ~/.sandlot/<repo>/<branch> outside the project directory
This commit is contained in:
parent
a438391d70
commit
8874885250
17
src/cli.ts
17
src/cli.ts
|
|
@ -1,7 +1,8 @@
|
||||||
#!/usr/bin/env bun
|
#!/usr/bin/env bun
|
||||||
|
|
||||||
import { Command } from "commander"
|
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 git from "./git.ts"
|
||||||
import * as vm from "./vm.ts"
|
import * as vm from "./vm.ts"
|
||||||
import * as state from "./state.ts"
|
import * as state from "./state.ts"
|
||||||
|
|
@ -22,8 +23,7 @@ program
|
||||||
.description("Create a new session and launch Claude")
|
.description("Create a new session and launch Claude")
|
||||||
.action(async (branch: string, prompt?: string) => {
|
.action(async (branch: string, prompt?: string) => {
|
||||||
const root = await git.repoRoot()
|
const root = await git.repoRoot()
|
||||||
const worktreeRel = `.sandlot/${branch}`
|
const worktreeAbs = join(homedir(), '.sandlot', basename(root), branch)
|
||||||
const worktreeAbs = join(root, worktreeRel)
|
|
||||||
|
|
||||||
const existing = await state.getSession(root, branch)
|
const existing = await state.getSession(root, branch)
|
||||||
if (existing) {
|
if (existing) {
|
||||||
|
|
@ -40,7 +40,7 @@ program
|
||||||
|
|
||||||
await state.setSession(root, {
|
await state.setSession(root, {
|
||||||
branch,
|
branch,
|
||||||
worktree: worktreeRel,
|
worktree: worktreeAbs,
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ program
|
||||||
await vm.ensure()
|
await vm.ensure()
|
||||||
spin.succeed("Session ready")
|
spin.succeed("Session ready")
|
||||||
|
|
||||||
await vm.claude(join(root, session.worktree))
|
await vm.claude(session.worktree)
|
||||||
})
|
})
|
||||||
|
|
||||||
// ── sandlot close <branch> ───────────────────────────────────────────
|
// ── sandlot close <branch> ───────────────────────────────────────────
|
||||||
|
|
@ -102,11 +102,10 @@ program
|
||||||
const closeAction = async (branch: string) => {
|
const closeAction = async (branch: string) => {
|
||||||
const root = await git.repoRoot()
|
const root = await git.repoRoot()
|
||||||
const session = await state.getSession(root, branch)
|
const session = await state.getSession(root, branch)
|
||||||
const worktreeRel = session?.worktree ?? `.sandlot/${branch}`
|
const worktreeAbs = session?.worktree ?? join(homedir(), '.sandlot', basename(root), branch)
|
||||||
const worktreeAbs = join(root, worktreeRel)
|
|
||||||
|
|
||||||
await git.removeWorktree(worktreeAbs, root)
|
await git.removeWorktree(worktreeAbs, root)
|
||||||
console.log(`Removed worktree ${worktreeRel}/`)
|
console.log(`Removed worktree ${worktreeAbs}/`)
|
||||||
|
|
||||||
await git.deleteLocalBranch(branch, root)
|
await git.deleteLocalBranch(branch, root)
|
||||||
console.log(`Deleted local branch ${branch}`)
|
console.log(`Deleted local branch ${branch}`)
|
||||||
|
|
@ -157,7 +156,7 @@ program
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
const worktreeAbs = join(root, session.worktree)
|
const worktreeAbs = session.worktree
|
||||||
|
|
||||||
const spin = spinner("Starting VM")
|
const spin = spinner("Starting VM")
|
||||||
await vm.ensure()
|
await vm.ensure()
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ export async function ensure(): Promise<void> {
|
||||||
|
|
||||||
// Create from scratch
|
// Create from scratch
|
||||||
const home = homedir()
|
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()
|
await $`limactl start ${VM_NAME}`.quiet()
|
||||||
|
|
||||||
// Provision
|
// Provision
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user