Skip to content

anchor rm: remove an anchor worktree and dissolve its anchor#1303

Open
ed-irl wants to merge 4 commits into
ed-irl/anchor-scopefrom
ed-irl/anchor-rm
Open

anchor rm: remove an anchor worktree and dissolve its anchor#1303
ed-irl wants to merge 4 commits into
ed-irl/anchor-scopefrom
ed-irl/anchor-rm

Conversation

@ed-irl

@ed-irl ed-irl commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Adds gs anchor rm <path>, the counterpart to anchor create/track, for tearing down an anchor worktree once its work is done.

The command resolves the path to an anchor (matching the registry's recorded worktree path, then falling back to the branch checked out there), then:

  • Refuses to remove the current worktree up front, since Git won't remove the working tree it's run from.
  • Removes the worktree first — the only step that can fail for reasons outside our control (a dirty tree without --force) — so a failure leaves all state untouched and the command is safe to retry.
  • Retargets the anchor's direct children onto its base (the pinned branch for an internal anchor, else the canonical trunk) in retarget-only mode, leaving them needing a restack rather than risking a conflict.
  • Deletes the anchor's pointer branch and unregisters the anchor.

--force removes a worktree with uncommitted changes.

Includes a test script covering self-removal refusal, the dirty-tree no-op-on-failure guarantee, successful removal with child retargeting, and the non-anchor-path error, plus help golden files.

ed-irl and others added 3 commits June 23, 2026 13:48
'gs anchor rm <path>' removes an anchor worktree and dissolves its
anchor: direct child branches are retargeted onto the anchor's base
(left needing a restack), the anchor branch is deleted, and the
worktree directory is removed. Adds the git WorktreeRemove primitive.
Fixes from adversarial review (anchor-rm layer):
- remove the worktree before retargeting children, so a failed
  removal (a dirty tree without --force) leaves no half-applied state
  to clean up; the command is safe to retry (B5)
- refuse early when asked to remove the current worktree, instead of
  mutating state and then hitting Git's raw refusal
- fall back to the checked-out anchor branch when the registry's
  recorded worktree path is stale (a moved worktree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant