Skip to content

Bug: Git-ignored directory paths are treated as unanchored patterns, excluding unrelated source files #2849

Closed

Description

Environment

  • CodeGraph: 1.6.2
  • OS: Linux
  • Node.js: 24.14.1
  • Repository: Java multi-module Maven monorepo

Problem

CodeGraph incorrectly excludes thousands of tracked Java files when certain valid .gitignore patterns are present.

For example:

*jib*
**/opt/datadog

With these patterns, CodeGraph indexes zero Java files. Removing them allows 3,368 Java files to be indexed.

Root cause

In lib/dist/extraction/index.js, buildScopeIgnore() adds Git-reported ignored directory paths directly to the ignore matcher:

for (const dir of listGitIgnoredDirectories(rootDir)) {
    rootMatcher.add(dir);
}

Git legitimately reports the root-relative ignored directory src/.

However, the ignore library interprets src/ as matching directories with that name at any depth.

Consequently, CodeGraph incorrectly excludes paths such as:

services/backend-for-frontend/src/main/java/...

even though Git tracks these files and does not ignore them.

Proposed fix

Anchor Git-reported directory paths to the project root:

for (const dir of listGitIgnoredDirectories(rootDir)) {
-    rootMatcher.add(dir);
+    rootMatcher.add('/' + dir.replace(/^\/+/, ''));
}

Verification

Before patch:

  • 257 indexed files
  • 0 Java files

After patch:

  • 3,368 Java files indexed
  • Original .gitignore restored
  • Root src/ remains ignored
  • Nested service Java sources are correctly included

The fix was verified against CodeGraph 1.6.2 using buildScopeIgnore() and a full index rebuild.

Suggested regression test

Create a Git repository containing:

src/main/jib/opt/datadog/dd-java-agent.jar
services/example/src/main/java/Example.java

Add a .gitignore rule that ignores the JAR or its directory.

Assert that services/example/src/main/java/Example.java remains discoverable and indexable.

Activity

  1. colbymchenry commented on Oct 23, 2026

    @colbymchenry
    Owner

    Thanks for the precise report and the suggested fix, @Victor-Rodriguez-Garcia! You were right: the folders git reports as ignored were added to the scope matcher as unanchored patterns, so the ignored root src/ hid every module's src/.

    #2858 fixes it by matching those folders as exact paths from the project root, one step past anchoring them. The matcher library can't escape every character a folder name may contain (?, for example), so they're no longer read as patterns at all. The same change covers folders named like [draft] or scratch[1, which on 1.6.2 could match other folders or make the file watcher fail, and the includeIgnored entry codegraph init suggests for a gitignored nested repository.

    Checked on real repos after writing what each project's local build writes at the root: every file git considers in scope is now indexed (your jib layout on a Maven project: 104 files before, 1,423 of 1,423 after), and nothing git ignores is added.

    It's merged and ships in the next release. After upgrading, run codegraph index on the monorepo to pick up the Java files that were left out.

  2. added a commit that references this issue on Oct 23, 2026
    a278c2e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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