← Back to Pull requests

feat: switch a worktree's branch in place #500

Closed
unknown closed this pull request without merging on Nov 10, 2026 18:01 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 16:46 UTC
Author

Summary

Implements switch-worktree-branch from #495. Stacked on #498 (base feat/git-repository-management); the first commit archives enrich-repository-details so this change validates against the archived specs.

  • Backend (internal/workspace/switch.go): two-phase PreviewSwitch / SwitchWorktree with a purposeSwitch confirmation bound to worktree id+path, branch/head, target OID (and local tip) and the running-session set. Targets: local, remote (--track --create from refs/remotes/…), new (--no-track --create), detach — always --end-of-options, never --force/--discard-changes/--merge/--orphan/--ignore-other-worktrees. Blockers: tracked changes, in-progress operation, branch occupied (with occupant path), same target, unverifiable, existing local name. Warnings: untracked, locked, .gitmodules, sessions. Execution uses WithoutCancel + 3 min; overwritten-untracked → 409 listing ≤50 paths; hook/filter failures → 409 with the redacted first Git line and the refreshed state.

  • API: POST …/worktrees/{wid}/switch-preview and …/switch; snapshot worktree-switch-preview.json.

  • CLI: webmux worktree switch REPO WORKTREE (BRANCH | --track R/B | --create NAME [--from REF] | --detach REF) [--yes] [--json] with exit codes 0/1/2.

  • Web: SwitchBranch flow hosted by SwitchBranchDialog (home/sidebar) or as a RepositoryPanel subview (the panel's single detail view became a subview stack). Segmented 已有分支 / 新建分支 / 分离到提交, grouped searchable branch list with current/occupied branches disabled, auto preview via LatestRequest, 409 → re-preview, session acknowledgement, 改为在新工作树打开 (prefills the new-worktree dialog via a new preset) and 转到该工作树. "切换分支…" in WorktreeMenuItems; 在新工作树打开… on unoccupied branches in the 分支 tab. New Button wrap option (registered in the architecture guard).
  • Verification

  • make format, make check pass; make test-go green.

  • Vitest: only base64url.test.ts fails locally (Node 24 lacks Uint8Array.prototype.toBase64; repo pins 26). Fixed a menu-close race in RepositoryPanel.test.ts (3 consecutive green runs).

  • Playwright: worktree-switch.spec.ts (incl. open code tab marked 内容已更新 after the switch), worktrees, repository-scope, workspace-discovery — 48 passed.

  • Storybook overflow + design-system 25 passed (switch stories at 320×568 double-size text).
  • User stories

    New US-J16 (switch an existing worktree's branch); updated US-J05, coverage index, usage/protocol docs, verification log.

    Screenshots

    Demo repo as in #498.

    Worktree "⋯" menu gains 切换分支…

    | Viewport / theme | Before (#498) | After |
    |---|---|---|
    | desktop 1280×900 light | !before | !after |
    | desktop 1280×900 dark | !before | !after |
    | tablet 768×800 light | !before | !after |
    | tablet 768×800 dark | !before | !after |
    | phone 390×844 light | !before | !after |
    | phone 390×844 dark | !before | !after |

    切换分支 dialog from the sidebar (new)

    | Viewport | Light | Dark |
    |---|---|---|
    | desktop 1280×900 | !light | !dark |
    | tablet 768×800 | !light | !dark |
    | phone 390×844 | !light | !dark |

    切换 as a repository-panel subview (new)

    | Viewport | Light | Dark |
    |---|---|---|
    | desktop 1280×900 | !light | !dark |
    | tablet 768×800 | !light | !dark |
    | phone 390×844 | !light | !dark |

    Interaction

  • Desktop 1280×900 light — sidebar menu → 切换分支… → pick chore/old-deps → preview → 切换 → sidebar/home now show chore/old-deps:
  • !switch flow desktop

  • Phone 390×844 light — panel row menu on dirty docs/refresh → subview → preview blocked by uncommitted changes → 改为在新工作树打开 offered → 返回:
  • !blocked switch phone

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: mzdluo123 Review duration: 74m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #500"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%