Skip to content

fix: preserve explicit scan roots when matching parent unanchored .gitignore patterns - #2475

Closed
hopstreax wants to merge 1 commit into
Graphify-Labs:v8from
hopstreax:fix/2468-parent-gitignore-scan-root
Closed

hopstreax wants to merge 1 commit into
Graphify-Labs:v8from
hopstreax:fix/2468-parent-gitignore-scan-root

Conversation

@hopstreax

Copy link
Copy Markdown
Contributor

Summary

Fixes Issue #2468 by preventing unanchored parent .gitignore patterns from incorrectly matching the scan root itself when the user explicitly scans a subdirectory of a Git repository.

Previously, when a parent .gitignore contained an unanchored directory rule matching the scan root (for example, graphify-corpus/), Graphify evaluated the path relative to the parent ignore anchor. This allowed the scan root's own directory name to participate in unanchored basename matching, causing descendant directories to be incorrectly pruned during traversal.

The fix preserves existing ignore semantics while ensuring that unanchored parent patterns are evaluated relative to the scan root in this specific scenario, preventing the scan root itself from becoming a match candidate.

Changes

  • Adjust unanchored parent ignore matching in _is_ignored() to evaluate scan-root descendants using scan-root-relative paths when appropriate.

  • Preserve existing behavior for:

    • anchored ignore patterns
    • nested .gitignore files
    • directory-only patterns
    • wildcard and basename matching
    • negation rules

Tests

Added regression tests covering:

  1. Scanning a directory whose name is excluded by an unanchored parent .gitignore rule no longer suppresses traversal of the explicitly requested scan root.
  2. Parent .gitignore rules continue to ignore unrelated directories (for example, node_modules/) inside the scan root, ensuring existing ignore semantics are preserved.

Validation

  • New regression tests pass.
  • Existing ignore-related tests continue to pass.
  • Production change is limited to a small, localized modification in graphify/detect.py.

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

This PR modifies the _is_ignored logic in graphify/detect.py so that when matching a gitignore pattern from a parent anchor against a target in absolute (non-path_relative) mode, it recomputes the relative path against the scan root rather than the pattern's anchor in cases where the root is deeper than the anchor. The intent, per the referenced issue #2468, is to prevent a parent .gitignore that ignores the scan root directory itself from causing files inside that scan root to be excluded, while still honoring unrelated parent ignore patterns. Two new tests are added to tests/test_detect.py covering the scan-root-ignored case and the case where an unrelated node_modules/ rule from the parent should still apply.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1252 functions depend on the 435 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: detect() — 84 callers, 11 callees

Verification — 1252 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 668 function(s) in the blast radius were not formally verified this run

· 1 more finding(s) on lines outside this diff (see the check run).

safishamsi added a commit that referenced this pull request Aug 12, 2026
 follow-up)

The #2475 fix recomputed the match path against the explicit scan root but
skipped the _nfc() normalization rel_anchor gets, so an NFD-named path
could miss a parent ignore pattern under the #2544 NFC-matching regime.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.41 (graphifyy==0.9.41 on PyPI) (#2468), with an NFC follow-up. Credited in the release notes. Thanks @hopstreax!

@safishamsi safishamsi closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants