Skip to content

fix: filter out gitignore negation patterns to prevent excluding all files#1

Open
zlegein wants to merge 1 commit intoCSCSoftware:masterfrom
zlegein:fix/gitignore-negation-patterns
Open

fix: filter out gitignore negation patterns to prevent excluding all files#1
zlegein wants to merge 1 commit intoCSCSoftware:masterfrom
zlegein:fix/gitignore-negation-patterns

Conversation

@zlegein
Copy link

@zlegein zlegein commented Mar 6, 2026

Negation patterns in .gitignore (lines starting with !) were being passed through to minimatch, which caused them to match ALL files instead of being ignored. For example, !.vscode/settings.json would match every file path because minimatch interprets the leading ! as "NOT this pattern".

This caused the entire index to be purged after initialization in projects with negation patterns in their .gitignore (common in monorepos).

The fix filters out negation patterns in readGitignore() since they are meant to un-ignore files, not to add exclusion patterns.

Problem

When a project's .gitignore contains negation patterns (lines starting with !), AiDex incorrectly excludes all indexed files after initialization.
For example, a .gitignore with:
.vscode/* !.vscode/settings.json !.vscode/tasks.json

Causes the patterns !.vscode/settings.json to be passed to minimatch(). Since ! at the start of a pattern means "NOT this pattern", these patterns match every file that isn't .vscode/settings.json — effectively matching all source files.

Reproduction

  1. Clone any project with negation patterns in .gitignore (common in monorepos)
  2. Run aidex init .
  3. Observe: "Files indexed: N, Files removed: N (now excluded)"
  4. The index is empty despite successful indexing

Root Cause

readGitignore() in src/commands/init.ts doesn't filter out negation patterns. These patterns are then used in the post-indexing cleanup phase, where minimatch(filePath, '!.vscode/settings.json', { dot: true }) returns true for any path that isn't .vscode/settings.json.

Solution

Filter out negation patterns in readGitignore() since they are meant to un-ignore files, not to add exclusion patterns:

.filter(line => line && !line.startsWith('#') && !line.startsWith('!'))

…files

Negation patterns in .gitignore (lines starting with !) were being passed
through to minimatch, which caused them to match ALL files instead of being
ignored. For example, `!.vscode/settings.json` would match every file path
because minimatch interprets the leading `!` as "NOT this pattern".

This caused the entire index to be purged after initialization in projects
with negation patterns in their .gitignore (common in monorepos).

The fix filters out negation patterns in readGitignore() since they are
meant to un-ignore files, not to add exclusion patterns.

Made-with: Cursor
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.

2 participants