Require session to exist before closing; simplify worktree path resolution
This commit is contained in:
parent
4db29e4beb
commit
1e71b3b4a4
|
|
@ -1,6 +1,4 @@
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import { homedir } from "os"
|
|
||||||
import { basename } from "path"
|
|
||||||
import { unlink } from "fs/promises"
|
import { 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"
|
||||||
|
|
@ -10,9 +8,14 @@ import { die } from "../fmt.ts"
|
||||||
export async function action(branch: string, opts: { force?: boolean } = {}) {
|
export async function action(branch: string, opts: { force?: boolean } = {}) {
|
||||||
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 worktreeAbs = session?.worktree ?? join(homedir(), '.sandlot', basename(root), branch)
|
|
||||||
|
|
||||||
if (!opts.force && session && await git.isDirty(worktreeAbs)) {
|
if (!session) {
|
||||||
|
die(`No session found for branch "${branch}"`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const worktreeAbs = session.worktree
|
||||||
|
|
||||||
|
if (!opts.force && await git.isDirty(worktreeAbs)) {
|
||||||
die(`Branch "${branch}" has unsaved changes. Run "sandlot save ${branch}" first, or use -f to force.`)
|
die(`Branch "${branch}" has unsaved changes. Run "sandlot save ${branch}" first, or use -f to force.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,9 +30,7 @@ export async function action(branch: string, opts: { force?: boolean } = {}) {
|
||||||
await git.deleteLocalBranch(branch, root)
|
await git.deleteLocalBranch(branch, root)
|
||||||
.catch((e) => console.warn(`⚠ Failed to delete branch ${branch}: ${e.message}`))
|
.catch((e) => console.warn(`⚠ Failed to delete branch ${branch}: ${e.message}`))
|
||||||
|
|
||||||
if (session) {
|
await state.removeSession(root, branch)
|
||||||
await state.removeSession(root, branch)
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`✔ Closed session ${branch}`)
|
console.log(`✔ Closed session ${branch}`)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user