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 ───────────────────────────────────────────