Skip to content

worktree: Add worktree management commands, per-worktree trunks, and worktree-aware filtering#1173

Open
ed-irl wants to merge 2 commits into
ed-irl/integration-gitfrom
ed-irl/integration-handler
Open

worktree: Add worktree management commands, per-worktree trunks, and worktree-aware filtering#1173
ed-irl wants to merge 2 commits into
ed-irl/integration-gitfrom
ed-irl/integration-handler

Conversation

@ed-irl

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

Copy link
Copy Markdown
Collaborator

Add a gs worktree command 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/--branch also creates a tracked branch stacked on that trunk; --no-trunk preserves the legacy detached-HEAD behavior.
  • worktree list lists worktrees with their checked-out branch and stack.

State: a new optional, additive worktree-trunks registry 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/--worktree and repo restack -w/--worktree scope 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

@ed-irl

ed-irl commented May 19, 2026

Copy link
Copy Markdown
Collaborator Author

@ed-irl ed-irl force-pushed the ed-irl/integration-git branch from a4c832c to da5a5d4 Compare June 2, 2026 20:21
@ed-irl ed-irl force-pushed the ed-irl/integration-handler branch 2 times, most recently from 9a7fb4b to 9b2df5f Compare June 2, 2026 20:24
@ed-irl ed-irl force-pushed the ed-irl/integration-git branch from da5a5d4 to 7ac5544 Compare June 2, 2026 20:24
@ed-irl ed-irl force-pushed the ed-irl/integration-handler branch from 9b2df5f to 579bd8f Compare June 2, 2026 20:25
@ed-irl ed-irl added the skip changelog PRs that don't need a changelog. label Jun 2, 2026
@ed-irl ed-irl force-pushed the ed-irl/integration-git branch 2 times, most recently from da5a5d4 to 36bc98e Compare June 8, 2026 11:15
@ed-irl ed-irl force-pushed the ed-irl/integration-handler branch from 579bd8f to 96ee66a Compare June 8, 2026 11:15
@ed-irl ed-irl force-pushed the ed-irl/integration-git branch from 36bc98e to c8ef032 Compare June 12, 2026 20:08
@ed-irl ed-irl force-pushed the ed-irl/integration-handler branch from 96ee66a to b8affd4 Compare June 12, 2026 20:08
@ed-irl ed-irl force-pushed the ed-irl/integration-git branch from c8ef032 to f44afe8 Compare June 13, 2026 13:40
@ed-irl ed-irl force-pushed the ed-irl/integration-handler branch from b8affd4 to 874ae48 Compare June 13, 2026 13:40
@ed-irl ed-irl force-pushed the ed-irl/integration-git branch from f44afe8 to 30f5d97 Compare June 15, 2026 09:53
@ed-irl ed-irl force-pushed the ed-irl/integration-handler branch from 874ae48 to 2ea1183 Compare June 15, 2026 09:53
@ed-irl ed-irl force-pushed the ed-irl/integration-git branch from 30f5d97 to 58442a1 Compare June 19, 2026 01:06
@ed-irl ed-irl changed the title integration: Add handler package for integration branch operations worktree: Add worktree management commands, per-worktree trunks, and worktree-aware filtering Jun 19, 2026
@ed-irl ed-irl force-pushed the ed-irl/integration-handler branch from 2ea1183 to 23ee46e Compare June 19, 2026 01:07
ed-irl added 2 commits June 23, 2026 11:43
[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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip changelog PRs that don't need a changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant