Skip to content

detect(): scan root itself matched by an ancestor .gitignore prunes nested files but not top-level ones (near-total silent data loss) #2358

Open

Description

@martinknowsbest

Summary

detect() walks up from the scan root to find an ancestor .git/.gitignore even when the scan root itself is an ignored path (e.g. corpus/ is deliberately listed in the enclosing repo's .gitignore because it holds private snapshot data that shouldn't be committed). The result is inconsistent and near-total pruning: files directly inside the scan root survive, but anything nested one level deeper or more is silently dropped — with no warning.

This is distinct from #1873/#1887 (a nested .gitignore inside the scan root leaking its patterns outside its own subtree). Here there's no nested .gitignore at all — the only ignore file involved is the top-level one in the parent repo, and the bug is that it still gets applied to a directory that was explicitly passed as the scan root, in a way that behaves inconsistently by depth.

Repro

mkdir -p repo/corpus/subdir && cd repo
git init -q
printf 'corpus/\n' > .gitignore
printf '# top-level file\n' > corpus/manifest.md
printf '# nested file\n' > corpus/subdir/notes.md
printf '# nested file 2\n' > corpus/subdir/more.md

python3 -c "
from graphify.detect import detect
from pathlib import Path
result = detect(Path('corpus'))
print('total_files:', result.get('total_files'))   # 1 — expected: 3
for cat, files in result.get('files', {}).items():
    if files:
        print(cat, files)
"
# document ['.../repo/corpus/manifest.md']
# corpus/subdir/notes.md and corpus/subdir/more.md are missing — no warning, no skip count.

Expected

Either:

  • detect() should not honor an ancestor .gitignore pattern that matches the scan root path itself (you explicitly pointed at this directory — that's a stronger signal than an inherited ignore rule), or at minimum
  • it should behave consistently: currently top-level files in the scan root survive while nested ones don't, which is confusing and looks like partial success rather than a total-exclusion bug.

If exclude-by-design is intended, detect() should at least surface a skipped_gitignored count (or similar) so a near-empty result isn't silently mistaken for "this folder has almost no supported files."

Impact hit in the wild

Real project: a Graphify knowledge-graph automation snapshots private source files into corpus/ inside its own git repo, with corpus/ (and graphify-out/) in .gitignore on purpose (so the snapshot/output never gets committed). detect(Path('corpus')) returns total_files: 1 (a stray .json at the corpus root) instead of the real ~230 files. The project's own manifest-based snapshotter (independent of detect()) confirms 230 files are actually present.

This also breaks graphify update <corpus> on the same corpus (not just detect() directly) — the incremental updater's internal scan hits the same pruning, decided that ~207 previously-known files "left the scan corpus," and tried to shrink the graph from 1537 nodes down to 212 before the shrink-guard (correctly) refused the write. Had the shrink-guard not existed, this would have silently destroyed most of a curated knowledge graph.

Environment

  • graphify (graphifyy) 0.9.28
  • Python 3.14.6
  • macOS 24.6.0 (Darwin), x86_64
  • Installed via uv tool install graphifyy

Workaround

None found short of moving the scan root outside any git repo that ignores it, which isn't viable when the corpus needs to live in the automation's own repo (versioned tooling, gitignored data).

Activity

  1. shard-c6 commented on Aug 1, 2026

    @shard-c6

    Hi! I'd like to work on this issue. Could you assign it to me?

  2. martinknowsbest commented on Aug 4, 2026

    @martinknowsbest
    Author

    Could a maintainer please assign this issue to @shard-c6? They will be taking ownership of the fix. Thanks!

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