Repository navigation
refactor(switch): pin the picker alt-r keep path to BranchOnly - #3228
Merged
Merged
Conversation
Follow-ups from #3211's up-front removability prediction. `keep_unremovable_row` took the whole `RemoveResult` and re-matched for `BranchOnly`, silently no-oping the impossible `RemovedWorktree` arm. It now takes `branch_name: &str`, so the keep path is unrepresentable for a worktree result; `invoke` destructures the branch and `debug_assert!`s the unreachable variant (a `RemovedWorktree` always removes, so it never reaches the keep path). Also documents the overlapping reposition-chains tradeoff in `send_reposition`: rapid alt-r leaves several self-terminating chains in flight, last-to-run wins, and the cursor self-corrects on the next render — not worth a cross-chain generation token. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The type narrowing of `keep_unremovable_row` to `&str` already makes a `RemovedWorktree` unrepresentable on the keep path, and the tested `removal_will_remove_target` truth table pins that a worktree always removes. A `debug_assert!(false)` for that case was belt-and-suspenders and an uncovered line; let the impossible branch fall through (a kept row is data-safe regardless). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
The refactor is sound — removal_will_remove_target returns true for every RemovedWorktree, so the non-removing else can only be a BranchOnly, and narrowing keep_unremovable_row to take branch_name: &str makes the keep path unrepresentable for a worktree result. Nice.
One small gap: the PR body says invoke "debug_assert!s the unreachable variant," but there's no assert in the diff — the impossible RemovedWorktree-reaching-the-else case silently no-ops (the else if let just doesn't match). That preserves the old behavior, but doesn't deliver the safety the body describes. Either add the assert (suggested inline) or drop the claim from the description.
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.
Two review follow-ups from #3211 (the picker's up-front alt-r removability prediction), no behavior change.
keep_unremovable_rowtook the wholeRemoveResultand re-matched forBranchOnly, silently no-oping the impossibleRemovedWorktreearm. It now takesbranch_name: &str, so the keep path is unrepresentable for a worktree result, andinvokedestructures the branch in the keep arm. The invariant that only aBranchOnlyrow reaches that arm is already pinned byremoval_will_remove_target's tested truth table — everyRemovedWorktreereturnstrue, so the non-removing branch can only beBranchOnly. The impossible case therefore needs no runtime guard: anelse { debug_assert!(false) }would duplicate that guarantee (belt-and-suspenders) and add a permanently-uncovered line, so it's left out.The second change is doc-only: it records the overlapping reposition-chains tradeoff in
send_reposition. Rapid alt-r leaves several self-terminating chains in flight; the last to run wins, and the cursor self-corrects on the next render. Pinning this to only the newest reposition would mean threading a generation token through every chain and everyPickerCollectorconstruction site — not worth it for a self-correcting cosmetic transient.