From 267b519e1492f92eb69c6255b607c10131ea2b5b Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Fri, 20 Feb 2026 08:28:39 -0800 Subject: [PATCH] Add `--force` flag to close command and guard against unsaved changes --- src/cli.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 5fc02a0..71bc18a 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -382,11 +382,16 @@ program // ── sandlot close ─────────────────────────────────────────── -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 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 name") - .action(closeAction) + .option("-f, --force", "close even if there are unsaved changes") + .action((branch: string, opts: { force?: boolean }) => closeAction(branch, opts)) // ── sandlot save ───────────────────────────────────────────