Skip to content

fix: resolve worktrees whose recorded gitdir path exists on the host#13

Merged
rosstaco merged 1 commit into
mainfrom
fix/worktree-foreign-gitdir-on-host
Jun 24, 2026
Merged

fix: resolve worktrees whose recorded gitdir path exists on the host#13
rosstaco merged 1 commit into
mainfrom
fix/worktree-foreign-gitdir-on-host

Conversation

@rosstaco

@rosstaco rosstaco commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Problem

idc doctor reported a valid git worktree as an unsupported external worktree on a WSL remote:

⚠ worktree: /home/user/repos/repo/.worktrees/wt-1 looks like a worktree or submodule but cannot be resolved (external worktree or submodule)

Root cause

A worktree created inside a devcontainer records a container-absolute path in its .git file:

gitdir: /workspaces/repo/.worktrees/wt-1

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-spendster happened to exist as an unrelated directory, so:

  • main_repo.is_dir() returned True → the local-filesystem fallback was skipped
  • target.relative_to(main_repo) then raised ValueError
  • → the worktree was rejected as "external"

Fix

Locate the owning repository on the local filesystem first (walk up from the worktree), and trust the recorded gitdir path 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

  • New regression test test_resolves_worktree_when_foreign_gitdir_path_exists_on_host reproduces the exact WSL failure — fails on old code, passes on new.
  • Full suite: 348 passed; ruff clean.

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>
@rosstaco rosstaco merged commit 357a186 into main Jun 24, 2026
3 checks passed
@rosstaco rosstaco deleted the fix/worktree-foreign-gitdir-on-host branch June 24, 2026 04:00
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.

1 participant