worktree: Add worktree management commands, per-worktree trunks, and worktree-aware filtering#1173
Open
ed-irl wants to merge 2 commits into
Open
worktree: Add worktree management commands, per-worktree trunks, and worktree-aware filtering#1173ed-irl wants to merge 2 commits into
ed-irl wants to merge 2 commits into
Conversation
Collaborator
Author
This was referenced May 19, 2026
a4c832c to
da5a5d4
Compare
9a7fb4b to
9b2df5f
Compare
da5a5d4 to
7ac5544
Compare
9b2df5f to
579bd8f
Compare
da5a5d4 to
36bc98e
Compare
579bd8f to
96ee66a
Compare
36bc98e to
c8ef032
Compare
96ee66a to
b8affd4
Compare
This was referenced Jun 12, 2026
c8ef032 to
f44afe8
Compare
b8affd4 to
874ae48
Compare
f44afe8 to
30f5d97
Compare
874ae48 to
2ea1183
Compare
30f5d97 to
58442a1
Compare
2ea1183 to
23ee46e
Compare
[skip changelog]: internal handler package; user-facing commands ship in follow-up PRs.
internal/handler/integration provides the business logic for the
integration branch concept: a repo-scoped singleton that combines tips
of multiple tracked branches by sequentially merging them onto trunk.
Handler operations: Create, Delete, AddTip, RemoveTip, Show, Checkout,
Rebuild, and Submit. Checkout switches the worktree to the integration
branch after verifying that it exists. Rebuild merges with --no-ff in
tip order with rerere enabled per-command. On conflict, the merge is
left in the worktree for the user to resolve; the remaining tips and
the captured original tip hashes are persisted via
SetPendingIntegrationRebuild so the next Rebuild invocation resumes
from where it left off. A new *ConflictError carries the conflicting
tip's name and paths. Submit pushes with --force-with-lease against
the last recorded push hash and never calls any forge API.
Two hook methods drive auto behavior from the wrappers:
- MaybeRebuild detects per-tip hash drift and regenerates when any
tip has moved.
- MaybeRebuildAndSubmit additionally pushes when a non-empty
LastPushedHash signals the user has previously submitted manually.
Both hooks downgrade rebuild conflicts and push failures to warnings so
they cannot poison the outer command.
58442a1 to
9601c86
Compare
23ee46e to
0322a34
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 a
gs worktreecommand group and a per-worktree trunk concept that lets stacks in different worktrees sync and restack without contending on a single shared trunk checkout.Commands:
worktree create <path>creates a Git worktree. By default it sets up a per-worktree trunk: a local branch (named after the worktree directory, or--trunk) that tracks the same remote ref as the canonical trunk.-b/--branchalso creates a tracked branch stacked on that trunk;--no-trunkpreserves the legacy detached-HEAD behavior.worktree listlists worktrees with their checked-out branch and stack.State: a new optional, additive
worktree-trunksregistry maps each per-worktree trunk branch to its owning worktree root. Store gains IsTrunk, TrunkFor, WorktreeTrunks, and Register/UnregisterWorktreeTrunk. Branch-tracking invariants now treat any registered trunk as a graph root: trunks may not be tracked or deleted, and branches may stack directly on them.BranchGraph treats all trunk-equivalents as roots, so downstack and Bottom traversals stop at a worktree trunk instead of bleeding into the canonical trunk. Adds StacksInWorktree to collect full stacks with a branch checked out in a given worktree.
Filtering:
log short -w/--worktreeandrepo restack -w/--worktreescope output and restacking to stacks present in the current worktree. The sync handler now distinguishes the canonical remote trunk from the local per-worktree trunk it pulls into, fast-forwarding the local trunk from the remote ref.Part of #1244