Skip to content

feat(worktrees): support project-level .worktreeinclude (literal paths) for copying gitignored files into worktrees - #9791

Merged
brennanb2025 merged 20 commits into
mainfrom
brennanb2025/feature-support-project-level-.worktreeinclude-f
Jul 24, 2026
Merged

brennanb2025 merged 20 commits into
mainfrom
brennanb2025/feature-support-project-level-.worktreeinclude-f

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #7549

What

When creating a local worktree, Orca reads .worktreeinclude at 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:

  • Each non-comment line is a literal file or directory anchored to the repo root (.env, .env.local, .vscode/, node_modules, config/secrets.json — every example in the issue).
  • Glob (*/?) and negation (!) are not supported yet — such lines are skipped with a warning rather than silently mishandled. Full .gitignore glob syntax is a documented follow-up. This intentionally keeps the change small and avoids a user-controlled-regex surface for now.

Semantics

  • Gitignored-only (the caveat called out in the issue): a path is copied only if it exists in the primary checkout and git check-ignore confirms 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.
  • Copy, not symlink — the one deliberate deviation from the issue's "reuse the symlink fallback" suggestion: the convention promises each worktree its own private copy (editing a worktree's .env must not touch the primary). macOS uses the existing APFS clone-copy; elsewhere a real fs.cp, never a symlink.
  • Merges with (never replaces) the existing per-user Worktree Symlinks repo setting.
  • Fails safe: unreadable file, git errors, unsafe patterns (absolute, .., .git/), and per-path copy failures are logged and skipped — worktree creation is never blocked.
  • Remote (SSH) creation skips it, same as symlinkPaths (needs a relay method + auth surface).

Changes (net ~500 lines)

  • src/main/git/worktree-include-file.ts — parse + resolve .worktreeinclude to 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 from worktree-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 in worktree-symlinks.test.ts; full worktrees + orca-runtime suites green (1031 tests).
  • typecheck:node, oxlint, oxfmt, max-lines ratchet: clean.

Follow-ups

  • Glob / negation (full .gitignore syntax).
  • Remote (SSH) support.

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.

…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
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds .worktreeinclude parsing and resolution for selected gitignored paths, including glob, negation, directory-only, safety, and failure handling. Adds copy-based worktree materialization with guarded fallback behavior and macOS APFS cloning. Local worktree creation now copies resolved include paths after symlink setup, while remote worktree creation excludes this behavior. Tests cover parsing, path resolution, copying, APFS fallback, ignored-directory enumeration, and updated module mocks.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is missing the required template sections: Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Reformat the PR description to match the template and add the missing sections, including testing status, screenshots/no visual change, review report, security audit, and notes.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement project-level .worktreeinclude support, gitignore-style matching, gitignored-only copying, and merging with existing symlink paths as requested.
Out of Scope Changes check ✅ Passed The added APFS, glob, and resolution helpers all support the .worktreeinclude feature and do not appear unrelated to the stated objectives.
Title check ✅ Passed The title matches the main change: project-level .worktreeinclude support for copying gitignored paths into worktrees, though it understates broader pattern support.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 883743ee-f836-4a9c-b562-04446be8bf12

📥 Commits

Reviewing files that changed from the base of the PR and between 21e26de and 4471e8a.

📒 Files selected for processing (9)
  • src/main/git/worktree-include-file.test.ts
  • src/main/git/worktree-include-file.ts
  • src/main/ipc/worktree-apfs-clone.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktree-symlinks.test.ts
  • src/main/ipc/worktree-symlinks.ts
  • src/main/ipc/worktrees.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts

Comment thread src/main/git/worktree-include-file.ts Resolved
Comment thread src/main/git/worktree-include-file.ts Resolved
Comment thread src/main/ipc/worktree-symlinks.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Match unanchored literals against any path segment
The fallback pathspec scan can return full nested paths like apps/web/.env, so checking only the leaf segment still drops bare includes such as build under ignored parents. Compare unanchored literals against every path segment instead of at(-1).


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 84e485ba-ff2c-4eb7-93d2-17271b01b592

📥 Commits

Reviewing files that changed from the base of the PR and between 0403321 and 7f5f9f4.

📒 Files selected for processing (7)
  • src/main/git/worktree-include-file.test.ts
  • src/main/git/worktree-include-file.ts
  • src/main/git/worktree-include-glob.ts
  • src/main/ipc/worktree-apfs-clone.ts
  • src/main/ipc/worktree-symlinks.test.ts
  • src/main/ipc/worktree-symlinks.ts
  • src/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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3f349eeb-bbf8-4c6f-a5ed-6c83cbbee49a

📥 Commits

Reviewing files that changed from the base of the PR and between 7f5f9f4 and b574104.

📒 Files selected for processing (13)
  • src/main/git/check-ignored-paths.test.ts
  • src/main/git/check-ignored-paths.ts
  • src/main/git/worktree-include-file.test.ts
  • src/main/git/worktree-include-file.ts
  • src/main/git/worktree-include-flow.test.ts
  • src/main/git/worktree-include-glob.ts
  • src/main/git/worktree-include-pattern.ts
  • src/main/ipc/worktree-apfs-clone.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktree-symlinks.test.ts
  • src/main/ipc/worktree-symlinks.ts
  • src/main/runtime/orca-runtime.ts
  • src/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

Comment thread src/main/git/worktree-include-file.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/main/git/worktree-include-flow.test.ts (1)

65-71: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the tracked-file assertion prove the copy contract.

mixed/tracked.txt already exists because it was committed before git worktree add; reading it after copying cannot verify that copy materialization handled it. The exact includePaths assertion 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

📥 Commits

Reviewing files that changed from the base of the PR and between b574104 and 504a1eb.

📒 Files selected for processing (11)
  • src/main/git/worktree-include-file.test.ts
  • src/main/git/worktree-include-file.ts
  • src/main/git/worktree-include-flow.test.ts
  • src/main/git/worktree-include-git-enumeration.test.ts
  • src/main/git/worktree-include-git-enumeration.ts
  • src/main/git/worktree-include-glob.ts
  • src/main/git/worktree-include-stat-concurrency.test.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktree-symlinks.test.ts
  • src/main/ipc/worktree-symlinks.ts
  • src/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

Comment thread src/main/git/worktree-include-file.ts Resolved
Comment thread src/main/git/worktree-include-file.ts Resolved
…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
@brennanb2025 brennanb2025 changed the title feat(worktrees): support project-level .worktreeinclude for copying gitignored files into worktrees feat(worktrees): support project-level .worktreeinclude (literal paths) for copying gitignored files into worktrees Jul 23, 2026
…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.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review + perf audit round

Ran an adversarial code review and a /perf audit of the copy path. Outcome:

Fixed

  • (HIGH, correctness) A listed entry that is itself a gitignored symlink was copied as a symlink (fs.cp default 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 if the link pointed outside it. Now the top-level symlink is dereferenced (realpath) in copy mode so content is copied; regression tests cover the file and directory cases (no leak to primary).
  • (perf) assertSameApfsVolume ran df+diskutil per copied path (4 subprocesses each) → ~4N short-lived processes on the macOS create hot path, all re-probing one volume. Added a per-materialization device-keyed cache: one probe per distinct volume (4N → ~4), with a test asserting the probe count no longer scales with path count.

Documented as known limits (no code — kept the feature minimal)

  • Large gitignored directories copy synchronously; instant on macOS (APFS clone) but a real recursive copy on Linux/Windows, so listing a multi-GB tree (e.g. node_modules) slows creation there. Prefer the per-user Worktree Symlinks setting for big shared trees. Copy never fails creation (per-path errors are logged/skipped) — it can only slow it.
  • Symlinks nested inside a copied directory are preserved as-is (conventional cp -R semantics).
  • A path in both .worktreeinclude and the per-user symlink list stays a symlink for that entry (symlink pass runs first; copy pass skips an existing target).

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.

@brennanb2025
brennanb2025 merged commit b600e25 into main Jul 24, 2026
1 check passed
QingqiShi added a commit to QingqiShi/shiqingqi.com that referenced this pull request Aug 3, 2026
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.
@grundmanise

Copy link
Copy Markdown

Hi @brennanb2025, just curios of Glob / negation (full .gitignore syntax) is in the pipeline already?

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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.

[Feature]: Support project-level .worktreeinclude for copying gitignored files into worktrees

2 participants