Skip to content

Convert placement cards to real checkouts after branch placement - #28

Merged
seankearon merged 1 commit into
mainfrom
claude/fido-worktree-git-error-on12ox
Jul 23, 2026
Merged

Convert placement cards to real checkouts after branch placement#28
seankearon merged 1 commit into
mainfrom
claude/fido-worktree-git-error-on12ox

Conversation

@seankearon

Copy link
Copy Markdown
Owner

Summary

Fixes a regression where opening a second tool on a freshly placed branch would fail. When a user opened a new worktree placement card with one editor (e.g., Console) and then tried to open it again with another editor (e.g., Rider), the second click would attempt to re-add the same branch to git, which would fail because the branch was already checked out in the worktree created by the first click.

Changes

  • MainWindow.axaml.cs: After successfully creating a worktree or switching the main clone to a branch, immediately convert the placement card to a real checkout card via the new MaterialisePlacementAsync() method. This ensures subsequent tool clicks open the existing folder instead of attempting to place the branch again.

  • MainWindowViewModel.cs: Added ReplaceTarget() method to swap a placement card for the real checkout it became. A NewWorktree card becomes a Worktree card (now deletable), and a SwitchMainClone card becomes a MainClone card. Selection follows the swapped card to keep the just-opened target current.

  • Tests: Added comprehensive regression test Opening_a_second_tool_reuses_the_created_worktree_instead_of_re_adding_it() that verifies:

    • Opening a console on a new worktree placement card creates the worktree
    • The card converts to a real, deletable worktree
    • Opening Rider on the same card reuses the existing worktree without git errors
    • No duplicate worktree ("-2") is created
    • Discovery still reports exactly one worktree for the branch

Implementation Details

The MaterialisePlacementAsync() method:

  • Captures the folder path and last-write timestamp of the newly placed branch
  • Re-globs solutions from the tree that now exists (rather than using the preview from the clone)
  • Creates a new DiscoveredTarget with the correct Kind and updated metadata
  • Replaces the card in the view model while preserving selection state

https://claude.ai/code/session_01QSKHusKNU5w1zMeWfj2wjc

Opening a new-worktree placement card created the worktree and launched
into it, but left the card labelled "new worktree". A second tool click
(e.g. open a Console, then open Rider) therefore ran `git worktree add`
for the same branch again, which git rejects — the branch is now checked
out in the worktree the first click created — surfacing as
"git worktree add failed".

Placing a branch now converts the card in place to the real checkout it
became: a created worktree becomes a deletable Worktree target, a
switched clone becomes a MainClone target, with solutions re-globbed from
the tree that now exists. Subsequent opens launch that folder directly.
The conversion happens as soon as the placement succeeds (before the
launch, which may fail to locate the editor), so the card can never fall
back into trying to place the branch a second time.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSKHusKNU5w1zMeWfj2wjc
@seankearon
seankearon merged commit 47d4cca into main Jul 23, 2026
2 checks passed
@seankearon
seankearon deleted the claude/fido-worktree-git-error-on12ox branch July 28, 2026 17:39
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