Repository navigation
fix(git): enable Windows long paths for worktree creation (local, sparse, and SSH hosts) - #15866
Conversation
…H hosts Builds on @hwantage's fix: `git -c core.longpaths=true` only helped the plain `worktree add`, so two deep-path cases still failed with "Filename too long". - Sparse creation: `worktree add --no-checkout` writes no files, so the flag now also rides the `sparse-checkout set` and `checkout <branch>` calls that actually materialize the tree. Without it the failure landed after the worktree existed and rolled the whole create back. - SSH: relay addWorktreeOp builds its own argv, so a Windows SSH host was never covered. It now keys off the execution host's platform, not the client's, and the hardcoded --no-checkout splice index is offset by the prefix. - Predicate is now the cwd (`\\wsl.localhost\...` opts out) rather than the wslDistro option, which is not what decides which git binary runs. Scope stays command-level `-c`; no user, repo, or system config is written.
📝 WalkthroughWalkthroughThe change adds 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shared/windows-long-path-git-args.ts (1)
5-16: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense this comment block.
Keep only the non-obvious command-scope and WSL UNC rationale. The detailed version history and repeated explanation make this helper harder to scan.
As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 01b805da-519d-46be-9e17-35c8cc5f171e
📒 Files selected for processing (7)
src/main/git/add-sparse-worktree.test.tssrc/main/git/worktree-add-creation-config.test.tssrc/main/git/worktree.tssrc/relay/git-handler-worktree-ops.test.tssrc/relay/git-handler-worktree-ops.tssrc/shared/windows-long-path-git-args.test.tssrc/shared/windows-long-path-git-args.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
…rse, and SSH hosts) (stablyai#15866) Co-authored-by: hwantage <[email protected]> (cherry picked from commit 202d74a)
…rse, and SSH hosts) (stablyai#15866) Co-authored-by: hwantage <[email protected]>
Four clusters, all introduced by the origin/main merge: - config/scripts/vitest-host-ports-setup.ts left 28 suites failing on rmSync EPERM. POSIX lets an open file be unlinked; Windows does not, and a suite that keeps an OrchestrationDb open owns a handle in that scratch dir. Scratch cleanup under tmpdir must not fail a suite that passed. - core.longpaths=true (stablyai#15866) is prefixed to worktree add on Windows, so argv literals in three suites could only be right on one platform; they now derive the prefix from windowsLongPathGitArgs. - status-submodule-path-cache matched argv[0] for the subcommand, which is '-c' once that prefix is there. - The new Hermes skills-root cases used drive-less path literals; the file already has a VOLUME constant for exactly that. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01R3oGCiyWVfKj1DXK2hTFTH
…rse, and SSH hosts) (stablyai#15866) Co-authored-by: hwantage <[email protected]>
…rse, and SSH hosts) (stablyai#15866) Co-authored-by: hwantage <[email protected]>
Supersedes #15786 by @hwantage — carried over so it can run full CI (fork PRs only run
track-community-prin this repo). Original authorship is preserved in the first commit; the second commit adds the maintainer fixes described below.ELI5
Windows refuses to create files whose full path is longer than 260 characters unless a program explicitly asks for the long-path behavior. Orca creates worktrees in nested directories, so a repo with deep folder names blows past that limit and
git worktree adddies with "Filename too long". Git has a switch for this (core.longpaths), and we now flip it for just the commands Orca runs — not by editing anyone's Git config — on the Windows worktree-creation paths Orca controls end to end: normal local creation, local sparse creation, and plain (non-sparse) creation on a remote Windows SSH host. Sparse creation over SSH is not covered — see "Known limitations" below.What Changed
src/shared/windows-long-path-git-args.ts: returns['-c', 'core.longpaths=true']for a Windows cwd,[]otherwise. Platform is an injectable parameter (matchingisWindowsLongPathWorktreeRemovalErrorandisWslLinkedWorktreeGitRoutingCandidate).src/main/git/worktree.tsperformAddWorktreeprefixes theworktree addargv (this is @hwantage's original fix, refactored onto the shared helper).addSparseWorktreenow also prefixessparse-checkout setandcheckout <branch>.src/relay/git-handler-worktree-ops.ts:addWorktreeOptakes an injectableplatform(defaulting to the relay host'sprocess.platform) and prefixes both argv branches. The hardcodedargs.splice(3, 0, '--no-checkout')is now offset by the prefix length.--no-checkoutposition.Why
Root cause: Git for Windows aborts a checkout whose path exceeds
MAX_PATHwith "Filename too long" unlesscore.longpathsis enabled. Orca never set it.Three things needed fixing beyond the original one-liner:
addSparseWorktreecallsaddWorktreewithnoCheckout=true, so the flag decorated aworktree add --no-checkoutthat writes zero files. The commands that actually materialize the tree —sparse-checkout setandcheckout <branch>— ran without it. Worse, that failure happens aftercreated = true, so it fell into the rollback path and removed the worktree, presenting as a mysterious transient create failure.ssh-git-provider.addWorktree→ relaygit.addWorktree→addWorktreeOp, which builds its own argv.worktree.tscarries an explicit "SSH parity: relay'saddWorktreeOpmirrors this — change both in lockstep" comment, and the relay demonstrably supports Windows hosts (isWindowsAbsolutePathin the same file). The client'sprocess.platformis also the wrong process to ask here: only the execution host's OS matters.!options.wslDistrois not the routing predicate.resolveGitCommandcan return native host git for a WSL-linked worktree with aC:\...cwd even whenwslDistrois set (runner.ts:446-449) — suppressing the flag in a genuinely MAX_PATH-prone case. Conversely a\\wsl.localhost\...cwd routes to WSL git even withwslDistroundefined. The predicate is now the cwd: apply onwin32unless the path is a WSL UNC path.Scope is deliberately command-level.
git -c key=valueapplies to that invocation only — never--global,--system, or--local— so no user or repo config is mutated. Both-candcore.longpathspredate Git 1.9, well under the repo's 2.25 baseline, so noGitCapabilityCacheentry or fallback is needed; a non-Windows Git parses and ignores the key (verified against Git 2.44 locally).Known limitations / follow-ups
createRemoteWorktreematerializes the sparse tree withprovider.exec(['sparse-checkout', 'init', '--cone']),provider.exec(['sparse-checkout', 'set', ...])andprovider.exec(['checkout', <branch>])(src/main/ipc/worktree-remote.ts:1780-1782). Those go through the relay's genericgit.execRPC, which (a) rejects any global option before the subcommand (git-exec-validator.ts:154-162, "Global git flags before the subcommand are not allowed") and (b) does not allowlistsparse-checkoutorcheckoutat all (ALLOWED_GIT_SUBCOMMANDS,git-exec-validator.ts:17-33). Prefixing that argv would therefore not just fail to help, it would be rejected — covering it needs a narrow relay RPC (like the existinggit.addWorktree), which is a security-reviewable change well beyond this PR's scope. Note this is not a regression from this PR: the relay has nosparse-checkoutsupport today at all, so the remote sparse path is already blocked by the allowlist before MAX_PATH ever comes up.core.longpaths=trueclears the "Filename too long" checkout error but Git then dies withfatal: '$GIT_DIR' too big—setup_explicit_git_dir()hard-checks$GIT_DIR(<worktree>/.git) againstPATH_MAX - 40, and MinGW'sPATH_MAXis 260. Measured cutoff: root length 215 succeeds, 216 fails. Not a regression (a 230-char root fails pre-fix too), and not fixable from Orca — it needs an upstream Git change. This fix targets the common shape instead: a short worktree root whose checked-out files exceed MAX_PATH.isWindowsLongPathWorktreeRemovalError+\\?\-prefixed removal).Linked Issue
Fixes #15785
Visual Proof
N/A— no UI, renderer, or user-visible surface changes. This only alters the argv of Git subprocesses.Testing
Real Windows hardware verification (2026-08-22)
Host
awin— Windows, Git Bash (MINGW64),git version 2.55.0.windows.3. Repo checked out atC:/Users/neil/orca/orca. Baseline config check first, so nothing masked the bug:1. Original failure reproduced. Scratch repo
C:\Users\neil\lp-test\src, worktree target 276 chars:2. The fix resolves the real-world shape — short worktree root, tracked files that push past MAX_PATH (241-char relative path, 267 chars absolute):
3. Sparse path — claim #1 in "Why" confirmed on hardware. Replaying
addSparseWorktree's exact command sequence, the failing call ischeckout <branch>, exactly as argued:(
sparse-checkout init --coneneeds no prefix in practice: the worktree is always created--no-checkout, so there is no working tree for it to materialize. Exit 0 both times.)4. Config scope verified on hardware — nothing leaked. After every command above:
5. Relay argv ordering validated against real Git for Windows. The
--no-checkoutsplice offset produces a command real Git accepts, in bothaddWorktreeOpbranches:(An earlier revision of this section quoted the operands as
--no-checkout --no-track; that ordering is also accepted by Git but is not what the code produces. The block above is the produced argv, dumped fromaddWorktreeOpwith a capturingGitExecand then run verbatim onawin.)New finding — hard ceiling on worktree root path length, independent of this fix.
core.longpathsdoes not make arbitrarily deep worktree roots work. Git for Windows'setup_explicit_git_dir()dies when$GIT_DIR(=<worktree>/.git) exceedsPATH_MAX - 40, and MinGW'sPATH_MAXis 260. Measured boundary, all runs with-c core.longpaths=true:This wall is not introduced by the PR — a 230-char root fails pre-fix too (exit 128,
fatal: could not create directory of '.git/worktrees/<basename>'...: Filename too long; the exact path in the message shifts with the source repo's own path length). It is captured under "Known limitations". For scale on this host: Orca's own deepest tracked path is 117 chars and the worktree baseC:/Users/neil/orca/workspaces/orca/is 35, so Orca-on-Orca stays well inside both limits; the fix matters for user repos with deeper trees.Not verified on hardware: SSH creation against a Windows execution host.
awinruns no sshd (Get-Service sshdreturns nothing, 0 listeners on port 22) and Orca has no Windows SSH host registered (orca host listshows only a Linux SSH target), soaddWorktreeOp's Windows branch could not be exercised end to end — only its argv was validated against real Git for Windows (item 5). The remote sparse limitation was confirmed by code inspection only (sparse-checkout/checkoutabsent fromALLOWED_GIT_SUBCOMMANDS;validateGitExecArgsrejects any pre-subcommand global flag), not by an RPC round trip.Independent re-verification (second pass, 2026-08-22)
Everything above was re-run from scratch in a fresh scratch tree (
C:\Users\neil\lpv, since deleted) onawin(git version 2.55.0.windows.3), plus a real Linux SSH host (openclaw,git version 2.43.0). Results:Sparse sequence replayed verbatim, both ways:
Root-path ceiling re-measured independently against a shallow repo, so only root length varies. Boundary reproduces exactly:
Non-Windows argv proven unchanged two ways, not just asserted:
addWorktreeOpwas driven with a capturingGitExecacross all 12 combinations ofplatform ∈ {win32, darwin, linux} × noCheckout × checkoutExistingBranch, at this PR's head and at the merge base (2b1254d). The 8 non-Windows rowsdiffclean — byte-identical.worktree-add-creation-config.test.ts,add-sparse-worktree.test.tsandgit-handler-worktree-ops.test.ts— which pin full argv strings on darwin — were checked out over this PR's production code and run:Test Files 3 passed (3) | Tests 32 passed (32).Linux SSH host (
openclaw,hostPlatform: linux): a worktree was created through the realssh-git-provider→ relaygit.addWorktreepath (succeeded), and afterwardsGLOBAL=[] SYSTEM=[] LOCAL=[] ORIGIN=[]. Linuxgit 2.43.0also accepts and ignores-c core.longpaths=true(LINUX_WITH_FLAG_EXIT=0,LINUX_NOFLAG_EXIT=0, config still empty after).The remote-sparse limitation is now confirmed by execution, not only inspection —
validateGitExecArgswas called directly with each argvcreateRemoteWorktreesends:Still not verified end to end, and correctly disclosed as such above: SSH creation against a Windows execution host. Re-checked on this pass —
awinreports nosshdservice and0listeners on port 22, andorca host liststill shows exactly one SSH target, which is Linux.Local (macOS)
Regression proof — with the two product files (
src/main/git/worktree.ts,src/relay/git-handler-worktree-ops.ts) stashed back to @hwantage's original commit, 4 of the new tests fail and pass again once restored:Note on the pre-existing suites:
worktree-add-creation-config.test.tsandadd-sparse-worktree.test.tsassert exact argv, which now depends on the host OS. Both suites pinprocess.platformtodarwininbeforeEach, so they no longer silently fail for a maintainer running vitest on Windows (CI unit shards areubuntu-latestand would have hidden that). The relay suite passesplatformexplicitly for the same reason.Not run locally per repo policy for concurrent agents:
pnpm typecheck, fullpnpm lint,pnpm build. CI covers these.Review
win32;darwin/linuxargv is byte-identical to before, asserted explicitly. No hardcoded path separators or modifier keys involved. WSL UNC paths (\\wsl.localhost\...,\\wsl$\...) opt out viaparseWslUncPath, which is the platform-agnostic parser (theparseWslPathwrapper reads ambientprocess.platformand would defeat injection).docs/reference/ssh-execution-boundary.md. This covers plain remote creation only; the remote sparse path is out of reach from here (see Known limitations). No wire change: no RPC params, stream opcodes, or published content are altered — the fix is host-local argv construction, so mixed client/host versions are unaffected in both directions (docs/reference/remote-wire-compatibility.md).git -cexportsGIT_CONFIG_PARAMETERSto child processes, so apost-checkouthook inheritscore.longpaths=truefor that one invocation. That is documented Git behavior and not a privilege change. Telemetry still classifies the span correctly —-cis already inGIT_GLOBAL_OPTIONS_WITH_OPERAND(src/main/observability/instrumentation.ts:34), andfindSubcommandIndexinwsl-direct-git-read-commands.ts:58already skips-cwhen detecting subcommands, so WSL direct-read routing is unaffected. Folder workspaces are unaffected (this is worktree-creation-only). Provider-neutral: no GitHub/GitLab surface touched.-cis command-scope only; nogit config --global/--system/--localwrite is introduced, so no user config is mutated. Values are literal constants passed as separate argv elements through the existingexecFile-style path — no shell interpolation, and the relay's leading--branch/base guard is untouched. The--no-checkoutsplice offset was the one real injection-adjacent risk (a wrong index would silently reorder the command); it is pinned by a test.f269bf21in full (2 files, +42/-1). It adds two literal argv strings and two unit tests. No network calls, nochild_process/eval, no env or credential reads, no config writes, no dependency/lockfile/CI/workflow/entitlement changes, no obfuscation (diff is 100% ASCII), and no instruction-shaped text planted in comments or tests. Nothing malicious found.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance — all covered in Review above. Mobile is unaffected (main/relay process code only).
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)