Repository navigation
fix(list): OR over local + upstream in integration column - #2513
Merged
Merged
Conversation
`wt list`'s integration column resolved a single target via `effective_integration_target`, which picks upstream in the diverged case. A branch merged into local `main` while origin/main had its own commits rendered as unintegrated, while `wt remove` and `wt merge` (post-#2507) correctly detected it. Same data, two different answers. Add `Repository::integration_targets()` returning a `(primary, optional secondary)` pair that mirrors `compute_integration_reason_uncached`'s preamble: a single ref for same-commit / strict-subset cases, both refs only when local and upstream have diverged. Each integration task (`IsAncestor`, `CommittedTreesMatch`, `HasFileChanges`, `WouldMergeAdd`) now combines signals across the pair — OR for positive signals (ancestor, trees match, patch-id), AND for inverted ones (has-added-changes, would-merge-add). Tasks short-circuit when the primary alone proves integration, so the common one-sided case stays one git op. Regression tests in `tests/integration_tests/list.rs` mirror `test_remove_merged_locally_when_upstream_diverged`: a branch whose content lives in local main (via `--no-ff` merge) renders as integrated even when origin/main has diverged, and the symmetric remote-squash case still works. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
approved these changes
May 1, 2026
3 tasks done
max-sixty
added a commit
that referenced
this pull request
May 1, 2026
…2515) ## Summary `wt step prune` was the lone remaining caller of `Repository::effective_integration_target` — a "pick one ref" helper whose own docstring warned it was unsafe for safety-critical checks. In the diverged case it returned `origin/main`, then handed it to `integration_reason`, which couldn't resolve an upstream of an already-remote ref and ended up checking only that single side. Branches merged into local `main` while `origin/main` had unique commits never got pruned — the same diverged-case false negative #2513 fixed for `wt list` and #2507 fixed for `wt remove` / `wt merge`. This change passes the local default branch directly to `integration_reason`, letting it OR over local + upstream internally like `wt remove` and `wt merge` already do. The actual deletion gate inside `prepare_worktree_removal` was already correct, so this just stops the outer filter from silently dropping legitimately-integrated candidates. `effective_integration_target`, `integration_target`, and their `RepoCache` fields are now dead and deleted. ## Test plan - [x] New regression `test_prune_locally_merged_when_upstream_diverged` (mirrors `test_remove_merged_locally_when_upstream_diverged`). Verified to fail on the pre-fix code path with `No merged worktrees to remove`, passes on the fix. - [x] Symmetric `test_prune_squash_merged_on_remote_when_local_diverged` covers the merged-on-remote direction; pins forward-compatibility. - [x] `cargo run -- hook pre-merge --yes` — 3411/3411 pass, no snapshots to review. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
3 of 4 tasks
max-sixty
added a commit
that referenced
this pull request
May 2, 2026
…class (#2528) ## Summary Replaces the ambient ref-keyed caches in `RepoCache` with an explicit, point-in-time `RefSnapshot` value threaded through read paths. This closes the bug class behind PR #2507 (post-`update-ref` integration check seeing pre-write SHAs) — and several latent variants — by making the caches that could go stale unrepresentable. ## Why `RepoCache` cached ref-name → SHA in `commit_shas: DashMap<String, String>`, plus composite caches keyed off it (`integration_reasons`, `effective_integration_targets`, `ahead_behind`, `integration_target` OnceCell, `tree_shas`, `resolved_refs`). When wt itself moved a ref mid-command — most prominently `wt merge` running `git update-ref refs/heads/<target>` to advance the local target — those caches went stale, and any downstream read returned pre-write SHAs. PR #2507 patched one symptom by adding `ref_is_ancestor` (a cache-bypass helper) at the integration-check call site. That works locally; every other ref-name read after a write was a latent bug. The structural fix: there is no longer an ambient ref-name → SHA cache. Callers explicitly capture a `RefSnapshot` at known points and thread it through the read paths. After ref-mutating operations, callers capture a fresh snapshot — the discipline lives at the small set of write boundaries (currently one site, `finish_after_merge`), not at every ref-name accessor. Background analysis: `docs/dev/cache-staleness.md` (commit ba8b239) walks through six options and the trade-offs. ## What changed - **New `src/git/repository/ref_snapshot.rs`** — `RefSnapshot` value type. One `for-each-ref` over local + remote refs, optional ahead/behind batch. Cloned by value, no `OnceCell`/`Arc`. ~330 lines including unit tests (the freshness contract test mutates a ref and re-captures). - **Two-tier API** — `_by_sha` siblings of cached methods (`is_ancestor_by_sha`, `merge_base_by_sha`, `branch_diff_stats_by_sha`, `ahead_behind_by_sha`, `has_added_changes_by_sha`, `trees_match_by_sha`, `merge_integration_probe_by_sha`, …). The persistent on-disk `sha_cache` (already SHA-keyed) sits behind these. - **Snapshot-taking integration path** — `compute_integration_lazy`, `integration_reason`, `compute_integration_reason_uncached`, `integration_targets`, `delete_branch_if_safe`, `remove_worktree_with_cleanup` all take `&RefSnapshot`. - **Post-write fresh-snapshot pattern** — `wt merge`'s `finish_after_merge` captures a *fresh* snapshot AFTER `handle_no_ff_merge`/`handle_push` runs `update-ref`. This is the structural fix for PR #2507. The `ref_is_ancestor` workaround is deleted. - **`wt list` migration** — pre-skeleton phase captures one snapshot; `TaskContext` carries it; tasks call `_by_sha` siblings via the snapshot. No regression intended (one extra `for-each-ref` upfront, lose per-task `rev-parse` fallbacks). - **Cache deletions** — `commit_shas`, `tree_shas`, `effective_integration_targets`, `integration_reasons`, `ahead_behind`, `integration_target` OnceCell, `resolved_refs` all gone from `RepoCache`. `LocalBranchInventory`'s priming side-effects (writes to `commit_shas`/`resolved_refs`) removed. - **Uncached primitives** — `rev_parse_commit`, `rev_parse_tree`, `resolve_preferring_branch` no longer cache; consumers that need SHA-stable lookups thread a `RefSnapshot`. - **Persistent caches retained** — on-disk `sha_cache::*` and the in-memory `merge_base` / `branch_diff_stats` caches keep their SHA-keyed contract. ## Snapshot test deltas Three `list_*_with_nonexistent_default_branch.snap` snapshots no longer show the same-commit `_` symbol when the configured default branch is missing — that was a false positive (no ref to compare against). `list_warns_when_commit_details_batch_fails.snap` now embeds the resolved SHA in the error rather than the literal `"main"` ref name (strict improvement — the SHA is what was passed to git). ## Regression coverage - PR #2507's regression test (`test_remove_merged_locally_when_upstream_diverged`) passes without `ref_is_ancestor`. - PR #2513's `test_list_integrated_when_merged_locally_with_upstream_diverged` passes. - New unit test: `RefSnapshot` capture-mutate-recapture confirms two captures observe distinct SHAs after `update-ref`. ## Out of scope (deferred) Both flagged by `/reviewing-code` and explicitly deferred: - `prepare_worktree_removal` re-captures a snapshot per candidate inside `step_prune` — N+1 `for-each-ref` calls. Threading an optional `&RefSnapshot` would make `step_prune` reuse its entry snapshot. Affects display consistency in unusual hook setups (a `post-remove` hook that runs `git fetch` between candidates can desync the displayed integration target from the safety decision); not a safety bug. - `head_shas` cache retained. Different staleness model (per-worktree, mutated by `commit`/`reset` rather than `update-ref`); design doc lists it as a remaining vector. Out of scope for this PR's integration-target focus. ## Test plan - [x] `cargo run -- hook pre-merge --yes` (3413 tests pass before the merge of `origin/main`) - [x] 1071 lib + 607 bin + 1588 integration tests pass after merging `origin/main` - [x] `cargo check --all-targets` clean - [ ] CI green --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Merged
max-sixty
added a commit
that referenced
this pull request
May 3, 2026
Cuts v0.47.0. Highlights: - **Integration detection fix** across `wt list`, `wt remove`, `wt merge`, `wt step prune` for the local/upstream-diverged case (#2507, #2513, #2515). - **Faster shell-command dispatch** (~10ms per invocation, 1.49× on trivial aliases) via event-driven signal forwarding (#2537, #2538), plus parallel config load (#2543) and merged cold-start prewarm rev-parse (#2541). - **`wt switch <number>` suggests `pr:N` / `mr:N`** instead of just `--create` (#2516). - **Library API breaking changes**: `RefSnapshot` cutover (#2528, #2530) and the `for-each` direct-exec change (#2465). Full list in `CHANGELOG.md`. See `CHANGELOG.md` for the complete entry. > _This was written by Claude Code on behalf of @max-sixty_ --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wt list's integration column now agrees with the safety path (wt remove/wt merge) in the local/upstream-diverged case introduced by fix(integration): OR over local + upstream for integration detection #2507. A branch merged into localmainwhileorigin/mainhas unique commits no longer renders as unintegrated.Repository::integration_targets()returns a(primary, optional secondary)pair that mirrorscompute_integration_reason_uncached's preamble: a single ref for same-commit / strict-subset cases, both refs only when local and upstream have diverged.IsAncestor,CommittedTreesMatch,HasFileChanges,WouldMergeAdd) combines signals across the pair — OR for positive signals (ancestor, trees match, patch-id), AND for inverted ones — and short-circuits when the primary alone proves integration, so the common one-sided case stays one git op.effective_integration_targetis still used by thestep prunepath; it's the column that needed the OR semantics.Test plan
test_list_integrated_when_merged_locally_with_upstream_divergedmirrorstest_remove_merged_locally_when_upstream_diverged. Verified to fail without the fix (rendersmain_state == "behind") and pass with it.test_list_integrated_when_squash_merged_on_remote_with_local_divergedcovers the merged-on-remote direction.cargo run -- hook pre-merge --yes— 3407/3407 pass, no snapshots to review.🤖 Generated with Claude Code