Skip to content

anchor: Make restack and log anchor-aware#1302

Open
ed-irl wants to merge 3 commits into
ed-irl/worktree-managementfrom
ed-irl/anchor-scope
Open

anchor: Make restack and log anchor-aware#1302
ed-irl wants to merge 3 commits into
ed-irl/worktree-managementfrom
ed-irl/anchor-scope

Conversation

@ed-irl

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

Copy link
Copy Markdown
Collaborator

Anchors are per-worktree trunks: graph roots disconnected from the canonical trunk. This makes restack and log surface them.

  • gs repo restack now also restacks stacks rooted at anchors, which an upstack-from-trunk walk never reaches. repo restack -w from inside an anchor worktree restacks that worktree's own anchor-rooted stack.
  • gs ll injects an anchor display node for another worktree's anchor-rooted stack, tagged [root anchor] or [internal anchor]. JSON output gains anchor and anchorKind fields.
  • Checking out a branch already in use by another worktree now fails with a legible BranchInUseError naming the worktree, instead of git's raw fatal.

Adds unit tests, test scripts, and a changelog entry.

ed-irl added 2 commits June 23, 2026 13:48
Anchor-scoping behaviors that complement the per-worktree anchor model,
keeping parallel worktrees from reaching across each other's stacks and
making anchors legible in the log.

Reach and isolation:

- 'gs repo restack' (whole repo) now also restacks stacks rooted at
  anchors (per-worktree trunks), which are graph roots disconnected
  from the canonical trunk and were previously unreachable. 'gs repo
  restack -w' stays scoped to the current worktree.

- Restack stays within the invoking worktree's anchor: an anchor is a
  graph root, so downstack stops at it and upstack stops at any child
  anchor. This is enforced structurally; a regression test documents it.

- Checking out a branch already in use by another worktree now fails
  with a legible 'branch X is in use by worktree <path>' error
  (typed git.BranchInUseError) instead of git's raw fatal.

Surfacing in the log:

- 'gs ll' shows another worktree's anchor-rooted stack instead of
  silently dropping it: the anchor pointer renders as an intermediate
  node under its base, tagged '[root anchor]' or '[internal anchor]',
  with its stack above it. '--json' gains per-branch 'anchor' and
  'anchorKind' fields.

Adds BranchGraph.Anchors(), a WholeRepo restack request flag,
anchor-node injection in the log handler, and a worktree pre-check in
Worktree.CheckoutBranch.
Fixes from adversarial review (anchor-scope layer):
- 'repo restack -w' run inside an anchor worktree now restacks that
  worktree's anchor-rooted stack instead of doing nothing: the worktree
  filter admits the stack rooted at the worktree's anchor, which may
  have no tracked branch checked out locally (B1)
- list: an internal anchor whose pinned base is filtered out of the
  view now roots at the display trunk instead of silently hiding its
  subtree (M6)
- restack: correct the WholeRepo doc to match its actual behavior
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