Refactor checkout and add --force flag

This commit is contained in:
Chris Wanstrath 2026-02-25 20:50:49 -08:00
parent 7ebbfad8f2
commit 0cd8443e2c
2 changed files with 3 additions and 8 deletions

View File

@ -84,17 +84,12 @@ program
program
.command("checkout")
.alias("co")
.argument("<branch>", "branch name")
.option("-f, --force", "checkout even if there are unsaved changes")
.description("Close the session and check out the branch locally")
.action((branch: string, opts: { force?: boolean }) => checkoutAction(branch, opts))
program
.command("co", { hidden: true })
.argument("<branch>", "branch name")
.option("-f, --force", "checkout even if there are unsaved changes")
.action((branch: string, opts: { force?: boolean }) => checkoutAction(branch, opts))
// ── Branch ──────────────────────────────────────────────────────────
program.commandsGroup("Branch Commands:")

View File

@ -5,8 +5,8 @@ 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.`)
if (await git.isDirty(session.worktree)) {
die(`Branch "${branch}" has unsaved changes. Run "sandlot save ${branch}" first.`)
}
if (!opts.force && await git.isDirty(root)) {