Skip to content

Detect worktrees outside search roots via git worktree list - #30

Merged
seankearon merged 2 commits into
mainfrom
claude/fido-worktree-detection-copy-lveo9o
Jul 28, 2026
Merged

Detect worktrees outside search roots via git worktree list#30
seankearon merged 2 commits into
mainfrom
claude/fido-worktree-detection-copy-lveo9o

Conversation

@seankearon

Copy link
Copy Markdown
Owner

Summary

This PR fixes discovery of git worktrees that exist outside configured search roots by querying git directly (git worktree list) instead of relying solely on folder scanning. It also adds a UI feature to copy the selected working-tree path to the clipboard.

Key Changes

Discovery Logic (OpenerService.cs)

  • Changed from scanning folders and checking if each is a worktree to asking git for all worktrees of each discovered clone
  • Replaced Dictionary<string, string> with HashSet<string> for clone deduplication, since we now enumerate worktrees per clone rather than per scanned folder
  • Added seenPaths deduplication to prevent duplicate targets when the same worktree is discovered multiple times
  • Now uses git worktree list to get authoritative worktree information, including those outside search roots (central directories, nested past SearchDepth, or inside the main clone)
  • Worktrees are correctly identified as main clones or linked worktrees via git's response rather than filesystem checks

UI Enhancements (MainWindow.axaml and MainWindow.axaml.cs)

  • Added a copy-to-clipboard button in the OPEN strip next to the selected path
  • Implemented CopySelectedPathAsync() method with error handling and flight log narration
  • Added tooltips to ellipsised path displays (card and strip) showing the full path
  • Added styling for the new copy button with hover effects

Tests

  • Added CopyPathTests.cs with end-to-end test for clipboard functionality
  • Added OpenerServiceTests.cs test verifying worktrees outside search roots are discovered
  • Added MultipleWorktreesTests.cs regression test ensuring external worktrees are offered to open rather than triggering a "create new worktree" placement card

Notable Implementation Details

  • The fix prevents the error scenario where git rejects worktree creation with "<branch> is already used by worktree at …" by detecting existing checkouts via git worktree list
  • Deduplication is now two-level: by clone (to avoid re-querying git for the same clone) and by worktree path (to handle cases where the scan surfaces the same worktree multiple times)
  • The copy-to-clipboard feature is best-effort with graceful degradation if the clipboard is unavailable
  • All path operations use Path.GetFullPath() for consistent comparison and display

https://claude.ai/code/session_01MyhgL1kgHpvgYJQLvePuWy

claude added 2 commits July 28, 2026 11:21
Discovery recognised a branch's checkout only where the working-tree
folder itself sat under a configured search root, so a worktree kept in
a central directory, nested past the scan depth, or created inside the
main clone went unseen. Fido then offered to *create* a new worktree,
which git rejected with "'<branch>' is already used by worktree at …".

DiscoverTargetsAsync now asks git itself — `git worktree list` — for
each scanned clone's worktrees, matching on the reported branch, so any
checkout of the branch is surfaced as an openable worktree/main-clone
card wherever it lives on disk. The filesystem scan is still what
reaches each clone; git is what enumerates its worktrees. Dedup by main
path (per clone) and by full worktree path (across clones) keeps a
worktree that is both under the search root and git-registered from
appearing twice.

Also make the selected working-tree path copyable: a copy button in the
OPEN strip puts it on the clipboard (narrated in the flight log), and
the ellipsised card/strip paths carry a full-path tooltip.

Tests: a service-level test and an end-to-end test prove a worktree
outside the search roots is offered to open (not recreated); a test
covers the clipboard copy.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MyhgL1kgHpvgYJQLvePuWy
The copy button lived in a horizontal StackPanel beside the path chip,
with a fixed MaxWidth=380 on the chip. A horizontal StackPanel measures
its children with infinite width, so the chip measured at a fixed 380px
regardless of the column's real width — and as the window was resized
toward its 560px minimum the chip plus button overflowed the star
column and painted over the kind label on the right.

Put the chip back directly in the star column (so it ellipsises to the
width actually available and never overflows) and group the copy button
with the kind label in the trailing Auto column. The button keeps its
tooltip and flight-log confirmation; only its position changed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MyhgL1kgHpvgYJQLvePuWy
@seankearon
seankearon merged commit f854a9e into main Jul 28, 2026
2 checks passed
@seankearon
seankearon deleted the claude/fido-worktree-detection-copy-lveo9o branch July 28, 2026 17:38
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