fix(detect): scope nested ignore patterns to their own subtree#1885
Closed
Alwyn93 wants to merge 1 commit into
Closed
fix(detect): scope nested ignore patterns to their own subtree#1885Alwyn93 wants to merge 1 commit into
Alwyn93 wants to merge 1 commit into
Conversation
…ify-Labs#1873) Non-anchored patterns from a nested .gitignore/.graphifyignore were matched against root-relative paths first, so a nested ignore file's patterns leaked outside its directory. In the wild, .hypothesis/.gitignore (a bare "*" auto-written by the hypothesis library) ignored the entire repository and detect() returned 0 files. Per gitignore semantics, patterns from A/.gitignore apply only to paths under A. Match every pattern against the path relative to its own anchor (the anchor dir itself exempt — an ignore file governs its directory's contents, not the directory), and skip patterns whose anchor does not contain the target. Regression introduced with nested-ignore support in 8a5287a (Graphify-Labs#1206). tests/test_detect.py: 143 passed, including the existing nested-ignore and nested-negation tests plus two new regressions. Fixes Graphify-Labs#1873 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
roslinmahmud
approved these changes
Jul 14, 2026
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1873 — nested
.gitignore/.graphifyignorepatterns applied outside their own subtree, which can zero an entire scan._is_ignored()matched non-anchored patterns against the path relative to the scan root first, so patterns from a nested ignore file leaked out of their directory. In-the-wild trigger: thehypothesislibrary auto-writes.hypothesis/.gitignorecontaining a bare*— with nested-ignore support (8a5287a, #1206) that single file ignored the whole repository anddetect()returned 0 files.Fix
Per gitignore semantics, patterns from
A/.gitignoreapply only to paths underA. The patch matches every pattern against the path relative to its own anchor:continue)rel_anchor == ".") — an ignore file governs its directory's contents, not the directory/-prefixed) and non-anchored patterns unified on the same anchor-relative path; last-match-wins and!negation behavior unchangedTests
tests/test_detect.py: 143 passed — including the existing nested-ignore, nested-negation-beats-root, andgit info/excludeprecedence teststest_nested_gitignore_star_does_not_ignore_outside_its_dir— the.hypothesisscenario; fails onv8HEAD (total_files == 0), passes with the fixtest_nested_gitignore_patterns_still_apply_inside_their_dir— guard that nested ignore files still work within their subtreetests/test_skillgen.py(11) andtests/test_ollama_retry_cap.py(4) are pre-existing atv8HEAD (verified on a clean checkout) and unrelated to this change.Also verified on a real repo: a scan that returned 0 files at HEAD returns 204/230 with the fix.
Related
graphify update/--watchre-run detection without the CLIextra_excludes, so a workaround via CLI excludes doesn't survive watch mode — happy to file/fix separately if useful.🤖 Generated with Claude Code