Skip to content

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

Draft
ed-irl wants to merge 1 commit into
branch-comment-testsfrom
branch-comment-stale
Draft

worktree: Add management commands, per-worktree trunks, and worktree-aware filtering#1222
ed-irl wants to merge 1 commit into
branch-comment-testsfrom
branch-comment-stale

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 by default: a local
branch (named after the worktree directory, or set with --trunk) that
tracks the same remote ref as the canonical trunk. Stacks created in
the worktree are based on this branch, so repo sync and restacks in
different worktrees never contend on a single shared trunk checkout.
Use -b to also create a tracked branch stacked on the worktree trunk,
or --no-trunk for the legacy detached-HEAD behavior.

The state store gains a per-worktree trunk registry (an additive,
optional key, so older repositories and binaries are unaffected).
Trunk-equivalence now flows through the branch graph and branch
transactions: any registered worktree trunk is treated as a graph
root, so traversals stop at it and it cannot itself be tracked.

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, and resolve the displayed/synced trunk per worktree
via Store.TrunkFor.

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

@ed-irl ed-irl force-pushed the branch-comment-tests branch from d42cd46 to e683e4f Compare June 2, 2026 20:22
@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-tests branch 2 times, most recently from bc2d528 to 5228b63 Compare June 8, 2026 10:18
@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-tests branch from d270ec2 to 0a8ca42 Compare June 8, 2026 11:15
@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-tests branch from 0a8ca42 to 03fafd4 Compare June 12, 2026 20:07
@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-tests branch from 03fafd4 to 1f477e3 Compare June 13, 2026 13:39
@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-tests branch from 1f477e3 to 7241e23 Compare June 15, 2026 09:52
@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-tests branch from f84f05d to c2cb662 Compare June 19, 2026 01:03
@ed-irl ed-irl changed the title branch comment: compute outdated/stale from diff state worktree: Add management commands, per-worktree trunks, and worktree-aware filtering Jun 19, 2026
@ed-irl ed-irl force-pushed the branch-comment-stale branch from 41864dd to 93682d9 Compare June 19, 2026 01:04
Until now shamhub's inline comments hard-coded Outdated:false; the
boolean flowed through to the JSON output but never told the truth.
Real forges (GitHub, GitLab) compute outdated as "the line this
comment was anchored to no longer matches the current head diff" —
without that, the VSCode extension's stale-comment surface has
nothing to render against in tests.

Plumb the same shape end-to-end in shamhub:

  - shamComment.CommitSHA: captured at post time via 'git rev-parse'
    on the change's head branch. The forge now knows the exact
    commit each comment was anchored to.
  - diffmap.Mapper.LineModified: given an already-parsed unified
    diff, ask whether a path:line on the LEFT or RIGHT side was
    touched. The RIGHT/OLD mapping is documented inline — comment
    anchors are on the RIGHT side of the original PR diff (the
    post-commit's version), which becomes the OLD side of the
    post-commit..head diff used for stale detection.
  - handleListInlineComments: for each comment, run
    'git diff --unified=0 commitSHA..head -- path' against the
    bare repo, parse the result with diffmap, and report stale if
    the anchored line falls into a modified hunk. Comments without
    a captured CommitSHA fall through to the existing Outdated
    override (test seeds + the new shamhub -outdated flag).
  - shamhub 'comment edit -outdated=true|false' force-sets the
    stale flag for tests that don't want to set up divergent
    commits.

The new test script (branch_comment_stale.txt) covers the full
flow: post two comments on the same head, amend the file so one
anchor line changes and the other doesn't, push the new head, and
verify only the touched comment reports outdated.

This is the prerequisite the extension-json commit's stale field
was waiting on.
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