Refactor checkout and add --force flag
This commit is contained in:
parent
7ebbfad8f2
commit
0cd8443e2c
|
|
@ -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:")
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user