sandlot/src/commands/close.ts

19 lines
675 B
TypeScript

import * as git from "../git.ts"
import { die } from "../fmt.ts"
import { requireSession, teardownSession } from "./helpers.ts"
export async function action(branch: string, opts: { force?: boolean } = {}) {
const { root, session } = await requireSession(branch)
if (!opts.force && await git.isDirty(session.worktree)) {
die(`Branch "${branch}" has unsaved changes. Run "sandlot save ${branch}" first, or use -f to force.`)
}
await teardownSession(root, branch, session.worktree)
await git.deleteLocalBranch(branch, root)
.catch((e) => console.warn(`⚠ Failed to delete branch ${branch}: ${e.message}`))
console.log(`✔ Closed session ${branch}`)
}