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 (await git.isDirty(session.worktree)) { die(`Branch "${branch}" has unsaved changes. Run "sandlot save ${branch}" first.`) } if (!opts.force && await git.isDirty(root)) { die(`Working tree has uncommitted changes that may conflict with checkout. Commit or stash them first, or use -f to force.`) } await teardownSession(root, branch, session.worktree) await git.checkout(branch, root) console.log(`✔ Checked out ${branch}`) }