Skip to content

fix(core): match ls ignore globs by relative path#28247

Open
JSap0914 wants to merge 1 commit into
google-gemini:mainfrom
JSap0914:fix/ls-ignore-relative-globs-28207
Open

fix(core): match ls ignore globs by relative path#28247
JSap0914 wants to merge 1 commit into
google-gemini:mainfrom
JSap0914:fix/ls-ignore-relative-globs-28207

Conversation

@JSap0914

@JSap0914 JSap0914 commented Jul 3, 2026

Copy link
Copy Markdown

Summary

  • match ls ignore patterns containing path separators against workspace-relative paths instead of only basenames
  • use picomatch so ** glob patterns work as expected
  • preserve existing basename-only behavior for patterns like *.log

Fixes #28207

Verification

  • npm ci --ignore-scripts
  • npx vitest run packages/core/src/tools/ls.test.ts (25 passed)
  • npm run generate
  • npm run typecheck --workspace @google/gemini-cli-core
  • npx prettier --check packages/core/src/tools/ls.ts packages/core/src/tools/ls.test.ts

@JSap0914 JSap0914 requested a review from a team as a code owner July 3, 2026 07:32
@google-cla

google-cla Bot commented Jul 3, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 enhances the file listing tool's ignore logic to better handle complex directory structures. By transitioning to picomatch and enabling path-relative matching, users can now effectively exclude files using glob patterns that account for directory depth, while preserving the simplicity of existing basename-based filtering.

Highlights

  • Improved Ignore Pattern Matching: Updated the ls tool to support path-aware ignore patterns by matching against workspace-relative paths when separators are present.
  • Integration of picomatch: Replaced custom regex-based matching with picomatch to provide robust glob support, including globstar (**) functionality.
  • Backward Compatibility: Maintained existing behavior for simple basename-only patterns (e.g., *.log) to ensure no breaking changes for standard file filters.
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 the 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 counterproductive. 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.

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.

@github-actions github-actions Bot added the size/m A medium sized PR label Jul 3, 2026
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 72
  • Additions: +60
  • Deletions: -12
  • Files changed: 2

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the LSTool to support workspace-relative and globstar ignore patterns by integrating picomatch and matching against relative paths. While the new functionality is well-tested, compiling the glob patterns with picomatch inside the loop for every file is inefficient. It is recommended to compile and cache these matchers on the invocation instance to avoid performance degradation in directories with many files.

Comment on lines 110 to 118
for (const pattern of patterns) {
// Convert glob pattern to RegExp
const regexPattern = pattern
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
.replace(/\*/g, '.*')
.replace(/\?/g, '.');
const regex = new RegExp(`^${regexPattern}$`);
if (regex.test(filename)) {
const normalizedPattern = pattern.replace(/\\/g, '/');
const hasPathSeparator = normalizedPattern.includes('/');
const matcher = picomatch(normalizedPattern, { dot: true });

if (matcher(hasPathSeparator ? normalizedPath : filename)) {
return true;
}
}

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.

high

Compiling glob patterns with picomatch inside the loop for every single file is highly inefficient. For directories with many files, this will repeatedly parse and compile the same patterns, leading to significant performance degradation.

To optimize this, compile the matchers once and cache them on the invocation instance (this) to avoid global state and prevent race conditions in concurrent environments.

    const self = this as any;
    if (!self._compiledMatchers) {
      self._compiledMatchers = patterns.map((pattern) => {
        const normalizedPattern = pattern.replace(/\\/g, '/');
        return {
          hasPathSeparator: normalizedPattern.includes('/'),
          matcher: picomatch(normalizedPattern, { dot: true }),
        };
      });
    }

    for (const { hasPathSeparator, matcher } of self._compiledMatchers) {
      if (matcher(hasPathSeparator ? normalizedPath : filename)) {
        return true;
      }
    }
References
  1. Avoid module-level global variables for state like caches to prevent race conditions and memory issues in concurrent environments. Instead, use session-scoped or instance-scoped state.

@gemini-cli

gemini-cli Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'.

This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ignore patterns in ls tool do not work for path-relative/nested globs

1 participant