Skip to content

feat: Add worktree commands, per-worktree trunks, and worktree filters#1172

Open
ed-irl wants to merge 1 commit into
integration-statefrom
ed-irl/integration-git
Open

feat: Add worktree commands, per-worktree trunks, and worktree filters#1172
ed-irl wants to merge 1 commit into
integration-statefrom
ed-irl/integration-git

Conversation

@ed-irl

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

Copy link
Copy Markdown
Collaborator

Add 'gs worktree create' and 'gs worktree list' commands. By default,
'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 trunk as the main checkout. Stacks created in the worktree are
based on this branch, so 'gs repo sync' and restacks in different
worktrees never contend on a single shared trunk checkout. --no-trunk
keeps the legacy detached-HEAD behavior, and -b/--branch creates a
tracked branch stacked on the new trunk.

The state store gains a per-worktree trunk registry (WorktreeTrunk,
Register/Unregister, TrunkFor, IsTrunk). Trunk checks throughout the
store and branch graph now recognize any registered worktree trunk as a
trunk-equivalent graph root, so traversals stop at it and branches may
be stacked directly on it.

'log short' and 'repo restack' gain -w/--worktree to scope output and
restacking to stacks with a branch checked out in the current worktree,
backed by BranchGraph.StacksInWorktree. 'repo restack' also skips its
trailing checkout. SyncTrunk now distinguishes the canonical remote
trunk from the local trunk it pulls into, fetching the remote ref into
the worktree's own trunk.

Adds Repository.WorktreeAdd for creating worktrees.

Part of #1244

@ed-irl

ed-irl commented May 19, 2026

Copy link
Copy Markdown
Collaborator Author

@ed-irl ed-irl force-pushed the integration-state branch from fc67eba to 2f117ea Compare June 2, 2026 20:12
@ed-irl ed-irl force-pushed the ed-irl/integration-git branch 2 times, most recently from da5a5d4 to 7ac5544 Compare June 2, 2026 20:24
@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 from 7ac5544 to da5a5d4 Compare June 2, 2026 22:21
@ed-irl ed-irl force-pushed the integration-state branch from 2f117ea to 93c644e Compare June 8, 2026 11:15
@ed-irl ed-irl force-pushed the ed-irl/integration-git branch from da5a5d4 to 36bc98e Compare June 8, 2026 11:15
@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/integration-git branch from 36bc98e to c8ef032 Compare June 12, 2026 20:08
@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/integration-git branch from c8ef032 to f44afe8 Compare June 13, 2026 13:40
@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/integration-git branch from f44afe8 to 30f5d97 Compare June 15, 2026 09:53
@ed-irl ed-irl force-pushed the integration-state branch from b0c48d9 to e3c8701 Compare June 19, 2026 01:06
@ed-irl ed-irl changed the title git: Add Merge, IsClean, and CheckoutNewBranch worktree helpers feat: Add worktree commands, per-worktree trunks, and worktree filters Jun 19, 2026
@ed-irl ed-irl force-pushed the ed-irl/integration-git branch from 30f5d97 to 58442a1 Compare June 19, 2026 01:06
Worktree.Merge supports --no-ff and optional rerere via per-command
-c rerere.enabled=true -c rerere.autoupdate=true flags. On conflict the
merge is automatically aborted (default) and a *MergeConflictError
carrying the refs and unmerged paths is returned, leaving the worktree
at HEAD. Setting MergeOptions.LeaveConflict skips the abort so the
caller can drive a conflict-resolution flow.

Worktree.IsClean reports whether the worktree has uncommitted changes
among tracked files (untracked files are ignored), backed by
git status --porcelain --untracked-files=no.

Worktree.CheckoutNewBranch creates a new branch at an optional start
point in one operation, with a Force flag for git checkout -B semantics.
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