Add --force flag to close command and guard against unsaved changes
This commit is contained in:
parent
7c46b28aab
commit
267b519e14
13
src/cli.ts
13
src/cli.ts
|
|
@ -382,11 +382,16 @@ program
|
||||||
|
|
||||||
// ── sandlot close <branch> ───────────────────────────────────────────
|
// ── sandlot close <branch> ───────────────────────────────────────────
|
||||||
|
|
||||||
const closeAction = async (branch: string) => {
|
const closeAction = async (branch: string, opts: { force?: boolean } = {}) => {
|
||||||
const root = await git.repoRoot()
|
const root = await git.repoRoot()
|
||||||
const session = await state.getSession(root, branch)
|
const session = await state.getSession(root, branch)
|
||||||
const worktreeAbs = session?.worktree ?? join(homedir(), '.sandlot', basename(root), branch)
|
const worktreeAbs = session?.worktree ?? join(homedir(), '.sandlot', basename(root), branch)
|
||||||
|
|
||||||
|
if (!opts.force && session && await git.isDirty(worktreeAbs)) {
|
||||||
|
console.error(`✖ Branch "${branch}" has unsaved changes. Run "sandlot save ${branch}" first, or use -f to force.`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
await vm.clearActivity(worktreeAbs, branch)
|
await vm.clearActivity(worktreeAbs, branch)
|
||||||
|
|
||||||
await git.removeWorktree(worktreeAbs, root)
|
await git.removeWorktree(worktreeAbs, root)
|
||||||
|
|
@ -471,13 +476,15 @@ program
|
||||||
program
|
program
|
||||||
.command("close")
|
.command("close")
|
||||||
.argument("<branch>", "branch name")
|
.argument("<branch>", "branch name")
|
||||||
|
.option("-f, --force", "close even if there are unsaved changes")
|
||||||
.description("Remove a worktree and clean up the session")
|
.description("Remove a worktree and clean up the session")
|
||||||
.action(closeAction)
|
.action((branch: string, opts: { force?: boolean }) => closeAction(branch, opts))
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("rm", { hidden: true })
|
.command("rm", { hidden: true })
|
||||||
.argument("<branch>", "branch name")
|
.argument("<branch>", "branch name")
|
||||||
.action(closeAction)
|
.option("-f, --force", "close even if there are unsaved changes")
|
||||||
|
.action((branch: string, opts: { force?: boolean }) => closeAction(branch, opts))
|
||||||
|
|
||||||
// ── sandlot save <branch> ───────────────────────────────────────────
|
// ── sandlot save <branch> ───────────────────────────────────────────
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user