fix(linter): respect .gitignore regardless of if a git repo is initialized#17375
Conversation
.gitignore regardless of if a git repo is initialized
You were correct! The initial test was passing even without the changes because it was using explicit I've updated the implementation to include both
The key insight was that Commit: d32a50a |
|
@copilot fix CI |
|
@Boshen mind taking a quick look? |
There was a problem hiding this comment.
Pull request overview
This PR enables oxlint to respect .gitignore files even when a Git repository hasn't been initialized (i.e., when there's no .git directory). This resolves unexpected behavior where .gitignore files were only honored in initialized Git repositories.
Key Changes
- Modified
WalkBuilderconfiguration to explicitly enable.gitignoreprocessing and remove the Git repository requirement - Added comprehensive unit test validating
.gitignoreauto-discovery without.gitdirectory - Improved code formatting for the builder chain
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge activity
|
…ialized (#17375) ## Plan: Enable oxlint to read gitignore without git repo initialization - [x] Analyze the issue and understand the problem - [x] Add `.require_git(false)` and `.git_ignore(true)` to WalkBuilder in walk.rs - [x] Create a proper unit test in walk.rs that validates auto-discovery of .gitignore files - [x] Verify test fails without the settings and passes with them - [x] Remove old integration test that didn't properly test the fix - [x] Run all tests to ensure no regressions - [x] Verify the fix manually with CLI - [x] Fix formatting issues for CI <!-- START COPILOT CODING AGENT SUFFIX --> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > update oxlint to read from the gitignore even if the git repo has not been initialized </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
9c6662e to
fec2863
Compare
… .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.
…o boundaries Switches `require_git(false)` to `require_git(true)` in the oxlint and oxfmt walkers. **The problem:** `require_git(false)` (introduced in oxc-project#17375) makes the `ignore` crate read `.gitignore` files from directories *above* the git root, which differs from standard git behaviour. This causes a concrete bug in nested git repositories: `parent_repo/.gitignore` incorrectly filters files inside `parent_repo/child_repo/`, which has its own `.git`. **Why `require_git(true)` fixes it:** The `ignore` crate already implements correct git-boundary logic via a `saw_git` flag in `matched_ignore`. When iterating parent directories from innermost to outermost, `saw_git` becomes `true` at the innermost `.git` boundary, preventing gitignore rules from any outer repository from applying. `require_git(true)` activates this standard git behaviour. **Alternative discarded workarounds:** `parents(false)` was a workaround idea for the nested-repo bug. That would cause a regression where `oxlint src/` would not pick up `.gitignore` rules from the repo root above `src/`. **Trade-off:** `.gitignore` rules no longer apply when there is no `.git` ancestor anywhere in the directory tree. This reverts the behaviour added in oxc-project#17375. Reverts oxc-project#17375
…s nested repos Detects at runtime whether the walked paths are inside a git repository and sets `require_git` accordingly — `true` inside a git repo (activating correct git-boundary behaviour), `false` outside (preserving the behaviour introduced in oxc-project#17375 where `.gitignore` rules apply even without a `.git` ancestor). **The problem:** `require_git(false)` (introduced in oxc-project#17375) makes the `ignore` crate read `.gitignore` files from directories *above* the git root, which differs from standard git behaviour. This causes a concrete bug in nested git repositories: `parent_repo/.gitignore` incorrectly filters files inside `parent_repo/child_repo/`, which has its own `.git`. **Why `require_git(true)` fixes it:** The `ignore` crate already implements correct git-boundary logic via a `saw_git` flag in `matched_ignore`. When iterating parent directories from innermost to outermost, `saw_git` becomes `true` at the innermost `.git` boundary, preventing gitignore rules from any outer repository from applying. `require_git(true)` activates this standard git behaviour. **Trade-off:** None — the dynamic detection preserves oxc-project#17375 behaviour for non-git directories while fixing the nested-repo bug for git repos.
…s nested repos Detects at runtime whether the walked paths are inside a git repository and sets `require_git` accordingly — `true` inside a git repo (activating correct git-boundary behaviour), `false` outside (preserving the behaviour introduced in oxc-project#17375 where `.gitignore` rules apply even without a `.git` ancestor). **The problem:** `require_git(false)` (introduced in oxc-project#17375) makes the `ignore` crate read `.gitignore` files from directories *above* the git root, which differs from standard git behaviour. This causes a concrete bug in nested git repositories: `parent_repo/.gitignore` incorrectly filters files inside `parent_repo/child_repo/`, which has its own `.git`. **Why `require_git(true)` fixes it:** The `ignore` crate already implements correct git-boundary logic via a `saw_git` flag in `matched_ignore`. When iterating parent directories from innermost to outermost, `saw_git` becomes `true` at the innermost `.git` boundary, preventing gitignore rules from any outer repository from applying. `require_git(true)` activates this standard git behaviour. **Trade-off:** None — the dynamic detection preserves oxc-project#17375 behaviour for non-git directories while fixing the nested-repo bug for git repos.
…s nested repos Detects at runtime whether the walked paths are inside a git repository and sets `require_git` accordingly — `true` inside a git repo (activating correct git-boundary behaviour), `false` outside (preserving the behaviour introduced in oxc-project#17375 where `.gitignore` rules apply even without a `.git` ancestor). **The problem:** `require_git(false)` (introduced in oxc-project#17375) makes the `ignore` crate read `.gitignore` files from directories *above* the git root, which differs from standard git behaviour. This causes a concrete bug in nested git repositories: `parent_repo/.gitignore` incorrectly filters files inside `parent_repo/child_repo/`, which has its own `.git`. **Why `require_git(true)` fixes it:** The `ignore` crate already implements correct git-boundary logic via a `saw_git` flag in `matched_ignore`. When iterating parent directories from innermost to outermost, `saw_git` becomes `true` at the innermost `.git` boundary, preventing gitignore rules from any outer repository from applying. `require_git(true)` activates this standard git behaviour. **Trade-off:** None — the dynamic detection preserves oxc-project#17375 behaviour for non-git directories while fixing the nested-repo bug for git repos.
…o boundaries Switches `require_git(false)` to `require_git(true)` in the oxlint and oxfmt walkers. **The problem:** `require_git(false)` (introduced in oxc-project#17375) makes the `ignore` crate read `.gitignore` files from directories *above* the git root, which differs from standard git behaviour. This causes a concrete bug in nested git repositories: `parent_repo/.gitignore` incorrectly filters files inside `parent_repo/child_repo/`, which has its own `.git`. **Why `require_git(true)` fixes it:** The `ignore` crate already implements correct git-boundary logic via a `saw_git` flag in `matched_ignore`. When iterating parent directories from innermost to outermost, `saw_git` becomes `true` at the innermost `.git` boundary, preventing gitignore rules from any outer repository from applying. `require_git(true)` activates this standard git behaviour. **Alternative discarded workarounds:** `parents(false)` was a workaround idea for the nested-repo bug. That would cause a regression where `oxlint src/` would not pick up `.gitignore` rules from the repo root above `src/`. **Trade-off:** `.gitignore` rules no longer apply when there is no `.git` ancestor anywhere in the directory tree. This reverts the behaviour added in oxc-project#17375. Reverts oxc-project#17375
…o boundaries Switches `require_git(false)` to `require_git(true)` in the oxlint and oxfmt walkers. **The problem:** `require_git(false)` (introduced in oxc-project#17375) makes the `ignore` crate read `.gitignore` files from directories *above* the git root, which differs from standard git behaviour. This causes a concrete bug in nested git repositories: `parent_repo/.gitignore` incorrectly filters files inside `parent_repo/child_repo/`, which has its own `.git`. **Why `require_git(true)` fixes it:** The `ignore` crate already implements correct git-boundary logic via a `saw_git` flag in `matched_ignore`. When iterating parent directories from innermost to outermost, `saw_git` becomes `true` at the innermost `.git` boundary, preventing gitignore rules from any outer repository from applying. `require_git(true)` activates this standard git behaviour. **Alternative discarded workarounds:** `parents(false)` was a workaround idea for the nested-repo bug. That would cause a regression where `oxlint src/` would not pick up `.gitignore` rules from the repo root above `src/`. **Trade-off:** `.gitignore` rules no longer apply when there is no `.git` ancestor anywhere in the directory tree. This reverts the behaviour added in oxc-project#17375. Reverts oxc-project#17375
Plan: Enable oxlint to read gitignore without git repo initialization
.require_git(false)and.git_ignore(true)to WalkBuilder in walk.rsOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.