Skip to content

fix(linter): skip looking for ignore files in parent directories#17813

Closed
camc314 wants to merge 1 commit into
mainfrom
c/01-08-fix_linter_skip_looking_for_ignore_files_in_parent_directories
Closed

fix(linter): skip looking for ignore files in parent directories#17813
camc314 wants to merge 1 commit into
mainfrom
c/01-08-fix_linter_skip_looking_for_ignore_files_in_parent_directories

Conversation

@camc314

@camc314 camc314 commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

fixes #17805
closes #17513
fixes #17510

@github-actions github-actions Bot added A-linter Area - Linter A-cli Area - CLI labels Jan 8, 2026

camc314 commented Jan 8, 2026

Copy link
Copy Markdown
Contributor Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@hirehamir

Copy link
Copy Markdown
Contributor

@camc314, is there anything I can do to help this get merged?

@goloveychuk

Copy link
Copy Markdown

this issue become more prominent when many devs are using ai agents + git worktrees.
@camc314 @imawizard can you please merge?

@fabb

fabb commented Apr 1, 2026

Copy link
Copy Markdown

i ran into this issue today, and took quite a long time to pinpoint. please get this merged.

i have nested git repos, even without using worktrees. i have put my home dir under git management and have * in my ~/.gitignore so i can only force-add files to it. this is very practical for me, and i'd like not to have changing my workflow.

@fabb

fabb commented Apr 2, 2026

Copy link
Copy Markdown

TLDR: i'd NOT merge this PR, and rather enable require_git(true) either hard coded or dependent on whether in a git repo or not. i've created 2 alternative PRs for that: #20951 and #20952

i researched it again, and .parents(false) could cause legitimate parent .gitignore files of the same git repo not to be applied correctly, when the walker starts in a subfolder.

The proper fix would be to set .require_git(true). I see it was set to false explicitly in #17375, but i fear we cannot have both. IMHO working correctly in git repos is more important.

Full example:

* /parent_repo/.git                                                                                                                                     
* /parent_repo/.gitignore <---- should NOT apply when current folder is /parent_repo/child_repo/sub_path                                                                                                         
* /parent_repo/child_repo/.git                                                                                                                 
* /parent_repo/child_repo/.gitignore
* /parent_repo/child_repo/sub_path/.gitignore    

fabb added a commit to fabb/oxc that referenced this pull request Apr 2, 2026
… .gitignore

Switches `require_git(false)` to `require_git(true)` in both the oxlint
and oxfmt walkers, and reverts the `parents(false)` workaround added in
oxc-project#17813 (oxlint only).

**Background:** `require_git(false)` was introduced in oxc-project#17375 so that
`.gitignore` rules would apply even in directories without a `.git` file.
A side-effect is that the `ignore` crate reads `.gitignore` files from
directories *above* the git root, which is non-standard git behaviour.
This caused a concrete bug: when linting inside a nested git repo
(`parent_repo/child_repo/`), the parent repo's `.gitignore` incorrectly
filtered files in the child repo.

**Why require_git(true) is the right fix:** The `ignore` crate's
`matched_ignore` already implements the correct git-boundary logic via a
`saw_git` flag. When iterating parent directories from innermost to
outermost, `saw_git` is set to `true` the moment the innermost `.git`
directory is encountered, preventing gitignore rules from any outer
repository from being applied. Setting `require_git(true)` activates this
standard behaviour.

**Why parents(false) can be reverted (oxlint):** `parents(false)` was a
workaround for the nested-repo bug. With `require_git(true)` the `saw_git`
mechanism handles this correctly, so `parents(true)` can be restored.
This also fixes the regression where running `oxlint src/` would fail to
pick up `.gitignore` rules from the repo root sitting above `src/`.

**Trade-off:** `.gitignore` rules no longer apply in directories that have
no `.git` ancestor. This reverts the behaviour added in oxc-project#17375.
graphite-app Bot pushed a commit that referenced this pull request May 1, 2026
This regressed in oxlint v1.36.0 (fec2863)

This is caused by the walker configuring `ignore` with `.require_git(false)`, which makes `.gitignore` files from parent directories above the current repository apply to the walk. That differs from Git behavior, where `.gitignore` lookup stops at the working tree root.

Here is how we handle it:

- detect whether all walk roots are inside a Git/JJ repository boundary
- enable `require_git(true)` for repository walks so parent `.gitignore` files above the repo boundary are ignored
- keep `require_git(false)` for non-repository walks so local `.gitignore` files still work outside Git repos
- add regression coverage for nested repositories, worktree-style `.git` files, and subdirectory walks inside a repo

Here is how the `ignore` crate checks for git directories:

- when `require_git(true)` is enabled, it records whether each directory has a `.git` or `.jj` entry
- while matching `.gitignore` rules, it applies parent gitignore matchers only until it has seen that repository boundary
- `.git` files are handled as boundaries too, which covers Git worktrees

Fixes #17510.
Fixes #17805.
Fixes #19902.
Closes #21727.
Closes #17513.
Closes #17813.
Closes #20951.
Closes #20952.
@graphite-app graphite-app Bot closed this in #22033 May 1, 2026
@camc314

camc314 commented May 2, 2026

Copy link
Copy Markdown
Contributor Author

Fixed by #22033

The fix should be released on Monday (May 4th) (or possibly tuesday due to the holiday).

@Boshen
Boshen deleted the c/01-08-fix_linter_skip_looking_for_ignore_files_in_parent_directories branch May 31, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: home directory gitignore breaks oxlint npx oxlint . checks 26 files with Version: 1.31.0 but 0 files with Version: 1.36.0

4 participants