Skip to content

Conversation

@EricRahm
Copy link
Contributor

The gitignore parser was incorrectly processing patterns containing backslash-escaped characters (e.g., \#, \!, '\ '). This was caused by an aggressive path normalization step that replaced all backslashes with forward slashes, corrupting the escape sequence before it could be interpreted by the ignore library.

This resulted in patterns intended to ignore files with special names (like #foo) being misinterpreted, causing those files to be incorrectly processed instead of ignored.

This commit addresses the issue by:

  • Removing the incorrect string replacement for path normalization.
  • Switching to path.posix.join for path manipulation to ensure consistent, cross-platform behavior with forward slashes, as expected by the underlying ignore library.

These changes ensure that escaped patterns are passed to the ignore library unmodified, restoring the correct gitignore behavior as specified in the gitignore man pages.

TLDR

The gitignore parser is replacing ignore pattern escape sequences with forward slashes.

Dive Deeper

The gitignore parser was incorrectly processing patterns containing backslash-escaped characters (e.g., \#, \!, '\ '). This was caused by an aggressive path normalization step that replaced all backslashes with forward slashes, corrupting the escape sequence before it could be interpreted by the ignore library.

This resulted in patterns intended to ignore files with special names (like #foo) being misinterpreted, causing those files to be incorrectly processed instead of ignored.

This commit addresses the issue by:

  • Removing the incorrect string replacement for path normalization.
  • Switching to path.posix.join for path manipulation to ensure consistent, cross-platform behavior with forward slashes, as expected by the underlying ignore library.

These changes ensure that escaped patterns are passed to the ignore library unmodified, restoring the correct gitignore behavior as specified in the gitignore man pages.

Reviewer Test Plan

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Fixes #11168

@EricRahm EricRahm requested a review from a team as a code owner October 15, 2025 00:30
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @EricRahm, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the gitignore parser where patterns containing backslash-escaped characters were misinterpreted. The root cause was an overzealous path normalization step that inadvertently corrupted these escape sequences. The fix involves removing the problematic string replacement and adopting path.posix.join for all path manipulations, ensuring that the ignore library receives patterns exactly as intended, thereby restoring correct gitignore behavior for special file names.

Highlights

  • Fixes Gitignore Escaped Characters: The pull request resolves an issue where backslash-escaped characters in .gitignore patterns (e.g., \#, \!) were incorrectly processed, leading to files not being ignored as intended.
  • Path Normalization Refinement: The aggressive string replacement that converted all backslashes to forward slashes, corrupting escape sequences, has been removed. Path manipulation now uses path.posix.join for consistent, cross-platform behavior with forward slashes.
  • Improved Test Coverage: A new test suite has been added to gitIgnoreParser.test.ts specifically to verify the correct handling of escaped characters in .gitignore patterns.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses a bug in the gitignore parser where backslash-escaped characters were being incorrectly processed. The root cause was an aggressive path normalization step that replaced all backslashes, which corrupted escape sequences in gitignore patterns. The fix correctly removes this string replacement and switches to using path.posix.join for path manipulation. This ensures that paths consistently use forward slashes, as expected by the underlying ignore library, without corrupting the patterns. The addition of a specific test case for escaped characters is excellent, as it directly validates the fix. The changes are well-targeted and correctly resolve the issue.

@@ -89,9 +92,6 @@ export class GitIgnoreParser implements GitIgnoreFilter {
newPattern = '!' + newPattern;
}

// Even in windows, Ignore expects forward slashes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

have you tested this on windows? need to make sure these changes do not break windows support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the quick review, I'm getting a windows dev environment setup and will report back!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I now have a windows machine setup and have tested this locally.

I added three files with special names:

  • packages/core/#foo.js
  • packages/core/src/tools/#foo.js
  • packages/core/src/utils/#foo.js

I setup my .gitignore to ignore all #foo.js (this requires an escape character) by default but explicitly allow two of the files:

\#foo.js
!packages/core/#foo.js
!packages/core/src/utils/#foo.js

I then asked gemini-cli to find all the #foo.js files, we see it find the 2 that are allowed, but it does not find the 3rd as expected by the the .gitignore configuration.

Copy link
Collaborator

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtm

The gitignore parser was incorrectly processing patterns containing
backslash-escaped characters (e.g., `\#`, `\!`, '\ '). This was caused
by an aggressive path normalization step that replaced all backslashes
with forward slashes, corrupting the escape sequence before it could be
interpreted by the `ignore` library.

This resulted in patterns intended to ignore files with special names
(like `#foo`) being misinterpreted, causing those files to be
incorrectly processed instead of ignored.

This commit addresses the issue by:
- Removing the incorrect string replacement for path normalization.
- Switching to `path.posix.join` for path manipulation to ensure
  consistent, cross-platform behavior with forward slashes, as
  expected by the underlying `ignore` library.

These changes ensure that escaped patterns are passed to the `ignore`
library unmodified, restoring the correct gitignore behavior as
specified in the gitignore man pages.
@jacob314 jacob314 added this pull request to the merge queue Oct 20, 2025
Merged via the queue into google-gemini:main with commit 518a9ca Oct 20, 2025
19 checks passed
thacio added a commit to thacio/auditaria that referenced this pull request Oct 21, 2025
cocosheng-g pushed a commit to cocosheng-g/gemini-cli that referenced this pull request Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backslash-escaped characters in gitignore patterns are incorrectly processed

2 participants