feat(cli): add --delete-branch to workspaces archive
What & why
Related to #6380 — that issue asks for branch release to become the default;
this PR only makes it possible from the CLI, keeping today's behaviour when
the flag is absent, like the desktop dialog's unticked "delete branch" box.
superset workspaces archive (alias delete) had no way to clean up a host
workspace's local git branch. The external delete surface (workspace.delete,
shared by CLI/SDK/MCP) hardcoded deleteBranch: false when calling the cleanup
saga, so the branch cleanup the desktop dialog offers had no non-interactive
equivalent — scripted teardown left a branch behind for every workspace.
This adds it as an explicit opt-in, with the current behaviour untouched by
default:
workspace.deletenow acceptsdeleteBranch(z.boolean().default(false))
and forwards it todestroyWorkspace. Every existing caller that omits the
field keeps its exact behaviour.- The CLI gains
--delete-branch, and reports what actually happened in
branchesDeletedplus a(branch deleted)/N/M branches deletednote in
the human message. The note only appears when the flag was passed. - Cloud workspaces have no local branch, so
--delete-branchis rejected there
before anything is archived (--local/--hosttargets a host).
Branch deletion stays where the saga already runs it (after the workspace row
is gone), so a git failure lands in warnings instead of failing the archive.
--delete-branch is the user's consent to the saga's existing forced semantics
(git branch -D, unmerged branches included); the help and docs say so since
there is no confirmation dialog on this path.
Version skew: a newer CLI against an older host has the field stripped, gets
branchDeleted: false, and prints branch not deleted — never a false success.
Output shape gains one field: { deleted, branchesDeleted, warnings }.
Docs: apps/docs/content/docs/cli/cli-reference.mdx.
How I tested it
bun run lint → exit 0, bun run typecheck → 0 errors.
Host cleanup API — real git, not mocks
(workspace-create-delete.integration.test.ts, 17 pass): two new tests run
against a real git worktree add -b fixture and assert on git branchLocal()
— the branch survives when deleteBranch is omitted, and is gone when it is
passed. The second one fails with the host change reverted
(branchDeleted: false) and passes with it.
CLI (workspaces/archive/command.test.ts, 6 pass; packages/cli 417
pass): the file now uses the shared withLocalHostService helper (a real local
tRPC server) instead of its hand-rolled host setup, and covers the default
(branch kept, no note), the flag forwarded to every id, a partial result
(1/2 branches deleted), and the cloud rejection.
End-to-end against a live host — both behaviours in one run:
Terminal transcript of a real run, rendered with freeze. The output is captured verbatim through a pseudo-terminal; the $ … lines are printed by the demo script with shortened ids rather than typed.
Setup: the CLI binary built from this branch (bun run build in packages/cli), talking to a host-service bundled from this branch (bun run build:host, run under Node) on the local stack from ./.superset/setup.local.sh. The project is a throwaway git repo. Two workspaces on two branches, then archive without the flag (demo/keep survives) and with it (demo/scratch is gone).
Rendered help — workspaces archive --help from this branch:
Options:
--host <string> Host the workspaces live on
--local The workspaces are on this machine
--delete-branch Also delete each workspace's local branch (git branch -D, so unpushed commits are lost); host workspaces only
Checklist
- PR title follows conventional commits (
type(scope): subject) -
bun run lintandbun run typecheckpass (CI fails on lint warnings too) - "Allow edits from maintainers" is checked on fork PRs
Summary by cubic
Adds --delete-branch to superset workspaces archive (alias delete) so scripted teardown can remove each workspace’s local git branch. Keeps current behavior by default and clarifies single-workspace output.
-
New Features
- CLI (
@superset/cli): Added--delete-branch; output now includesbranchesDeleted. Single deletes show “(branch deleted|not deleted)”; multi deletes show “N/M branches deleted”. No branch note is shown without the flag, and the flag is rejected for cloud workspaces, which have no local branch. - Host service (
@superset/host-service):workspace.deleteacceptsdeleteBranch(defaultfalse) and forwards it todestroyWorkspace; branch cleanup runs post-delete and git failures becomewarnings. An older host that ignores the flag reportsbranchDeleted: false, so the CLI never claims a deletion that didn’t happen. - Docs (
@superset/docs): Updated CLI reference with the new option, output shape, and that it usesgit branch -D.
- CLI (
-
Bug Fixes
- CLI: Fixed single-workspace message to avoid “1/1 branches deleted”; now says “(branch deleted|not deleted)”.
Summary by CodeRabbit
-
New Features
- Added a
--delete-branchoption tosuperset workspaces delete. - Worktrees are removed automatically; associated branches are deleted only when explicitly requested.
- Command results now report deleted branches and include warnings for cleanup failures.
- Added a
-
Bug Fixes
- Branch cleanup failures no longer prevent workspace deletion from being reported as successful.
-
Documentation
- Updated the CLI reference with the new option, output fields, and branch cleanup behavior.