Repository navigation
fix(indexer): honor nested .gitignore files - #204
Conversation
Apply package ignore rules during the shared preview and index scan. Keep directory-relative matching and parent exclusions, and cover both index paths with regression tests. Reuse: extend src/core/indexer.ts Agent-Harness: codex Agent-Session: 01a24044-09a7-7a31-91fc-c3e6a0977878
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Confidence Score: 3/5
[Medium impact] The change affects which files project previews and indexes include. Restore support for linked root Findings
SummaryThe shared scan now reads nested
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Shared file scan] --> B[Load parent ignore rules]
B --> C{Directory already ignored?}
C -->|Yes| D[Keep inherited rules]
C -->|No| E[Read local .gitignore]
E --> F[Scope and append local rules]
D --> G[Check source file]
F --> G
G --> H[Preview or saved index]
Reviews (1) · Last reviewed commit: "fix(indexer): honor nested .gitignore fi..." · Reviewed by Greptile |
| if (isRoot || !inherited?.ignores(`${directory}/`)) { | ||
| try { | ||
| const ignoreFile = path.join(rootPath, directory, '.gitignore'); | ||
| if ((await fs.lstat(ignoreFile)).isFile()) { |
There was a problem hiding this comment.
If the root .gitignore is a readable symlink, lstat(...).isFile() returns false and none of its rules are loaded. Previously, scanFiles read the file directly and followed the link. A workspace linking to shared rules containing secrets.ts will now include that source file in the preview and saved index despite respectGitignore: true. Preserve the previous root behavior and add a regression test.
How this was verified: The new file-type check skips linked ignore files, and the shared scan accepts supported source files when the matcher returns false.
What changed
The indexer read
.gitignoreonly at the project root, so files ignored by packages could appear in the preview and the saved index. The shared file scan now applies each nested.gitignorerelative to its directory, including negations and excluded parent directories.Reproduce
Create
packages/api/generated.tsand put/generated.tsinpackages/api/.gitignore. Runcodebase-context reindex --no-embeddingsfrom the project root. Before this fix,packages/api/generated.tsappears in the index. The regression test checks both the preview and the saved index.Tests
masterbefore the fix. The focused run passed 14 of 14 tests with the fix.pnpm teston Windows with Node 24 passed 1,572 tests, skipped 2, and failed 0 across 167 test files.