Honour repository boundaries in the ignore-file search; filter hidden dirs relative to include roots - #4402
Open
willemkokke wants to merge 2 commits into
Open
Conversation
added 2 commits
August 1, 2026 19:13
The upward search for .gitignore/.ignore/.git/info/exclude treated the directory tree as one hierarchy: from a linked worktree (whose .git is a gitdir pointer file, not a directory) it sailed past the working-tree root, found the enclosing checkout's .git/info/exclude, and applied its patterns rooted at the enclosing checkout. A pattern like '.claude/worktrees/' in a main checkout's exclude file (how several agent tools register their worktrees) then matched every file inside the worktree, and pyrefly skipped all of the project's includes with 'No Python files matched'. git's own semantics: a directory carrying a .git entry (file or directory) is a working-tree root; an outer repository's ignore rules never apply inside it, and the repository's shared info/exclude applies to each worktree relative to that worktree's own root. The search now walks upward collecting the nearest .gitignore and .ignore, stops at the first directory with a .git entry, and resolves info/exclude through the gitdir pointer and commondir for linked worktrees -- rooted at the working tree being checked.
The RelativeTo hidden-directory allowance carried only import_root, so for a src-layout project (import_root = src/) any include outside it -- tests/check.py -- fell back to absolute-path component checking, where a checkout under a hidden directory (~/.codex/worktrees/..., .claude/worktrees/...) has every path hidden and the include was skipped. The roots are now every include root plus the import root. Also decouples the allowance from use_ignore_files: the root list was only populated when ignore files were enabled, so --use-ignore-files= false degraded the filter to HiddenDirFilter::All and made hidden- directory filtering stricter -- disabling one exclusion mechanism silently hardened another.
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D114483806. (Because this pull request was imported automatically, there will not be any future comments.) |
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.
Fixes #4401. Two commits, one per mechanism:
1.
find_ignore_fileshonours repository boundaries the way git does (pyrefly_util/globs.rs)The upward search for
.gitignore/.ignore/.git/info/excludetreated the directory tree as one hierarchy: from a linked worktree (whose.gitis agitdir:pointer file, not a directory) it walked past the working-tree root, found the enclosing checkout's.git/info/exclude, and applied its patterns rooted at the enclosing checkout — so a pattern like**/.claude/worktrees/in the main checkout's exclude file matched every file inside the worktree and all includes were skipped.The search now collects the nearest
.gitignoreand.ignorewalking upward, stops at the first directory carrying a.gitentry (file or directory — the working-tree root), and resolvesinfo/excludethrough thegitdirpointer andcommondirfor linked worktrees, rooted at the working tree being checked — matchinggit check-ignore's verdicts. The memoizedUpwardSearchstatics are replaced by a direct ancestor walk; it runs once perGlobFilterconstruction and is O(depth) file stats.2.
HiddenDirFilter::RelativeTois built from every include root plus the import root (pyrefly_config/config.rs)Follow-up to #2402: the allowance carried only
import_root, so for a src-layout project (import_root = src/) an include outside it (tests/check.py) fell back to absolute-path component checking and was hidden by the checkout's own ancestors. Also decoupled fromuse_ignore_files, which previously degraded the filter toAllwhen ignore files were turned off — disabling one exclusion mechanism silently hardened another.Tests: two new tests in
globs.rs(nested-repository boundary; linked worktree withgitdir+commondirresolution, asserting the shared exclude file still applies but relative to the worktree root); the existingtest_get_filtered_globs_coverage_scopeexpectation updated to the newRelativeToconstruction.cargo test -p pyrefly_util -p pyrefly_configpasses (318 tests).Verified end to end on the real-world layout that surfaced this (a
.claude/worktrees/…checkout of a src-layout project whose main checkout excludes**/.claude/worktrees/): before, every include was skipped; after, the project checks clean with all-default settings, in both--use-ignore-filesstates.