fix: resolve worktrees whose recorded gitdir path exists on the host#13
Merged
Conversation
A worktree created inside a devcontainer records a container-absolute path in its .git file (e.g. gitdir: /workspaces/<repo>/.git/worktrees/<n>). resolve_worktree() derived the main repo from that path and only walked the local filesystem when the derived path did not exist. On WSL (and similar hosts) that /workspaces/... path can actually exist as an unrelated directory, so the fallback was skipped, target.relative_to raised, and idc reported the worktree as an unsupported "external worktree". Locate the owning repository on the local filesystem first by walking up from the worktree, and trust the recorded gitdir path only as a fallback when no local ancestor repository is found. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Problem
idc doctorreported a valid git worktree as an unsupported external worktree on a WSL remote:Root cause
A worktree created inside a devcontainer records a container-absolute path in its
.gitfile:resolve_worktree()derived the main repo from that recorded path and only walked the local filesystem when the derived path didn't exist. On WSL,/workspaces/agent-spendsterhappened to exist as an unrelated directory, so:main_repo.is_dir()returnedTrue→ the local-filesystem fallback was skippedtarget.relative_to(main_repo)then raisedValueErrorFix
Locate the owning repository on the local filesystem first (walk up from the worktree), and trust the recorded
gitdirpath only as a fallback when no local ancestor repository is found. The recorded path can't be trusted — it may be foreign (a container path) or even coincidentally present as an unrelated directory.Tests
test_resolves_worktree_when_foreign_gitdir_path_exists_on_hostreproduces the exact WSL failure — fails on old code, passes on new.ruffclean.