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> ───────────────────────────────────────────
|
||||
|
||||
const closeAction = async (branch: string) => {
|
||||
const closeAction = async (branch: string, opts: { force?: boolean } = {}) => {
|
||||
const root = await git.repoRoot()
|
||||
const session = await state.getSession(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 git.removeWorktree(worktreeAbs, root)
|
||||
|
|
@ -471,13 +476,15 @@ program
|
|||
program
|
||||
.command("close")
|
||||
.argument("<branch>", "branch name")
|
||||
.option("-f, --force", "close even if there are unsaved changes")
|
||||
.description("Remove a worktree and clean up the session")
|
||||
.action(closeAction)
|
||||
.action((branch: string, opts: { force?: boolean }) => closeAction(branch, opts))
|
||||
|
||||
program
|
||||
.command("rm", { hidden: true })
|
||||
.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> ───────────────────────────────────────────
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user