Skip to content

fix(switch): diff previews against the upstream-aware comparison base - #3305

Merged
max-sixty merged 1 commit into
mainfrom
summary-tab-dim
Jun 29, 2026
Merged

max-sixty merged 1 commit into
mainfrom
summary-tab-dim

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

What

The interactive picker's branch-diff preview pane and the LLM branch summary diffed against the raw local default branch, while the wt list comparison columns and the tab-dimming signals already measure against the upstream-aware comparison base. On a fork whose local default lags its upstream, this made the summary describe dozens of upstream commits as the branch's own changes and let a dimmed tab number contradict a non-empty pane. Orphan branches — which share no merge base with the default — rendered "no changes to summarize" instead of their content.

How

Both panes now resolve their base through a new Repository::branch_diff_spec(head), which measures against IntegrationTargets::primary (the upstream ref when the local default lags it, memoized per repo) and falls back to a full diff against the empty tree for orphan branches. A merge-base error is no longer mistaken for an orphan. The primary-else-default base selection now lives in a single shared select_comparison_base, so the columns and the panes are structurally guaranteed to pick the same base.

Where to look

  • src/git/repository/integration.rs — branch_diff_spec, the memoized comparison_base, and the shared select_comparison_base rule.
  • src/summary.rs and src/commands/picker/items.rs — the two call sites routed through the new helper.
  • src/commands/list/collect/tasks.rs — the list columns delegate to the shared rule too.

Testing

Regression tests on both surfaces (pane and summary) for the orphan case and the upstream-aware base — the upstream-aware tests set up a local default that genuinely lags a tracking ref and fail on the old code. Existing cache/dimming tests pass. Full local pre-merge gate green (4283 tests). Not covered: the merge-base-error path (hard to reproduce deterministically; it degrades to the normal three-dot range).

Trade-offs

The preview path captures its own ref snapshot rather than reusing the list collector's already-captured one — bounded to one extra for-each-ref pair per process (memoized, off the first-paint path). For orphans, the numeric main…± list column still shows 0 (it measures lines-ahead-of-merge-base) while the pane/summary show content; these answer different questions.

This was written by Claude Code on behalf of max

The branch-diff preview pane and the LLM branch summary diffed against the raw local default branch, while the list columns and the tab-dimming signals use the upstream-aware comparison base. On a fork whose local default lags its upstream this made the summary describe upstream commits as the branch's own changes, and let the dimmed tab number contradict a non-empty pane. Orphan branches, which share no merge base with the default, rendered "no changes to summarize" instead of their content.

Both panes now resolve their base through a new Repository::branch_diff_spec, which measures against IntegrationTargets::primary (the upstream ref when the local default lags it) and falls back to a full empty-tree diff for orphans; a merge-base error is no longer mistaken for an orphan. The primary-else-default base selection lives in one shared select_comparison_base, so the columns and the panes can't drift onto different bases.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Approved. Required test (linux), test (macos), lint, and both codecov checks (codecov/patch, codecov/project) are green; test (windows) was still running when this review session ended, so that one leg is unverified on my side — it mirrors the other test legs and showed no failure while polling. If it goes red, ping and I'll take another look.

@max-sixty
max-sixty merged commit afb3f5e into main Jun 29, 2026
36 checks passed
@max-sixty
max-sixty deleted the summary-tab-dim branch June 29, 2026 00:41
max-sixty added a commit that referenced this pull request Jun 29, 2026
…parison base (#3308)

Follow-up to #3305. That PR routed the picker's diff/summary preview
panes through the upstream-aware comparison base, which is resolved from
a `RefSnapshot` and memoized on the repo's `RepoCache`. But the preview
path captured its *own* snapshot — a second `git for-each-ref` scan
duplicating the one the `wt list` collector already runs a moment
earlier.

This primes that memoized base from the collector's snapshot.
`resolve_comparison_base` splits into a snapshot-taking core
(`comparison_base_from`) shared by the lazy path and a new
`prime_comparison_base`; the collector calls the latter once from the
snapshot it already holds. The picker's preview panes run on a clone of
the collector's `Repository` (shared `Arc<RepoCache>`) and `wt list
--full`'s summary column runs on it directly, so both read the primed
base instead of re-scanning. The lazy capture remains as the fallback
for any caller that previews without collecting first.

No behavior change — the base value and its staleness characteristics
are identical; only the scan that resolves it is shared instead of
repeated.

**Testing**: new `prime_comparison_base_feeds_branch_diff_spec`
exercises the prime path and asserts it feeds `branch_diff_spec` the
upstream-aware base; the existing branch-diff and summary tests cover
the lazy path. Feature-gated clippy and the rustdoc `-Dwarnings` gate
are clean.

> _This was written by Claude Code on behalf of max_

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Jun 29, 2026
…3309)

Completes the 0.63.0 changelog for everything that landed on `main`
during the release PR's CI windows:

- Documents [#3301](#3301)
(picker default view keeps collect order),
[#3305](#3305) (picker
branch-diff preview/summary use the upstream-aware base), and
[#3306](#3306) (picker
comment previews render fenced code blocks cleanly).
- Relocates the
[#3286](#3286) statusline
entry, which #3286's own commit added under the already-released
**0.62.0** section (its branch predated the 0.63.0 section), up to
**0.63.0** where it ships.

> _This was written by Claude Code on behalf of max_
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.63.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## Release Notes

### Improved

- **`[list] columns` can force a column on past `--full`**: Listing a column now overrides the `--full` / `[list] summary` presets — `columns = ["branch", "ci"]` shows the CI column without `--full`. Hard data-source prerequisites still apply: a listed `summary` with no `[commit.generation]` command, or `url` with no template, stays hidden, since listing can't conjure data that isn't configured. ([#3295](max-sixty/worktrunk#3295))

- **`Alt-r` in the picker refreshes the preview panes, not just the rows**: `Alt-r` re-collected the rows but kept serving cached preview content, so editing a tracked file and refreshing still showed the pre-edit diff. It now clears the preview cache too, recomputing the working-tree / log / branch-diff / upstream / summary tabs and re-fetching `pr` / `comments`. Unchanged branches re-read from the content-keyed on-disk cache, so only genuinely changed content pays a recompute. ([#3293](max-sixty/worktrunk#3293))

- **A narrowed `wt list` is now actually faster**: A narrowed `[list] columns` selection (e.g. `["branch", "path"]`) now runs only the git work its columns need. It previously ran every per-worktree `git status`, diff, and ahead/behind walk regardless, then discarded the unselected results — so a trimmed view was no faster than the full table, and on a repo with many dirty worktrees that discarded work was the bulk of the wall-clock cost. ([#3274](max-sixty/worktrunk#3274), thanks @jtaby for reporting)

- **Fewer duplicate git calls in `wt list --full`**: The two integration probes per row (the conflict bit for `main-state` and the clean-merge tree for the integration column) issued a byte-identical `git merge-tree`, and the shared default-branch tip was peeled to its tree once per row. Both are now deduplicated through the in-memory cache, so each resolves once per run instead of once per worktree. ([#3288](max-sixty/worktrunk#3288), [#3289](max-sixty/worktrunk#3289))

- **Picker `comments` tab avoids redundant forge fetches**: The picker's `comments` preview tab gained an on-disk cache keyed by the PR's `updatedAt` (which rides for free on the CI fetch the picker already makes), so a repeat `wt switch` skips the per-row `gh pr view --json comments` fetch when the thread is unchanged and paints the tab instantly instead of showing "Loading comments…". The cache is also primed from the `gh pr list` call the picker already makes, so the tab skips its own fetch even on a session's first open (including PRs with no comments). GitHub only. ([#3294](max-sixty/worktrunk#3294), [#3299](max-sixty/worktrunk#3299))

- **Statusline width comes from `COLUMNS`, not a parent-process walk**: `wt list statusline` used to spawn up to 10 `ps` calls plus `stty` per render to recover a terminal width, because Claude Code piped the subprocess with no inherited TTY. Claude Code now sets `COLUMNS`/`LINES` to the terminal dimensions before running the script (since v2.1.153), so the width comes straight from there — less a fixed 5-column margin for Claude Code's own UI — and the `ps`/`stty` walk is gone. On an older Claude Code that doesn't set `COLUMNS`, the line renders untruncated rather than walking the process tree. ([#3286](max-sixty/worktrunk#3286), closes [#2950](max-sixty/worktrunk#2950))

### Fixed

- **`wt list` diff and ahead/behind columns use the upstream default tip**: The `main↕` (ahead/behind) and `main…±` (diff) columns measured every branch against the *local* default-branch tip, so in a fork whose local `main` lagged its upstream they reported inflated counts — one fork branch showed `↑44` and `+∞ / -5K` when it was ~2 commits past the real upstream tip. They now diff against the same upstream-aware base the integration column already uses. ([#3280](max-sixty/worktrunk#3280))

- **Integrated branches no longer flash `✗` in `wt list`**: A squash-merged branch whose default branch later re-edited the same lines showed `✗` (would-conflict), even though `wt step prune` classified it as `⊂` (fully integrated) and removed it. The list now ranks the integration verdict above the downstream conflict, matching prune; a genuinely un-integrated conflict still shows `✗`. ([#3278](max-sixty/worktrunk#3278))

- **`wt list` divergence-overflow marker uses one emphasis level**: When an ahead/behind count overflows its digit budget, the `main↕` column's compact `C`/`K`/`∞` marker rendered the "behind" subcolumn as dim + bold (reading as bold red) instead of a clean one-level step. It now steps exactly one level — dim red → normal red — matching the "ahead" subcolumn, across `wt list` and the picker. ([#3303](max-sixty/worktrunk#3303))

- **Branch deletion on removal is atomic**: `wt remove` and prune now delete a branch with a compare-and-swap (`git update-ref -d <ref> <expected-sha>`) against the SHA the integration check already read, closing the window where a branch whose tip moved in between (e.g. a hook landing a commit) could be deleted. Such a branch is now retained with a clear message and a `wt remove -D <branch>` recovery hint. This also unifies the previously divergent safe-delete paths; explicit force-delete still uses `git branch -D`. ([#2903](max-sixty/worktrunk#2903))

- **`wt list` and picker Age/Message columns paint as soon as the commit batch lands**: These columns carry no async task — their data arrives with the initial `git log` batch — but stayed on the `·` placeholder until some slower task happened to redraw the row, so the commit message lagged behind a cache-warm Summary preview. They now paint the moment the batch lands. ([#3287](max-sixty/worktrunk#3287))

- **Picker `Alt-x` removal: no cursor flash, `--prs` rows preserved**: Removing a row with `Alt-x` flashed the `>` pointer to the top of the list for a frame, and in `--prs` mode made the streamed PR/MR rows vanish until the next `Alt-r`. Removal is now a synchronous in-place pool resync: the cursor lands on the row that slid up with no flash, and the PR/MR rows survive. ([#3268](max-sixty/worktrunk#3268), [#3275](max-sixty/worktrunk#3275))

- **Removable rows stay gray when selected in the picker**: A safe-to-delete worktree (integrated, or clean and even with the default branch) renders its row gray, but the gray vanished under the selection highlight — exactly when you're about to act on it. The gray now survives selection (selected row only; `wt list` and unselected rows are unchanged). ([#3267](max-sixty/worktrunk#3267))

- **Picker preview keeps its scroll when CI status arrives**: Scrolling down a diff and waiting a couple of seconds snapped it back to the top when the live CI fetch landed and re-rendered the pane. The re-render is now precise — a tab re-runs only when its own content would actually change — so a CI update no longer throws away the scroll position of an unrelated tab. ([#3292](max-sixty/worktrunk#3292))

- **Picker summary tab dims when there's nothing to summarize**: The summary preview tab (`5`) stayed lit on a clean branch with no commits ahead, unlike the diff tabs (1/3/4), which dim once their diff is known empty. It now dims in concert with them once both the branch diff and working tree are known empty. ([#3291](max-sixty/worktrunk#3291))

- **Picker default view keeps collect order**: With no query typed, the `wt switch` picker reordered rows by where each name's last `/` falls, so slash-bearing branches (`feature/…`, `perf/…`) sank toward the bottom and intermixed with other row kinds. The default view now preserves collect order. ([#3301](max-sixty/worktrunk#3301))

- **Picker branch-diff preview and summary use the upstream-aware base**: Like the `wt list` columns above, the picker's branch-diff preview pane and the LLM branch summary diffed against the raw local default branch, so a fork whose local default lagged upstream made them describe dozens of already-merged commits. They now use the same upstream-aware comparison base. ([#3305](max-sixty/worktrunk#3305))

- **Picker comment previews render fenced code blocks cleanly**: A fenced code block inside a PR/MR comment rendered as a garbled double gutter in the `wt switch` comments preview — alternating bar/no-bar lines with broken alignment. The code block now renders without the nested gutter. ([#3306](max-sixty/worktrunk#3306))

- **First-run hints show the config path wt actually loads from**: The picker's disabled-summary tab and the commit-generation setup prompt hardcoded `~/.config/worktrunk/config.toml`, so a user with `--config`, `WORKTRUNK_CONFIG_PATH`, or a non-default `$XDG_CONFIG_HOME` was told to edit a file wt never reads. Both now show the resolved path. ([#3290](max-sixty/worktrunk#3290), [#3298](max-sixty/worktrunk#3298))

### Internal

- **`-vv` trace and profiler accuracy**: `trace.log` is now purely human-readable, with the machine-parseable `[wt-trace]` fields living only in `trace.jsonl`; and the performance profile's cache analysis no longer reports stdin-driven commands (LLM `claude -p` calls, `git patch-id`) as duplicate re-runs, since their real input isn't captured in the command string. ([#3296](max-sixty/worktrunk#3296), [#3297](max-sixty/worktrunk#3297))

## Install worktrunk 0.63.0

### Install prebuilt binaries via shell script

`

See merge request: Harmonybrew/homebrew-core!13092
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.

2 participants