Skip to content

Feature Request: Support .ignore files to override .gitignore exclusions #699

@keeferwu

Description

@keeferwu

Problem

CodeGraph uses git ls-files under the hood to discover source files, which means it inherently respects .gitignore. Any directory or file matched by .gitignore is invisible to CodeGraph and cannot be indexed.

In many real-world projects, entire directories are gitignored even though they contain valuable source code that an AI agent needs to understand. Common examples:

  • A top-level customer/ directory that contains per-customer customization code
  • Pods/ in iOS projects (tracked locally but gitignored)
  • vendor/ in Go projects
  • Embedded independent git repos inside a monorepo

Currently, the only workaround is to remove entries from .gitignore (which changes repo semantics) or to initialize a separate CodeGraph instance inside the ignored directory (which creates a fragmented index and requires passing --projectPath everywhere).

Proposed Solution

Support .ignore files (using the same pattern syntax as .gitignore) that act as a local override layer on top of .gitignore. This is a well-established pattern used by tools like ripgrep, fd, ag, and rg:

  • .gitignore — patterns to ignore (unchanged, respected by CodeGraph as today)
  • .ignore — patterns to override .gitignore with negation patterns (! prefix)

For example, if .gitignore contains:

customer/

And the user creates .ignore with:

!customer/

Then CodeGraph would include the customer/ directory in its index even though it's gitignored.

How it works (proposed)

  1. CodeGraph reads .gitignore as today to get the base exclusion set.
  2. CodeGraph then reads .ignore files (if present) from the same locations where .gitignore is checked.
  3. .ignore patterns are applied after .gitignore patterns, so negation patterns (!xxx/) in .ignore can re-include files/directories that .gitignore excluded.
  4. .ignore is gitignored by default (added to tooling's own ignore list) so it doesn't affect repository semantics.

Why this is better than alternatives

Approach Downsides
Remove entries from .gitignore Changes repo behavior for all git commands; commits required
git add -f Modifies the repo permanently; pollutes git tracking
Separate CodeGraph instances Fragmented index; --projectPath needed everywhere; no cross-repo queries
.ignore file Zero impact on git; local to each developer; well-known pattern from other tools

Prior art

  • ripgrep (rg): reads .ignore files as a gitignore-aware ignore layer
  • fd: reads .ignore files with the same semantics
  • ag (the silver searcher): supports .ignore files
  • Node.js's glob module: respects .gitignore + .ignore
  • Git itself: supports .gitignore + .git/info/exclude + core.excludesFile (though .ignore is not native to git)

Use case from the reporter

We have a large networking switch firmware project organized as:

root/          (main git repo, customer/ is in .gitignore)
  customer/
    cus_dlinkg2/    (1075 C source files, independent git repo)

With .ignore support, users could add !customer/ to .ignore at the project root and CodeGraph would index the customer code as part of the main project — no separate init needed, no --projectPath required.

Additional notes

  • The .ignore file should be checked at the project root level (same directory as .gitignore).
  • Ensure .ignore is added to CodeGraph's own built-in exclusion list so it is never indexed itself.
  • The parse order should be: .gitignore.ignore (applied as overlay).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions