Repository navigation
feat(worktrees): support project-level .worktreeinclude (literal paths) for copying gitignored files into worktrees - #9791
Conversation
…orktrees Read .worktreeinclude at the repo root (gitignore syntax) and copy matching gitignored paths from the primary checkout into each newly created local worktree, so .env and other local config carry over with zero per-user setup. - Literal patterns resolve by direct stat; globs match against ls-files --others --ignored --exclude-standard --directory (collapsed dirs keep huge repos fast); every candidate is re-verified with check-ignore so tracked or unignored files are never copied. - Copy semantics, never symlink: APFS clone-copy on macOS, real copy elsewhere, so each worktree owns its files (unlike repo.symlinkPaths, which it merges with rather than replaces). - Failures never block worktree creation. - Remote (SSH) creation skips it, same as symlinkPaths. - Split APFS clone helpers into worktree-apfs-clone.ts (max-lines). Closes #7549
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 883743ee-f836-4a9c-b562-04446be8bf12
📒 Files selected for processing (9)
src/main/git/worktree-include-file.test.tssrc/main/git/worktree-include-file.tssrc/main/ipc/worktree-apfs-clone.tssrc/main/ipc/worktree-remote.tssrc/main/ipc/worktree-symlinks.test.tssrc/main/ipc/worktree-symlinks.tssrc/main/ipc/worktrees.test.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/git/worktree-include-file.ts (1)
68-93: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winMatch unanchored literals against any path segment
The fallback pathspec scan can return full nested paths likeapps/web/.env, so checking only the leaf segment still drops bare includes such asbuildunder ignored parents. Compare unanchored literals against every path segment instead ofat(-1).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 84e485ba-ff2c-4eb7-93d2-17271b01b592
📒 Files selected for processing (7)
src/main/git/worktree-include-file.test.tssrc/main/git/worktree-include-file.tssrc/main/git/worktree-include-glob.tssrc/main/ipc/worktree-apfs-clone.tssrc/main/ipc/worktree-symlinks.test.tssrc/main/ipc/worktree-symlinks.tssrc/shared/git-binary-compatibility.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/main/ipc/worktree-symlinks.test.ts
- src/main/git/worktree-include-file.test.ts
- src/main/ipc/worktree-symlinks.ts
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 3f349eeb-bbf8-4c6f-a5ed-6c83cbbee49a
📒 Files selected for processing (13)
src/main/git/check-ignored-paths.test.tssrc/main/git/check-ignored-paths.tssrc/main/git/worktree-include-file.test.tssrc/main/git/worktree-include-file.tssrc/main/git/worktree-include-flow.test.tssrc/main/git/worktree-include-glob.tssrc/main/git/worktree-include-pattern.tssrc/main/ipc/worktree-apfs-clone.tssrc/main/ipc/worktree-remote.tssrc/main/ipc/worktree-symlinks.test.tssrc/main/ipc/worktree-symlinks.tssrc/main/runtime/orca-runtime.tssrc/shared/git-binary-compatibility.test.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- src/main/runtime/orca-runtime.ts
- src/main/ipc/worktree-remote.ts
- src/main/git/worktree-include-glob.ts
- src/main/ipc/worktree-symlinks.test.ts
- src/main/ipc/worktree-symlinks.ts
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/main/git/worktree-include-flow.test.ts (1)
65-71: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMake the tracked-file assertion prove the copy contract.
mixed/tracked.txtalready exists because it was committed beforegit worktree add; reading it after copying cannot verify that copy materialization handled it. The exactincludePathsassertion already verifies tracked-path exclusion, so remove Line 71 or replace it with an assertion that isolates copy behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 3f4a96e4-c788-4e56-a293-cd52cf124c71
📒 Files selected for processing (11)
src/main/git/worktree-include-file.test.tssrc/main/git/worktree-include-file.tssrc/main/git/worktree-include-flow.test.tssrc/main/git/worktree-include-git-enumeration.test.tssrc/main/git/worktree-include-git-enumeration.tssrc/main/git/worktree-include-glob.tssrc/main/git/worktree-include-stat-concurrency.test.tssrc/main/ipc/worktree-remote.tssrc/main/ipc/worktree-symlinks.test.tssrc/main/ipc/worktree-symlinks.tssrc/main/ipc/worktrees.test.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- src/main/ipc/worktrees.test.ts
- src/main/ipc/worktree-remote.ts
- src/main/ipc/worktree-symlinks.test.ts
- src/main/git/worktree-include-file.test.ts
- src/main/ipc/worktree-symlinks.ts
…support-project-level-.worktreeinclude-f
…support-project-level-.worktreeinclude-f
…scope The reviewed implementation grew well past the ticket (#7549), which asks for a size-M feature that reuses existing worktree machinery. Trim back to the minimal change that solves the reported problem safely: - Resolver now supports literal files and directories only. Glob/negation lines are skipped with a warning (documented follow-up), which removes the entire user-controlled-regex ReDoS surface, the CPU/byte budgets, the git enumeration scan, and the case-sensitivity engine. The filesystem + git check-ignore handle existence and case for free. - Copy layer folded back into worktree-symlinks.ts (link/copy modes share one loop); dropped worktree-path-copy.ts, worktree-target-safety.ts, the descendant-dedup/realpath/target-parent machinery, and the per-materialization APFS filesystem cache. Kept the df/diskutil probe timeout. - Reverted unrelated changes: check-ignored-paths timeout param and the git-binary-compatibility enumeration tests. Net: -1903/+172 across the include+copy code. Behavior for the ticket's cases (.env, .env.local, .vscode/, node_modules, config/secrets.json) is unchanged; gitignored-only + copy-not-symlink semantics preserved. Closes #7549
…support-project-level-.worktreeinclude-f # Conflicts: # resources/skills/release-mapping.json
…e APFS volume probe Two issues found by review + perf audit of the copy path: - Correctness (HIGH): a listed entry that is itself a gitignored symlink was copied AS a symlink (fs.cp dereference:false), and the darwin APFS branch was skipped for all symlink sources. Editing the worktree's copy then wrote through to the shared/primary target — inverting copy-mode's 'each worktree owns its files' guarantee, and escaping the worktree entirely if the link pointed outside it. Now resolve realpath for a top-level symlink in copy mode so we copy content; nested symlinks inside a copied dir stay as-is (cp -R semantics). - Perf: assertSameApfsVolume ran df+diskutil per copied path (4 subprocesses each), so an N-entry include spawned ~4N short-lived processes on the macOS create hot path, all re-probing one volume. Add a per-materialization device-keyed cache: one probe per distinct volume (4N -> ~4). Tests: symlinked-file and symlinked-dir dereference regressions (no leak to primary); APFS volume probed once regardless of copied-path count.
Review + perf audit roundRan an adversarial code review and a Fixed
Documented as known limits (no code — kept the feature minimal)
Verified solid by review: gitignored-only filtering (tracked files never copied), resolver failure-isolation (never throws/blocks creation; bounded), double-layered path-traversal guards, remote/SSH correctly skipped, WSL git routing threaded, copy ordered after symlinks and before setup hooks. All gates green: typecheck, oxlint, oxfmt, max-lines ratchet, 1115 unit tests. |
A new worktree arrives with no env file, so the app cannot start until you hand-copy one across. `.worktreeinclude` asked for `.env.local` at the repo root, and no such file has ever existed here — this is a pnpm monorepo, and the env files live in the app packages. Each line of that file is a literal path anchored at the repo root ([stablyai/orca#9791](stablyai/orca#9791)), and a line that matches nothing is skipped without an error, so the root path quietly copied nothing every time. This lists the two paths that do exist: `apps/web/.env.local` and `apps/trip-planner/.env.local`. Both are gitignored by the existing `.env*.local` rule, which is the other condition the copier checks before it copies anything. A worktree created from here on opens with both env files already in place. Two things a reviewer might expect to see and won't. The copy runs at worktree-creation time, so the three worktrees that already exist keep their missing env files and still need a manual copy once. And `.claude/settings.local.json` stays as-is: it does not exist yet either, but Claude Code adds it to `.gitignore` the first time it writes the file, at which point the line starts working on its own.
|
Hi @brennanb2025, just curios of |
…s) for copying gitignored files into worktrees (stablyai#9791) * feat(worktrees): copy project-level .worktreeinclude paths into new worktrees Read .worktreeinclude at the repo root (gitignore syntax) and copy matching gitignored paths from the primary checkout into each newly created local worktree, so .env and other local config carry over with zero per-user setup. - Literal patterns resolve by direct stat; globs match against ls-files --others --ignored --exclude-standard --directory (collapsed dirs keep huge repos fast); every candidate is re-verified with check-ignore so tracked or unignored files are never copied. - Copy semantics, never symlink: APFS clone-copy on macOS, real copy elsewhere, so each worktree owns its files (unlike repo.symlinkPaths, which it merges with rather than replaces). - Failures never block worktree creation. - Remote (SSH) creation skips it, same as symlinkPaths. - Split APFS clone helpers into worktree-apfs-clone.ts (max-lines). Closes stablyai#7549 * fix(worktrees): harden worktree include copying * fix(worktrees): support nested includes on Git 2.25 * fix(worktrees): bound include copy costs * fix(worktrees): close include correctness and perf gaps * fix(worktrees): preserve included copy semantics * fix(worktrees): harden include resolution * fix(worktrees): preserve bounded include resolution * fix(worktrees): bound include filesystem resolution * fix(worktrees): harden include matching * fix(worktrees): tighten include matching and scan bounds * fix(types): use concrete filesystem stat types * fix(worktrees): harden included path materialization * perf(worktrees): stop include parsing at resolver budgets * chore(skills): refresh bundled skill manifests * refactor(worktrees): reduce .worktreeinclude to focused literal-only scope The reviewed implementation grew well past the ticket (stablyai#7549), which asks for a size-M feature that reuses existing worktree machinery. Trim back to the minimal change that solves the reported problem safely: - Resolver now supports literal files and directories only. Glob/negation lines are skipped with a warning (documented follow-up), which removes the entire user-controlled-regex ReDoS surface, the CPU/byte budgets, the git enumeration scan, and the case-sensitivity engine. The filesystem + git check-ignore handle existence and case for free. - Copy layer folded back into worktree-symlinks.ts (link/copy modes share one loop); dropped worktree-path-copy.ts, worktree-target-safety.ts, the descendant-dedup/realpath/target-parent machinery, and the per-materialization APFS filesystem cache. Kept the df/diskutil probe timeout. - Reverted unrelated changes: check-ignored-paths timeout param and the git-binary-compatibility enumeration tests. Net: -1903/+172 across the include+copy code. Behavior for the ticket's cases (.env, .env.local, .vscode/, node_modules, config/secrets.json) is unchanged; gitignored-only + copy-not-symlink semantics preserved. Closes stablyai#7549 * fix(worktrees): dereference symlinked .worktreeinclude entries + cache APFS volume probe Two issues found by review + perf audit of the copy path: - Correctness (HIGH): a listed entry that is itself a gitignored symlink was copied AS a symlink (fs.cp dereference:false), and the darwin APFS branch was skipped for all symlink sources. Editing the worktree's copy then wrote through to the shared/primary target — inverting copy-mode's 'each worktree owns its files' guarantee, and escaping the worktree entirely if the link pointed outside it. Now resolve realpath for a top-level symlink in copy mode so we copy content; nested symlinks inside a copied dir stay as-is (cp -R semantics). - Perf: assertSameApfsVolume ran df+diskutil per copied path (4 subprocesses each), so an N-entry include spawned ~4N short-lived processes on the macOS create hot path, all re-probing one volume. Add a per-materialization device-keyed cache: one probe per distinct volume (4N -> ~4). Tests: symlinked-file and symlinked-dir dereference regressions (no leak to primary); APFS volume probed once regardless of copied-path count.
Closes #7549
What
When creating a local worktree, Orca reads
.worktreeincludeat the repo root and copies each listed gitignored path from the primary checkout into the new worktree. The include list is version-controlled and travels with the repo, so every teammate and machine gets the same worktree setup with zero per-user config — and repos that already carry this file for other tools work in Orca unchanged.Scope — focused, safe-for-now subset
The ticket asks for a size-M feature that reuses existing worktree machinery. This PR is deliberately the minimal implementation that solves the reported problem:
.env,.env.local,.vscode/,node_modules,config/secrets.json— every example in the issue).*/?) and negation (!) are not supported yet — such lines are skipped with a warning rather than silently mishandled. Full.gitignoreglob syntax is a documented follow-up. This intentionally keeps the change small and avoids a user-controlled-regex surface for now.Semantics
git check-ignoreconfirms it is ignored. Tracked files are already in a fresh worktree; unignored files would show as spurious diffs. The filesystem + git handle existence and case-sensitivity, so there's no separate case logic..envmust not touch the primary). macOS uses the existing APFS clone-copy; elsewhere a realfs.cp, never a symlink...,.git/), and per-path copy failures are logged and skipped — worktree creation is never blocked.symlinkPaths(needs a relay method + auth surface).Changes (net ~500 lines)
src/main/git/worktree-include-file.ts— parse + resolve.worktreeincludeto concrete gitignored paths (literal-only).src/main/ipc/worktree-symlinks.ts—createWorktreeCopiedPaths: copy-mode materialization sharing the existing link loop.src/main/ipc/worktree-apfs-clone.ts— APFS clone helpers extracted fromworktree-symlinks.ts(max-lines), plus a df/diskutil probe timeout.worktree-remote.ts(createLocalWorktree) +orca-runtime.ts— resolve + copy after the symlink pass, before setup hooks.Testing
vitest:worktree-include-file.test.ts+ copy-mode cases inworktree-symlinks.test.ts; fullworktrees+orca-runtimesuites green (1031 tests).typecheck:node,oxlint,oxfmt, max-lines ratchet: clean.Follow-ups
.gitignoresyntax).Note: an earlier revision of this branch carried a much larger hardening layer (glob engine, CPU/byte budgets, git enumeration, filesystem caches). It has been trimmed to the focused scope above; the net diff reflects only the minimal feature.