Skip to content

fix(linter): respect .gitignore regardless of if a git repo is initialized#17375

Merged
graphite-app[bot] merged 1 commit into
mainfrom
copilot/update-oxlint-gitignore-reading
Dec 27, 2025
Merged

fix(linter): respect .gitignore regardless of if a git repo is initialized#17375
graphite-app[bot] merged 1 commit into
mainfrom
copilot/update-oxlint-gitignore-reading

Conversation

Copilot AI commented Dec 26, 2025

Copy link
Copy Markdown
Contributor

Plan: Enable oxlint to read gitignore without git repo initialization

  • Analyze the issue and understand the problem
  • Add .require_git(false) and .git_ignore(true) to WalkBuilder in walk.rs
  • Create a proper unit test in walk.rs that validates auto-discovery of .gitignore files
  • Verify test fails without the settings and passes with them
  • Remove old integration test that didn't properly test the fix
  • Run all tests to ensure no regressions
  • Verify the fix manually with CLI
  • Fix formatting issues for CI
Original prompt

update oxlint to read from the gitignore even if the git repo has not been initialized


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update oxlint to read from .gitignore without initialization Enable oxlint to read .gitignore without git repository initialization Dec 26, 2025
Copilot AI requested a review from camc314 December 26, 2025 17:34
Comment thread apps/oxlint/src/walk.rs
@github-actions github-actions Bot added A-linter Area - Linter A-cli Area - CLI labels Dec 26, 2025
@camc314 camc314 changed the title Enable oxlint to read .gitignore without git repository initialization fix(linter): respect .gitignore regardless of if a git repo is initialized Dec 26, 2025
@github-actions github-actions Bot added the C-bug Category - Bug label Dec 26, 2025

@camc314 camc314 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot if i comment out require_git the tests still pass - is this because we're in the root oxc repo?

comment out the change, write a failing test, that then passes if you un-comment it out

Copilot AI commented Dec 26, 2025

Copy link
Copy Markdown
Contributor Author

@copilot if i comment out require_git the tests still pass - is this because we're in the root oxc repo?

comment out the change, write a failing test, that then passes if you un-comment it out

You were correct! The initial test was passing even without the changes because it was using explicit .gitignore loading via ignore_path instead of testing auto-discovery.

I've updated the implementation to include both .git_ignore(true) and .require_git(false), and created a proper unit test in walk.rs that:

  • Uses auto-discovery (empty ignore_path) to test the actual feature
  • Fails without the settings (finds both files)
  • Passes with the settings (only finds non-ignored file)

The key insight was that .git_ignore(true) enables auto-discovery of .gitignore files, and .require_git(false) allows this to work without a .git directory. The old test bypassed auto-discovery entirely.

Commit: d32a50a

Copilot AI requested a review from camc314 December 26, 2025 18:10
@camc314

camc314 commented Dec 26, 2025

Copy link
Copy Markdown
Contributor

@copilot fix CI

Copilot AI commented Dec 26, 2025

Copy link
Copy Markdown
Contributor Author

@copilot fix CI

Fixed formatting issues in walk.rs. The CI was failing due to trailing whitespace and incorrect comment spacing. Commit: fb72dac

@camc314
camc314 marked this pull request as ready for review December 26, 2025 20:48
Copilot AI review requested due to automatic review settings December 26, 2025 20:48
@camc314 camc314 assigned Boshen, camc314 and Copilot and unassigned camc314 and Copilot Dec 26, 2025
@camc314

camc314 commented Dec 26, 2025

Copy link
Copy Markdown
Contributor

@Boshen mind taking a quick look?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 WalkBuilder configuration to explicitly enable .gitignore processing and remove the Git repository requirement
  • Added comprehensive unit test validating .gitignore auto-discovery without .git directory
  • Improved code formatting for the builder chain

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Dec 27, 2025

Boshen commented Dec 27, 2025

Copy link
Copy Markdown
Member

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).
@graphite-app
graphite-app Bot force-pushed the copilot/update-oxlint-gitignore-reading branch from 9c6662e to fec2863 Compare December 27, 2025 04:10
@graphite-app
graphite-app Bot merged commit fec2863 into main Dec 27, 2025
18 checks passed
@graphite-app
graphite-app Bot deleted the copilot/update-oxlint-gitignore-reading branch December 27, 2025 04:16
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Dec 27, 2025

@fabb fabb 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.

this PR introduces a bug with nested git repos, see #20951

Comment thread apps/oxlint/src/walk.rs
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.
fabb added a commit to fabb/oxc that referenced this pull request Apr 2, 2026
…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
fabb added a commit to fabb/oxc that referenced this pull request Apr 2, 2026
…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.
fabb added a commit to fabb/oxc that referenced this pull request Apr 2, 2026
…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.
fabb added a commit to fabb/oxc that referenced this pull request Apr 2, 2026
…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.
fabb added a commit to fabb/oxc that referenced this pull request Apr 2, 2026
…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
fabb added a commit to fabb/oxc that referenced this pull request Apr 2, 2026
…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
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.

5 participants