Skip to content

feat: add worktree management commands, per-worktree trunks, and worktree-aware filtering#1223

Draft
ed-irl wants to merge 2 commits into
branch-comment-stalefrom
branch-comment-scopes
Draft

feat: add worktree management commands, per-worktree trunks, and worktree-aware filtering#1223
ed-irl wants to merge 2 commits into
branch-comment-stalefrom
branch-comment-scopes

Conversation

@ed-irl

@ed-irl ed-irl commented Jun 2, 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 dir, or --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 keeps the legacy detached-HEAD behavior; -b also creates a tracked branch stacked on the worktree trunk.

Persist the per-worktree trunk registry in the state store under an additive, optional worktree-trunks key (older binaries and pre-feature repos see no entry and fall back to the canonical trunk). Add Store.IsTrunk, TrunkFor, WorktreeTrunks, and register/unregister methods. Trunk checks throughout the state and branch-graph layers now treat every registered worktree trunk as a graph root, so traversals (Downstack, Bottom, tx path-finding) stop at them and a branch may be stacked directly on a worktree trunk.

Add -w/--worktree to log short and repo restack to scope operations to stacks with at least one branch checked out in the current worktree, backed by BranchGraph.StacksInWorktree. sync pulls the canonical remote trunk into the worktree's local trunk. repo restack gains SkipCheckout and handles checkout itself.

Includes unit tests for the trunk registry and graph roots, plus test scripts covering worktree create/list, the -w filters, and branch create/restack when trunk is checked out elsewhere.

@ed-irl ed-irl force-pushed the branch-comment-stale branch from 13fcb5b to ce6c1aa Compare June 2, 2026 20:08
@ed-irl ed-irl force-pushed the branch-comment-scopes branch from 2f2d7a9 to 673dc16 Compare June 2, 2026 20:14
@ed-irl ed-irl force-pushed the branch-comment-stale branch from 5582ec7 to ee1f597 Compare June 2, 2026 22:20
@ed-irl ed-irl force-pushed the branch-comment-scopes branch from 673dc16 to 3c58177 Compare June 2, 2026 22:30
@ed-irl ed-irl force-pushed the branch-comment-stale branch from ee1f597 to 9f8657d Compare June 8, 2026 10:18
@ed-irl ed-irl force-pushed the branch-comment-scopes branch from 3c58177 to 75e05c0 Compare June 8, 2026 10:19
@ed-irl ed-irl force-pushed the branch-comment-stale branch from 1113e5d to 312db25 Compare June 8, 2026 11:15
@ed-irl ed-irl force-pushed the branch-comment-scopes branch from e46ecf6 to 658c245 Compare June 8, 2026 11:15
@ed-irl ed-irl force-pushed the branch-comment-stale branch from 312db25 to 6ab1da8 Compare June 12, 2026 20:07
@ed-irl ed-irl force-pushed the branch-comment-scopes branch from 658c245 to 9b32be2 Compare June 12, 2026 20:07
@ed-irl ed-irl force-pushed the branch-comment-stale branch from 6ab1da8 to 167cca4 Compare June 13, 2026 13:39
@ed-irl ed-irl force-pushed the branch-comment-scopes branch from 9b32be2 to b8a0e76 Compare June 13, 2026 13:39
@ed-irl ed-irl force-pushed the branch-comment-stale branch from 167cca4 to d049480 Compare June 15, 2026 09:52
@ed-irl ed-irl force-pushed the branch-comment-scopes branch from b8a0e76 to 9bb9a70 Compare June 15, 2026 09:53
@ed-irl ed-irl force-pushed the branch-comment-stale branch from 41864dd to 93682d9 Compare June 19, 2026 01:04
@ed-irl ed-irl changed the title branch comment: support pr and file scope variants feat: add worktree management commands, per-worktree trunks, and worktree-aware filtering Jun 19, 2026
@ed-irl ed-irl force-pushed the branch-comment-scopes branch from 00e9ec6 to ed5caa4 Compare June 19, 2026 01:04
ed-irl and others added 2 commits June 23, 2026 11:43
Until now every inline comment was line-scoped: anchored to a
specific path:line on the diff. The extension contract (issue
irl-llc/git-spice-code-extension#40) wants three rendering surfaces:

  - line: anchored to one line (existing)
  - file: anchored to a file but not a line — rendered at the top
    of the file diff
  - pr:   not anchored to anything — rendered at the top of the
    summary diff

Plumb that distinction end-to-end:

  - forge.CommentScope enum + String() ("pr"/"file"/"line").
  - forge.CommentRange struct for multi-line ranges.
  - forge.InlineComment and InlineCommentRequest grow Scope, Range,
    Side fields. (CommitSHA still lands in the JSON-exposure commit
    above.)
  - shamhub plumbs Scope/Range through the inline-comment API,
    storage, and the SubmitReview batch path. The list filter
    switches from "Path \!= ''" to "Scope \!= ''" so PR-scope
    comments (which have no path) appear, while change-level
    comments created via the legacy non-inline endpoint stay
    excluded.
  - shamhub 'comment edit' is unchanged here — Scope is set at
    post time, not via the edit knob.

CLI shape — the positional anchor argument now distinguishes
scope by its form:

  gs branch comment add file.go:42         line scope
  gs branch comment add file.go:42-50      line scope multi-line
  gs branch comment add file.go            file scope (path only)
  gs branch comment add --pr               pr scope (no anchor)

parseAnchor centralizes the decoding and rejects --pr-with-arg and
missing-anchor cases up front so the user gets a clear error before
any forge call. parseFileAndRange is split out of parseFileAndLine
to back the multi-line form.

Test branch_comment_scopes.txt exercises all three scopes, confirms
they round-trip through 'gs branch comment list', and verifies the
two error cases. The JSON-shape assertion lives in the
extension-json commit above this one.
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