diff --git a/src/commands/close.ts b/src/commands/close.ts index 47f3a94..c1847b5 100644 --- a/src/commands/close.ts +++ b/src/commands/close.ts @@ -1,6 +1,4 @@ import { join } from "path" -import { homedir } from "os" -import { basename } from "path" import { unlink } from "fs/promises" import * as git from "../git.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 } = {}) { const root = await git.repoRoot() 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.`) } @@ -27,9 +30,7 @@ export async function action(branch: string, opts: { force?: boolean } = {}) { await git.deleteLocalBranch(branch, root) .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}`) }