fix: worktree-aware checkout guard, visible error toasts, worktree force-remove (DAN-12)#36
Merged
Merged
Conversation
git2 only rejects the HEAD move at set_head — after checkout_tree has already rewritten the workdir and index — leaving the repo half-switched and every later safe checkout failing with phantom conflicts (DAN-12). Check the worktree registry up front like git switch does, and roll back the tree diff if set_head still fails after a checkout.
git requires -f -f to remove a locked worktree; a single --force already implies discarding changes, so there is no middle step worth exposing.
…N-12) - Toasts get an error variant (red x, longer display) — failures no longer flash by with a green success check, which read as the app doing nothing. - Sidebar branch ops surfaced nothing on failure (console.warn only); they now raise an error toast. - Branch rows in the topbar switcher and sidebar badge branches that are HEAD of another worktree and open that worktree's tab instead of attempting a checkout that is guaranteed to fail. - Worktrees overview: a remove that git refuses (dirty/locked) arms an explicit Force remove / Cancel pair on the row instead of dead-ending.
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
Fixes DAN-12 — "Can not do checkout of branches nor commits" when worktrees are in use, plus the invisible worktree-remove failures.
Root cause:
checkout_branchrancheckout_tree(rewriting workdir + index) beforeset_head, and libgit2 refusesset_headonto a branch that is HEAD of a linked worktree. The repo was left half-switched — HEAD on the old branch, files on the new one — and every later safe checkout (any branch or commit) failed with phantomconflicts prevent checkouterrors until a terminal reset.checkout_branchnow rejects a worktree-occupied branch up front (same rule asgit switch), naming the worktree path; ifset_headstill fails post-checkout, the workdir/index roll back scoped to the tree diff so carried-over local changes are never clobbered.--force --forceso locked worktrees work too.Test plan
cargo test -p strand-core— 97 passed, including new regression testcheckout_refuses_branch_of_linked_worktree_without_touching_workdircargo clippy -p strand-core,cargo check -p strand-tauri— cleanpnpm run lint(tsc) — clean🤖 Generated with Claude Code