feat: add worktree management commands and per-worktree trunks#1187
Open
ed-irl wants to merge 4 commits into
Open
feat: add worktree management commands and per-worktree trunks#1187ed-irl wants to merge 4 commits into
ed-irl wants to merge 4 commits into
Conversation
Collaborator
Author
|
This change is part of the following stack: Change managed by git-spice. |
dd48baf to
57ee941
Compare
9f53a27 to
ab8825b
Compare
42e0c7c to
c4c89ca
Compare
c4c89ca to
a2cf5db
Compare
This was referenced Jun 23, 2026
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)
a2cf5db to
a9f1685
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
gs worktree createandgs worktree listfor managing Git worktrees.worktree createsets up a per-worktree trunk by default: a local branch(named after the worktree directory, or set with
--trunk) that tracks thesame remote ref as the canonical trunk. Stacks in different worktrees are
based on their own trunk, so
repo syncand restacks never contend on asingle shared trunk checkout.
--no-trunkkeeps the detached-HEAD behavior,and
-bcreates a tracked branch stacked on the worktree trunk.Worktree trunks are recorded in a new, additive state key and treated as
graph roots:
IsTrunkandBranchGraphtraversals stop at any trunk, andTrunkForresolves the trunk that applies to a given worktree. Trunk syncnow pulls the canonical remote ref into the worktree's local trunk.
Add
-w/--worktreetolog shortandrepo restackto scope operations tostacks with a branch checked out in the current worktree.
Part of #1247