fix(sync): apply the ignore matcher to the git change-detection fast path (#766) (#949)

Change detection's git fast path (collectGitStatus) consumed `git status`
output with only an isSourceFile filter, on the assumption that git already
omits ignored paths. It doesn't: gitignore is a no-op for *tracked* files, and
the built-in default excludes (vendor/, node_modules/) aren't gitignore at all.
So a tracked file inside a committed dependency dir, or under a .gitignored
dir, surfaced as a change the full index never tracks — `codegraph status`
reported phantom pending changes that `sync` (a filtered filesystem reconcile)
never cleared, and the public getChangedFiles() API returned the same wrong
list.

Apply buildDefaultIgnore(repoDir) per recursion level, matching repo-relative
paths — structurally equivalent to the full-index path's ScopeIgnore (each
embedded repo judged by its own rules) with no extra git subprocess calls.
Deletions stay unfiltered: getChangedFiles acts on one only when the path is
already tracked in the DB, where removal is always correct, and that lets a
newly-excluded dir's stale rows clean themselves up.

Unblocks #699 (an .ignore overlay inherits this leak unless change detection
consults the same matcher as enumeration).

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Colby Mchenry
2026-06-22 10:51:20 -05:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 149b4e11c7
commit 2010c2d2b5
3 changed files with 150 additions and 3 deletions
+24 -3
View File
@@ -639,6 +639,18 @@ function collectGitStatus(repoDir: string, prefix: string, out: GitChanges): voi
{ cwd: repoDir, encoding: 'utf-8', timeout: 10000, maxBuffer: 50 * 1024 * 1024, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true }
);
// This repo's own ignore rules — built-in defaults (#407) plus its .gitignore.
// Change detection must exclude the SAME files the full index does, but git
// status hides neither: it ignores nothing for *tracked* paths, and the
// built-in defaults aren't gitignore at all. Without this filter a committed
// vendor/ dir, or a tracked file under a .gitignored dir, surfaces here as a
// change — so `codegraph status` (which reads getChangedFiles) reports a
// pending edit the full index never tracks and `sync` never clears. Matching
// repo-relative `rel` at each recursion level mirrors getGitVisibleFiles'
// ScopeIgnore: every embedded repo is judged by ITS OWN rules, never the
// parent's. (#766)
const ig = buildDefaultIgnore(repoDir);
const untrackedDirs: string[] = [];
for (const line of output.split('\n')) {
if (line.length < 4) continue; // Minimum: "XY file"
@@ -654,13 +666,22 @@ function collectGitStatus(repoDir: string, prefix: string, out: GitChanges): voi
}
const filePath = normalizePath(prefix + rel);
// Skip non-source files (git status already omits .gitignored paths).
if (!isSourceFile(filePath)) continue;
if (statusCode.includes('D')) {
// Deletions stay unfiltered: getChangedFiles acts on one only when the
// path is already tracked in the DB, where removal is always correct — and
// that lets a newly-excluded dir's stale rows clean themselves up. (#766)
out.deleted.push(filePath);
continue;
}
// Added (`??`) / modified files inside an excluded dir must not enter the
// index — match against the repo-relative path, same as the full scan. (#766)
if (ig.ignores(rel)) continue;
if (statusCode === '??') {
out.added.push(filePath);
} else if (statusCode.includes('D')) {
out.deleted.push(filePath);
} else {
// M, MM, AM, A (staged), etc. — treat as modified
out.modified.push(filePath);