Incremental sync (git-status fast path) bypasses the ignore matcher — tracked files in excluded dirs leak back into the index
Summary
getGitVisibleFiles filters the file list through buildDefaultIgnore (built-in defaults + root .gitignore) — that's the #407 design: committed dependency dirs are excluded even though they're tracked. But the incremental path doesn't apply the same matcher: getChangedFiles' git fast path consumes git status --porcelain output unfiltered, on the assumption that "git status already omits .gitignored paths".
That assumption has two holes:
- The built-in default excludes aren't gitignore at all. A committed
vendor/ornode_modules/dir is excluded from a full index byDEFAULT_IGNORE_PATTERNS, but git status happily reports changes to tracked files inside it. - gitignore is a no-op for tracked files. The documented way to exclude a committed dependency dir is a .gitignore entry (tracking-blind by design, per #407) — but
git statusstill reports modifications to those tracked files, because ignoring only applies to untracked paths.
In both cases the changed file isn't in the DB (!tracked) → pushed to added → parsed and indexed. The index now disagrees with what a full index --force produces; the next force re-index silently drops the file again (flip-flop).
Repro
- Project with a committed
vendor/dir (tracked files). Fullcodegraph index --force→ vendor excluded ✓ (per #407). - Modify a tracked file inside
vendor/. codegraph sync→ the file is hashed, found missing from the DB, and indexed.codegraph index --force→ it disappears again.
Same repro with a tracked dir listed in .gitignore instead of the built-in defaults.
(The FSEvents watcher path is NOT affected — watcher.js builds this.ignoreMatcher from buildDefaultIgnore and filters events. It's specifically the git-status fast path in getChangedFiles.)
Suggested fix (verified locally)
Build the shared matcher in getChangedFiles and skip matched paths in the modified+added loop:
const ig = buildDefaultIgnore(this.rootDir);
for (const filePath of [...gitChanges.modified, ...gitChanges.added]) {
if (ig.ignores(filePath)) continue;
// ... existing hash/compare logic
}
Deleted files can stay unfiltered — they only act when the path is already tracked in the DB, where removal is always correct (and it lets a newly-excluded dir's stale entries clean up).
We're running this patch locally on a ~1,100-file Swift + TS workspace and verified: a new file in an excluded tracked dir shows up in git status but does not enter the index via codegraph sync; full index and sync now agree.
Relevance to #699
Any implementation of the proposed .ignore overlay inherits this leak unless the sync path consults the same matcher as enumeration — with an extra ignore layer that git knows nothing about, every exclusion (not just tracked-file edge cases) would leak back in through git status. Worth fixing together.
🤖 Generated with Claude Code
Nice writeup — confirmed the leak. The git fast path in getChangedFiles consumes git status --porcelain output without running it through buildDefaultIgnore, so tracked files in node_modules/, vendor/, etc. slip back in on every sync even though a full index --force excludes them.
Opened a PR that applies your suggested fix: build the matcher once and continue past ignored paths in the modified+added loop. Added a regression test that commits a file inside node_modules/, modifies it, and verifies sync() doesn't index it.
Fixed in #949 (merged to main) — thanks for the precise root-cause and the verified patch.
What landed: change detection's git fast path now runs git status output through the same ignore matcher the full index uses, so a tracked file inside a committed dependency dir (a checked-in vendor/, node_modules/) or under a .gitignored directory is no longer treated as a change. It's applied per repo level during the embedded-repo recursion, which makes it equivalent to the full scan's ScopeIgnore — each embedded repo judged by its own rules, not the parent's (so #514 stays intact) — with no extra git calls. Deletions stay unfiltered exactly as you suggested (the DB-tracked guard makes that safe, and it lets a newly-excluded dir's stale rows clean up).
One refinement on the symptom, for anyone finding this later: since the v0.9.5 sync refactor (#414), codegraph sync reconciles against the filesystem scan (which already applies the matcher), so it no longer indexes these files. The leak that remained was in the fast change-detector behind codegraph status (and the public getChangedFiles() API) — so the user-visible symptom on current releases was status reporting pending changes that never cleared. Same root cause, same fix; both now agree with the full index.
And as you flagged, this unblocks #699 — an .ignore overlay would have leaked through this same path otherwise.
Will go out in the next release.