Skip to content

_is_ignored: unanchored parent-.gitignore pattern matching the scan root's own directory name silently zeroes the corpus (detect_incremental returns 0 files) #2468

Closed

Description

@alexrdunbar

Summary

When the scan root's own directory name is also the subject of an unanchored ignore pattern in a parent .gitignore, _is_ignored's anchor-fallback branch matches that pattern against every path in the scan. Every file in the corpus is classified as ignored, and detect() / detect_incremental() report 0 files with no warning.

This is the normal, correct way to write the ignore rule from git's point of view (graphify-corpus/ in the repo root .gitignore keeps a regenerable corpus out of the repo), so the failure hits exactly the setup the tool is meant to support.

Version: graphifyy 0.9.12, Python 3.14, Windows.

Repro

  1. A git repo with a directory graphify-corpus/ at its root, holding the corpus you want to scan.

  2. The repo root .gitignore contains an unanchored line:

    # Graphify (regenerable knowledge graph)
    graphify-corpus/
    graphify-out/
  3. Run against that directory:

    from pathlib import Path
    from graphify.detect import detect_incremental
    r = detect_incremental(Path('graphify-corpus'))
    print(r['total_files'], r['new_total'])   # -> 0 0

Result: total_files = 0, new_total = 0, and deleted_files lists every entry from the previous manifest with a doubled path prefix, e.g.

C:\...\claude-code\graphify-corpus\graphify-corpus\claude-scripts\pm2-monit.ps1
C:\...\claude-code\graphify-corpus\graphify-corpus\claude-skills\autoresearch\autoresearch.py

The doubled prefix is the visible tell that the scan root's name is being prepended a second time during matching.

Cause

_load_graphifyignore walks up to the VCS root and returns (anchor_dir, pattern) pairs, so the repo-root .gitignore contributes (<repo_root>, "graphify-corpus/").

In detect.py::_is_ignored._eval, the unanchored branch (currently detect.py:896-907) falls back to re-matching against the pattern's own anchor directory when anchor != root:

else:
    try:
        rel = str(target.relative_to(root)).replace(os.sep, "/")
        matched = _matches(rel, p, anchored=False)
    except ValueError:
        pass
    if not matched and anchor != root:
        try:
            rel_anchor = str(target.relative_to(anchor)).replace(os.sep, "/")
            matched = _matches(rel_anchor, p, anchored=False)
        except ValueError:
            pass

For target = <repo>/graphify-corpus/docs and root = <repo>/graphify-corpus:

  • first attempt: rel = "docs" → no match, correct

  • fallback: rel_anchor = "graphify-corpus/docs", and _matches(..., anchored=False) splits on / and tests each component:

    for i, part in enumerate(parts):
        if fnmatch.fnmatch(part, p):   # "graphify-corpus" vs "graphify-corpus" -> True
            return True

    → matched, ignored.

The component that matches is the scan root itself, not anything inside the scan. Because the parent-exclusion walk at the top of _is_ignored evaluates ancestors first, every path under the root is excluded, so the whole corpus disappears.

Minimal A/B with the pattern in isolation, everything else held constant:

from pathlib import Path
from graphify.detect import _is_ignored
root = Path('graphify-corpus').resolve()
repo = root.parent
before = [(repo, 'graphify-corpus/')]
after  = [(repo, '/graphify-corpus/')]
for name in ['docs', 'memory', 'tasks', 'claude-agents', 'claude-skills']:
    print(name, _is_ignored(root/name, root, before), _is_ignored(root/name, root, after))
docs            before=True  after=False
memory          before=True  after=False
tasks           before=True  after=False
claude-agents   before=True  after=False
claude-skills   before=True  after=False

Suggested fix

In the anchor != root fallback, a pattern should not be allowed to match on a path component at or above the scan root. Either strip the root-relative prefix before component matching, or skip the fallback when the only matching component lies outside target.relative_to(root). Related but distinct from the nested-ignore scoping work in #1873 / #1922 / #1885: those are about a nested ignore file leaking outward; this is a parent pattern folding the scan root back into the match.

A detect() that returns 0 files on a directory the user explicitly passed is also worth a loud warning rather than a silent empty result (cf. #2358 / #2370).

Workaround

Anchor the pattern in the parent .gitignore:

/graphify-corpus/

Git treats /graphify-corpus/ and graphify-corpus/ identically for a rule at the repo root (both still exclude the whole tree from tracking, confirmed with git check-ignore -v), but the leading slash sends _is_ignored down the anchored=True path, where fnmatch("graphify-corpus/docs", "graphify-corpus") is correctly False. After the change the same scan reports real counts instead of 0.

Activity

  1. shard-c6 commented on Aug 5, 2026

    @shard-c6

    would like to work on this

  2. safishamsi commented on Aug 12, 2026

    @safishamsi
    Member

    Fixed in v0.9.41 (graphifyy==0.9.41 on PyPI). An explicitly-passed scan root is no longer excluded by an unanchored pattern in a parent-directory .gitignore that matches the root's own name; the match path is re-relativized to the scan root (and NFC-normalized). Thanks @hopstreax (PR #2475).

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions