Repository navigation
perf(list): skip redundant MergeTreeConflicts on dirty worktrees - #2602
Conversation
For dirty worktrees, WorkingTreeConflicts already runs `git merge-tree` against a tree that includes HEAD plus uncommitted changes. The HEAD-only MergeTreeConflicts probe was duplicating that work for the same row. MergeTreeConflictsTask now peeks the shared porcelain cache and short- circuits with a sentinel value when the worktree is dirty without unmerged entries. tier_would_conflict treats Some(Some(_)) as authoritative — the dirty-tree result reflects the user's current state and is the right answer for "would conflict?" anyway. Drops one merge-tree subprocess per dirty worktree row in `wt list`. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Optimization is sound: both probes read from the shared status_porcelain_cached OnceCell, so they always agree on the dirty-without-unmerged predicate, and the unreachable!() arm in tier_would_conflict for (Some(_), Some(Some(_))) is genuinely unreachable in production. Docstrings clearly state the new authoritative-WT contract.
One small gap: the test suite verifies WT(Some(Some(false))) rules out alongside HEAD(None) and HEAD(Some(false)), but not alongside HEAD(Some(true)) — the case that most directly demonstrates the new "WT wins over HEAD" semantics. Worth pinning down in case a future refactor reorders the matches.
|
codecov/patch is failing on line 353 — the A single tuple match makes the function exhaustive without any pub fn tier_would_conflict(
has_merge_tree_conflicts: Option<bool>,
has_working_tree_conflicts: Option<Option<bool>>,
) -> Tier<MainState> {
use Tier::*;
match (has_merge_tree_conflicts, has_working_tree_conflicts) {
// WT probe is authoritative when it has a dirty-tree result.
(_, Some(Some(true))) => Fired(MainState::WouldConflict),
(_, Some(Some(false))) => RuledOut,
// Otherwise consult HEAD probe.
(Some(true), _) => Fired(MainState::WouldConflict),
(Some(false), Some(None)) => RuledOut,
// HEAD says "no conflict" but WT hasn't reported — wait.
(Some(false), None) => Wait,
(None, _) => Wait,
}
}Happy to push this if you want — let me know. |
Removes the `unreachable!()` arm (which codecov/patch correctly flagged as uncovered — it's unreachable in production but contributes a coverage gap) by making the predicate exhaustive over `(merge_tree, working_tree)` in a single match. Also pins the `(Some(true), Some(Some(false)))` case where the WT probe overrides a positive HEAD probe — the strongest demonstration of WT-authoritative behavior, and the case that would silently regress if someone reordered the arms. Co-Authored-By: Claude <[email protected]>
|
Pushed
Walked all ten input shapes against both implementations to confirm semantic equivalence.
|
## Summary Release v0.48.0. See [CHANGELOG.md](https://github.com/max-sixty/worktrunk/blob/release/CHANGELOG.md) for the full notes. Highlights: - `--format=json` extends to seven step + hook commands (#2560) - `wt step commit` / `wt step squash` gain `--dry-run` (#2557) - New `dirname` / `basename` template filters (#2592, #2605) - New `[remove] delete-branch` config option (#2589) - `wt-perf timeline` subcommand (#2558) - Faster `wt list` on dirty worktrees (#2602) and faster alias dispatch (#2556, #2573) - Short-SHA display honors `core.abbrev` (#2576) - Cleaner `wt config show` shell-integration section for new users ## Test plan - [x] `cargo run -- hook pre-merge --yes` (3497 tests, lints clean) - [x] `cargo semver-checks check-release -p worktrunk` consulted; minor bump confirmed - [ ] CI green
Summary
WorkingTreeConflictsalready runsgit merge-treeagainst a tree that includes HEAD + uncommitted changes;MergeTreeConflictswas duplicating that work against HEAD alone.MergeTreeConflictsTasknow peeks the shared porcelain cache and short-circuits with a sentinelfalsewhen the worktree is dirty without unmerged entries.tier_would_conflictnow treatsSome(Some(_))as authoritative — the dirty-tree probe wins regardless of the HEAD probe. This is the answer most users want for "would this merge conflict?" anyway, since the dirty tree reflects the current working state.Implementation notes
test_list_warns_when_commit_details_batch_fails— the corrupt-HEAD repro now surfacesmerge-tree-conflicts (fatal: bad object HEAD)from the early porcelain check instead of the deepermerge-base failedmessage. Same severity; same diagnostic value.Test plan
cargo run -- hook pre-merge --yes(full lints + 3484 tests) passesRUST_LOG=worktrunk=debugthat exactly one merge-tree subprocess fires per dirty row (theWorkingTreeConflictsephemeral-commit one), down from twotest_list_working_tree_conflictsandtest_list_full_clean_working_tree_uses_commit_conflictsboth pass —✗symbol still renders correctly for dirty conflicts; clean conflicts still detected via HEAD probetier_would_conflictunit tests cover the new short-circuit and the "skipped HEAD probe" path