Skip to content

✨ Worktree support, branch triage list, and branch review - #32

Draft
trasta298 wants to merge 3 commits into
mainfrom
feat/worktree-triage-review
Draft

✨ Worktree support, branch triage list, and branch review#32
trasta298 wants to merge 3 commits into
mainfrom
feat/worktree-triage-review

Conversation

@trasta298

Copy link
Copy Markdown
Owner

Summary

Three features aimed at parallel-branch workflows — increasingly common now that AI coding agents spawn many worktrees and branches (.claude/worktrees/, worktree-*, etc.):

1. Worktree first-class support

  • Linked worktrees are listed via git2 and refreshed with the graph
  • Branches checked out in a worktree get a marker in the graph ([agent-task ⌂]), and the commit detail pane shows the worktree path
  • w creates a worktree for the selected branch (path input pre-filled with a sibling directory), W removes it (confirmation; refuses when dirty via git worktree remove)
  • Checkout / branch deletion are guarded for branches checked out in another worktree — git2 does not enforce the CLI's "already checked out elsewhere" rule, so without this the other worktree could be corrupted

2. Branch triage list (B)

Full-screen list of local branches for cleaning up branch sprawl:

  • ahead/behind vs the base branch (detected via origin/HEADmainmaster), merged / base badges, worktree marker, last activity, commit subject
  • Enter checkout, d delete (warns when not merged), D bulk-delete merged branches (HEAD / base / worktree-attached branches are excluded), v / w / W also work from the list
  • Mouse: scroll, click to select, double-click to checkout

3. Branch review (v)

  • Shows the cumulative diff merge-base..branch (= git diff base...branch) in the existing FileSelect / FileDiff views
  • Status bar shows a base…branch badge and a REVIEW mode label
  • Works from the graph and from the branch list

Implementation notes

  • Worktree add/remove shell out to git, matching the existing fetch/push pattern, so CLI locking and checkout rules apply
  • Review plumbs a DiffSource::Range through FileSelect/FileDiff, reusing the diff viewer; the async uncommitted-diff sync is guarded so it never overwrites a review file list
  • Auto-refresh is paused in the branch list, same as FileSelect/FileDiff
  • Help popup, status bar hints, mouse routing, and the debug server (branch_list mode) are updated

Test plan

  • cargo test (72 passed) — new tests/branch_triage_test.rs covers base-branch detection, triage ahead/behind/merged flags, worktree listing, and range diffs
  • cargo clippy --all-targets / cargo fmt --check clean
  • Verified end-to-end via the debug TUI (--debug-listen): ⌂ markers, worktree create/remove, checkout guard message, triage list rendering, bulk prune of merged branches, review badge + range file diff

🤖 Generated with Claude Code

https://claude.ai/code/session_01HHpCigTLkn7MstZMcP9twP

trasta298 and others added 3 commits July 3, 2026 05:22
Three features for parallel-branch workflows (common with AI coding
agents that spawn many worktrees/branches):

- Worktrees: list linked worktrees, show a ⌂ marker on their branches
  in the graph and the worktree path in the commit detail pane. Create
  (w) and remove (W) worktrees via the git CLI. Guard checkout/delete
  of branches checked out in another worktree, which git2 does not
  enforce.
- Branch triage list (B): full-screen list of local branches with
  ahead/behind vs the base branch (origin/HEAD -> main -> master),
  merged/base badges, worktree marker, last activity and subject.
  Checkout (Enter), delete (d), bulk-delete merged branches (D).
- Branch review (v): show the cumulative diff merge-base..branch
  (git diff base...branch) in the existing file list / file diff
  views, with a base…branch badge in the status bar.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHpCigTLkn7MstZMcP9twP
RUSTSEC-2026-0194/0195 are DoS issues in quick-xml's XML parsing,
patched only in 0.41.0, which syntect -> plist cannot use yet. keifu
never parses untrusted XML (syntect loads its bundled binary dumps),
so the advisories are not reachable.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHpCigTLkn7MstZMcP9twP
Performance:
- Compute branch review diffs on a background thread; the UI showed
  a freeze on large branches (same mpsc pattern as commit diffs)
- Build graph rows for the visible window only instead of all ~500
  rows on every frame (the offset is now synced by clamp_graph_offset)
- Read worktree HEAD files directly instead of opening each worktree
  as a Repository on every auto-refresh
- Replace O(n²) already-shown scans in build_graph with a HashSet
- Resolve HEAD once in BranchInfo::list_all instead of per branch
- Skip full row clones for branch-list movement keys

UX:
- Show errors in a wrapping dialog; long git errors were clipped to
  one status-bar line and unreadable
- Clear stale in-progress messages when an operation fails, and stop
  silent auto-fetch from pinning unrelated messages forever
- Drop whole status-bar hints that don't fit instead of clipping
  mid-word; fixed-height dialogs so y/n hints survive 24-row terminals
- Checkout now reports success, and dirty-tree conflicts get an
  actionable message instead of raw git2 codes
- Empty states for a fresh repo and an empty branch list; "1 file
  changed" pluralization; neutral search badge only after typing
- Branch list: name column sized to content, subject preferred over
  date on narrow widths; B toggles the list; ? opens help from it
- Help popup: Branch List / Diff View sections, readable width on
  narrow terminals; detail panes stack below 70 columns

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHpCigTLkn7MstZMcP9twP
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