fix(scan): honor .codegraphignore on the git fast path#103
Open
andreinknv wants to merge 1 commit into
Open
Conversation
The .codegraphignore marker (per-directory opt-out from indexing) was
respected by `scanDirectoryWalk` (the filesystem-walk fallback) but
silently ignored by `getGitVisibleFiles` (the git fast path) and
`getGitChangedFiles` (sync's git path). Same project gave different
file sets depending on whether `.git` existed — typically the marker
"worked" only on non-git scratch projects and was a no-op everywhere
else, which is the opposite of how most users encounter it.
This change adds two helpers in `src/extraction/index.ts`:
- `findCodegraphIgnoredDirs(rootDir, files)` — walks parent directories
of the given file list, returns the set of directories that contain
a `.codegraphignore` marker. Walks once per unique parent directory,
with an early-out on shared ancestors.
- `isUnderCodegraphIgnoredDir(filePath, ignoredDirs)` — true if filePath
lives under any of those dirs.
Applied in:
- `scanDirectory` and `scanDirectoryAsync` — between the git file list
and the include-pattern filter.
- `getGitChangedFiles` — refactored to a two-pass collect-then-bucketize
so the ignored-dir set is built once from the candidate paths.
The marker file itself does not need to be tracked by git — fs.existsSync
catches it whether it was committed or added as a local override.
## Files changed
| File | Change |
|---|---|
| src/extraction/index.ts | Add findCodegraphIgnoredDirs + isUnderCodegraphIgnoredDir; apply in scanDirectory, scanDirectoryAsync, getGitChangedFiles |
| __tests__/codegraphignore.test.ts | 6 regression tests |
## Test plan
- [x] npm test: 386/386 pass on macOS (one pre-existing fs.watch flake under parallel load, passes in isolation)
- [x] npx tsc --noEmit clean
- [x] Independent reviewer pass before pushing — APPROVE; addressed two info-level cleanups (JSDoc accuracy, removed dead try/catch around fs.existsSync)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
.codegraphignoremarker (per-directory opt-out from indexing) was respected byscanDirectoryWalk(the filesystem-walk fallback) but silently ignored bygetGitVisibleFiles(the git fast path) andgetGitChangedFiles(sync's git path). Same project gave different file sets depending on whether.gitexisted — typically the marker "worked" only on non-git scratch projects and was a no-op everywhere else, the opposite of how most users encounter it.What changed
Two helpers in
src/extraction/index.ts:findCodegraphIgnoredDirs(rootDir, files)— walks parent directories of the given file list, returns the set of dirs that contain a.codegraphignoremarker. Walks once per unique parent directory with an early-out on shared ancestors.isUnderCodegraphIgnoredDir(filePath, ignoredDirs)— true iffilePathlives under any of those dirs.Applied at three sites:
scanDirectoryandscanDirectoryAsync— between the git file list and the include-pattern filtergetGitChangedFiles— refactored to a two-pass collect-then-bucketize so the ignored-dir set is built once from the candidate pathsThe marker file itself does not need to be tracked by git —
fs.existsSynccatches it whether it was committed or added as a local override.Files changed
src/extraction/index.tsfindCodegraphIgnoredDirs+isUnderCodegraphIgnoredDir; apply inscanDirectory,scanDirectoryAsync,getGitChangedFiles__tests__/codegraphignore.test.tsTest coverage
scanDirectoryhonors marker in a subdir on the git fast pathgetGitChangedFiles) ignores changes inside marker dirsKnown limitation (pre-existing, out of scope)
If a
.codegraphignoremarker is added after files in that directory have already been indexed, the next sync via the git fast path won't proactively delete those stale rows —git statusdoesn't report unchanged files. The next fullindexAll(or a sync that falls into the filesystem-walk path) will clean them up. This is an existing characteristic of the git fast path; documenting here for transparency rather than fixing in this PR.Test plan
npm test: 386/386 pass on macOS (one pre-existing fs.watch flake under parallel load, passes in isolation)npx tsc --noEmitcleanfs.existsSyncwhich never throws)🤖 Generated with Claude Code