fix(git): Windows drive-letter paths and worktree reuse in ensure_worktree (swamp-club #3521) #510
Loading…
Reference in a new issue
No description provided.
Delete branch "3521"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes swamp-club #3521.
Problem
@swamp/githandled worktree and local-remote paths as POSIX strings. On Windows:ensure_worktreewithpath: C:/repos/factory/work/ITEMtreated the drive-letter path as relative and created the worktree under<cwd>/C:/....ensure_worktreefor an existing worktree failed with<path> is outside the worktree root <root>: once the directory existed,realPathSyncreturned a backslash path that never matched the forward-slash root prefix.C:/...listing, so they were effectively off.Fix
git/extensions/models/_lib/paths.ts:absolutePath,canonicalPath,samePath,isWithin, built on@std/path/windowson Windows. Drive-letter, backslash and drive-less paths resolve correctly, and every comparison folds case and separator. The platform rules are injectable (setPathFlavor), so the Windows behaviour is tested on macOS/Linux.operations.ts: every worktree path comparison and current-directory base goes through the new module. That coversensure_worktree,verify_worktree,remove_worktree,readLayout, therequireCleanPrimarynested filter and theensure_checkouttop-level check.absolutePathkeeps the previous join, so..is still resolved by the kernel.Related fixes, same root cause
normaliseRemoteon Windows no longer readsC:/repoas an scp-style hostc.file:///C:/...decodes to a Windows path, and a malformed escape is kept as-is, as on POSIX...guard on worktreepath/rootalso splits on backslashes (a\..\b).Testing
paths_test.ts: the issue's exactcanonicalPathcases with cwdC:\repos\factory, the reuse root check, separator/case folding,\\?\prefix, drive root, symlinked ancestor, UNC, plus POSIX tests that pin the current behaviour.git_test.ts: WindowsnormaliseRemote, rejection of a backslash..,readLayout+assertPlacementover a mockedC:/worktree list (reuse passes, the safety checks still refuse), andremove_worktreeacross spellings.7280d23; the attestation is posted.Caveat: there is no Windows CI runner, so Windows behaviour is exercised only through the injected Windows rules. We'll ask the reporter to confirm on Windows 11 after release.
Manifest bumped to
2026.10.16.1.🤖 Generated with Claude Code