Skip to content

feat: add worktree management commands and per-worktree trunks#1187

Open
ed-irl wants to merge 4 commits into
ed-irl/restack-options-paramfrom
ed-irl/worktree-management
Open

feat: add worktree management commands and per-worktree trunks#1187
ed-irl wants to merge 4 commits into
ed-irl/restack-options-paramfrom
ed-irl/worktree-management

Conversation

@ed-irl

@ed-irl ed-irl commented May 22, 2026

Copy link
Copy Markdown
Collaborator

Add gs worktree create and gs worktree list for managing Git worktrees.

worktree create sets up a per-worktree trunk by default: a local branch
(named after the worktree directory, or set with --trunk) that tracks the
same remote ref as the canonical trunk. Stacks in different worktrees are
based on their own trunk, so repo sync and restacks never contend on a
single shared trunk checkout. --no-trunk keeps the detached-HEAD behavior,
and -b creates a tracked branch stacked on the worktree trunk.

Worktree trunks are recorded in a new, additive state key and treated as
graph roots: IsTrunk and BranchGraph traversals stop at any trunk, and
TrunkFor resolves the trunk that applies to a given worktree. Trunk sync
now pulls the canonical remote ref into the worktree's local trunk.

Add -w/--worktree to log short and repo restack to scope operations to
stacks with a branch checked out in the current worktree.

Part of #1247

@ed-irl ed-irl force-pushed the ed-irl/worktree-management branch 4 times, most recently from dd48baf to 57ee941 Compare June 8, 2026 10:18
@ed-irl ed-irl force-pushed the ed-irl/worktree-management branch 3 times, most recently from 9f53a27 to ab8825b Compare June 15, 2026 09:52
@ed-irl ed-irl changed the title feat: add worktree management commands and worktree-aware filtering feat: add worktree management commands and per-worktree trunks Jun 19, 2026
@ed-irl ed-irl force-pushed the ed-irl/worktree-management branch from 42e0c7c to c4c89ca Compare June 19, 2026 01:01
@ed-irl ed-irl marked this pull request as ready for review June 19, 2026 01:04
@ed-irl ed-irl requested a review from abhinav June 19, 2026 01:04
@ed-irl ed-irl force-pushed the ed-irl/worktree-management branch from c4c89ca to a2cf5db Compare June 23, 2026 09:59
ed-irl added 3 commits June 23, 2026 11:38
Introduces restack.Options{AutoResolve} and threads an opts *Options
parameter through the high-level restack entry points (RestackBranch,
RestackStack, RestackDownstack) and the merge/sync RestackHandler
interfaces, with all current callers passing nil.

This is foundational plumbing for the restack auto-resolve feature.
Landing it on a branch below the consuming stacks lets every branch
inherit the 3-arg signature, rather than the signature change living
on a branch parallel to its callers.
Introduce `gs anchor create`, `gs anchor list`, and `gs anchor track` to manage per-worktree anchor branches: pointer branches that act as graph roots for linked worktrees, so sync and restack in different worktrees never contend on a shared trunk checkout.

- State: add an anchor registry to the store (`IsTrunk`, `TrunkFor`, `Anchors`, `RegisterAnchor`/`UnregisterAnchor`), persisted under an additive, optional `anchors` key.
- Branch graph: treat anchors as trunk-equivalent roots; add `StacksInWorktree` and `AnchorBranches`.
- Scope by worktree: `-w/--worktree` on `log short` and `repo restack`; sync pulls the canonical remote trunk into each worktree's local trunk.
- Git: add `Repository.WorktreeAdd`.

Includes help text, CLI reference, unit tests, and test scripts.
Fixes from adversarial review of the unreleased worktree anchor feature:
- anchor create rolls back the worktree and any branches it created
  when a later step fails, so a retry is not blocked by debris (B2)
- RegisterAnchor rejects a second anchor for one worktree and TrunkFor
  resolves deterministically regardless of map iteration order (M1)
- anchor list reads the anchor registry instead of dumping all
  worktrees (M2)
- repo sync rescues onto the worktree's local trunk, not the canonical
  trunk, after deleting the current branch (M3)
- WorktreeAdd requires Head or Detach to avoid creating a stray branch;
  --no-anchor --name is now rejected (M4)
@ed-irl ed-irl changed the base branch from main to ed-irl/restack-options-param June 24, 2026 01:33
@ed-irl ed-irl force-pushed the ed-irl/worktree-management branch from a2cf5db to a9f1685 Compare June 24, 2026 01:33
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