Skip to content

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

Open
ed-irl wants to merge 1 commit into
ed-irl/scriptrunfrom
integration-state
Open

worktree: Add worktree commands, per-worktree trunks, and worktree-aware filtering#1165
ed-irl wants to merge 1 commit into
ed-irl/scriptrunfrom
integration-state

Conversation

@ed-irl

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

Copy link
Copy Markdown
Collaborator

Add gs worktree create and gs worktree list. worktree create sets up a per-worktree trunk: a local branch (named after the worktree directory, or set with --trunk) that tracks the same remote ref as the canonical trunk, so sync and restack in different worktrees never contend on a single shared trunk checkout. --no-trunk preserves the old detached-HEAD behavior, and -b stacks a new tracked branch on the worktree trunk.

Introduce a persisted per-worktree trunk registry in state.Store (worktree.go): RegisterWorktreeTrunk, UnregisterWorktreeTrunk, WorktreeTrunks, TrunkFor, and IsTrunk. The registry lives under an additive, optional store key, so older repos and binaries simply see no entry. IsTrunk now treats both the canonical trunk and any registered worktree trunk as graph roots; BranchTx upsert/delete/path checks switch from == trunk to IsTrunk.

Teach BranchGraph about trunk-equivalents: it loads WorktreeTrunks from the BranchLoader, treats all of them as roots in Downstack/Bottom, and adds StacksInWorktree to enumerate complete stacks that have at least one branch checked out in a given worktree.

Wire worktree-aware behavior through the handlers:

  • list: add -w/--worktree to log short/log long, scoping output to the current worktree's stacks and rendering them under the worktree's own trunk (TrunkFor).
  • restack: add WorktreeFilter and SkipCheckout to the request; repo restack -w limits restacking to stacks in the current worktree.
  • sync: split canonical trunk (remote ref to pull from) from the worktree's local trunk (the branch to pull into), a no-op in the primary worktree.

Add git.Repository.WorktreeAdd, expose GitWorktree.RootDir on spice.Service, and add spice.Service.WorktreeTrunks/TrunkFor. Includes unit tests, test scripts, regenerated docs/help, and a changelog entry.

@ed-irl ed-irl force-pushed the integration-state branch from 5f6e857 to fc67eba Compare May 19, 2026 10:19
@ed-irl

ed-irl commented May 19, 2026

Copy link
Copy Markdown
Collaborator Author

@ed-irl ed-irl changed the base branch from main to ed-irl/scriptrun June 2, 2026 20:12
@ed-irl ed-irl force-pushed the integration-state branch 2 times, most recently from 2f117ea to 93c644e Compare June 8, 2026 11:15
@ed-irl ed-irl force-pushed the ed-irl/scriptrun branch from 5d13e29 to 3e9d081 Compare June 12, 2026 20:07
@ed-irl ed-irl force-pushed the integration-state branch from 93c644e to 512b215 Compare June 12, 2026 20:08
@ed-irl ed-irl force-pushed the ed-irl/scriptrun branch from 3e9d081 to 1373b7f Compare June 13, 2026 13:39
@ed-irl ed-irl force-pushed the integration-state branch from 512b215 to 8575070 Compare June 13, 2026 13:40
@ed-irl ed-irl force-pushed the ed-irl/scriptrun branch from 1373b7f to 4cbacbc Compare June 15, 2026 09:52
@ed-irl ed-irl force-pushed the integration-state branch from 8575070 to b0c48d9 Compare June 15, 2026 09:53
@ed-irl ed-irl force-pushed the ed-irl/scriptrun branch from 4cbacbc to f700687 Compare June 19, 2026 01:01
@ed-irl ed-irl changed the title integration: Add state model for integration branch worktree: Add worktree commands, per-worktree trunks, and worktree-aware filtering Jun 19, 2026
@ed-irl ed-irl force-pushed the integration-state branch from b0c48d9 to e3c8701 Compare June 19, 2026 01:06
Introduce repo-scoped integrationInfo carrying a singleton integration
branch name, the upstream branch, the last pushed hash for
--force-with-lease leasing, and an ordered list of tips with the hashes
recorded at the last rebuild.

Adds Store.Integration / Store.SetIntegration as the public API and
bumps the state storage layout to VersionThree. The version is upgraded
only when an integration is configured, so existing repos that never opt
in keep V1 or V2.

SetRemote preserves integration through remote changes; clearing the
integration drops the version back to its prior level.

Extends the spice.Service Store interface with Integration and
SetIntegration so the service layer can read and write the
configuration. spice.Service.RenameBranch now rewrites any integration
tip that references the renamed branch; rename failures of the
integration update are surfaced as warnings rather than aborting the
primary rename.

Also adds Store.PendingIntegrationRebuild,
Store.SetPendingIntegrationRebuild, and
Store.ClearPendingIntegrationRebuild for persisting a rebuild that was
paused mid-flight (typically by a merge conflict). The handler uses
this to support resuming after the user resolves conflicts in the
worktree.
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