Refactor checkout and add --force flag
This commit is contained in:
parent
7ebbfad8f2
commit
0cd8443e2c
|
|
@ -84,17 +84,12 @@ program
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("checkout")
|
.command("checkout")
|
||||||
|
.alias("co")
|
||||||
.argument("<branch>", "branch name")
|
.argument("<branch>", "branch name")
|
||||||
.option("-f, --force", "checkout even if there are unsaved changes")
|
.option("-f, --force", "checkout even if there are unsaved changes")
|
||||||
.description("Close the session and check out the branch locally")
|
.description("Close the session and check out the branch locally")
|
||||||
.action((branch: string, opts: { force?: boolean }) => checkoutAction(branch, opts))
|
.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 ──────────────────────────────────────────────────────────
|
// ── Branch ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
program.commandsGroup("Branch Commands:")
|
program.commandsGroup("Branch Commands:")
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ import { requireSession, teardownSession } from "./helpers.ts"
|
||||||
export async function action(branch: string, opts: { force?: boolean } = {}) {
|
export async function action(branch: string, opts: { force?: boolean } = {}) {
|
||||||
const { root, session } = await requireSession(branch)
|
const { root, session } = await requireSession(branch)
|
||||||
|
|
||||||
if (!opts.force && await git.isDirty(session.worktree)) {
|
if (await git.isDirty(session.worktree)) {
|
||||||
die(`Branch "${branch}" has unsaved changes. Run "sandlot save ${branch}" first, or use -f to force.`)
|
die(`Branch "${branch}" has unsaved changes. Run "sandlot save ${branch}" first.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opts.force && await git.isDirty(root)) {
|
if (!opts.force && await git.isDirty(root)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user