Add symlink in .sandlot/<branch> pointing to worktree on create, remove on close
This commit is contained in:
parent
8874885250
commit
f90cd3a38d
|
|
@ -3,6 +3,7 @@
|
||||||
import { Command } from "commander"
|
import { Command } from "commander"
|
||||||
import { basename, join } from "path"
|
import { basename, join } from "path"
|
||||||
import { homedir } from "os"
|
import { homedir } from "os"
|
||||||
|
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"
|
||||||
import * as state from "./state.ts"
|
import * as state from "./state.ts"
|
||||||
|
|
@ -33,6 +34,8 @@ program
|
||||||
|
|
||||||
const spin = spinner("Creating worktree")
|
const spin = spinner("Creating worktree")
|
||||||
await git.createWorktree(branch, worktreeAbs, root)
|
await git.createWorktree(branch, worktreeAbs, root)
|
||||||
|
await mkdir(join(root, '.sandlot'), { recursive: true })
|
||||||
|
await symlink(worktreeAbs, join(root, '.sandlot', branch))
|
||||||
|
|
||||||
spin.text = "Starting VM"
|
spin.text = "Starting VM"
|
||||||
await vm.ensure()
|
await vm.ensure()
|
||||||
|
|
@ -105,6 +108,7 @@ const closeAction = async (branch: string) => {
|
||||||
const worktreeAbs = session?.worktree ?? join(homedir(), '.sandlot', basename(root), branch)
|
const worktreeAbs = session?.worktree ?? join(homedir(), '.sandlot', basename(root), branch)
|
||||||
|
|
||||||
await git.removeWorktree(worktreeAbs, root)
|
await git.removeWorktree(worktreeAbs, root)
|
||||||
|
await unlink(join(root, '.sandlot', branch)).catch(() => {})
|
||||||
console.log(`Removed worktree ${worktreeAbs}/`)
|
console.log(`Removed worktree ${worktreeAbs}/`)
|
||||||
|
|
||||||
await git.deleteLocalBranch(branch, root)
|
await git.deleteLocalBranch(branch, root)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user