Skip to content

fix: respect gitignore exceptions during workspace scans - #3513

Open
Mohamed-El-Mouhib wants to merge 2 commits into
LuaLS:masterfrom
Mohamed-El-Mouhib:fix/gitignore-workspace-negation
Open

Mohamed-El-Mouhib wants to merge 2 commits into
LuaLS:masterfrom
Mohamed-El-Mouhib:fix/gitignore-workspace-negation

Conversation

@Mohamed-El-Mouhib

@Mohamed-El-Mouhib Mohamed-El-Mouhib commented Dec 3, 2026 •

Copy link
Copy Markdown

Fixes #3503.

Problem

A workspace with *, !*/, and !*.lua in .gitignore can be skipped entirely because * matches the empty relative path at its root. Directory-only exceptions also match a parent prefix of a file, and directory type lookups use the relative path instead of the workspace path. After scanning, the cached directory type is replaced by a boolean, which can cause isIgnored to disagree with the scan.

Changes

  • Match gitignore rules against complete entries, keeping the separate glob.glob prefix behavior unchanged. Keep the end assertion inside wildcard alternatives so a later path component can match.
  • Never match the empty workspace-relative path; evaluate each ancestor and the entry independently, preserving last-match ordering and excluded-parent semantics.
  • Resolve directory checks against the workspace root and retain the directory type in the scan cache.
  • Add regression coverage for nested exceptions, ignored parents, ordering, wildcard cases, root boundaries, simulated Windows paths/case, and the actual workspace scan plus isIgnored integration. Update the changelog as required.

Validation

  • Current upstream a58fc7b fails the new matcher regression and reports no problems on a real three-file Git fixture. The patched version reports the three expected undefined globals, excluding the explicitly blocked directory (matches git ls-files -o --exclude-standard).
  • The new workspace integration test also caught the cached-directory-type problem before that correction.
  • Full test.lua suite passed using the 3.19.2 macOS arm64 release executable with the current checkout's Lua sources; basic and tclient passed separately. After whitespace-only cleanup, basic passed again.
  • Lua syntax and git diff --check passed; bundled code-style diagnostics show no added warnings relative to upstream. Native Windows execution and a source rebuild of the native executable were not performed.

Follow-up validation

Comparing 1,599 pattern/path combinations against git check-ignore exposed a regression for standalone patterns containing literal commas and braces. The follow-up separates standalone parsing from the existing leading-brace group syntax, preserves escaped punctuation, and adds basic and real workspace-scan regression coverage. The new cases fail before the follow-up and pass after it. The final comparison has no introduced mismatches, 100 improvements, and 10 remaining preexisting differences; this is not a claim of complete Git compatibility. Unescaped leading braces intentionally retain legacy group syntax.

The previous head's GitHub Actions macOS ARM64 build job ran both native and Lua test suites successfully. Its separate macOS test job was cancelled because the runner configuration was unavailable (also reproduced on upstream). The follow-up's complete local suite passed with the downloaded ARM64 build artifact and matching source; final basic and tclient suites also passed after strengthening URI assertions. An earlier local full-suite run failed during coroutine readiness; this was not reproduced in the follow-up run. New-head CI is separate and must still run.

Fixes LuaLS#3503. Regression tests cover directory negation and actual workspace loading. AI assistance: ChatGPT.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 17:12

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings December 3, 2026 18:09

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

.gitignore starting with * and re-including files via ! patterns ignores the whole workspace

2 participants