Skip to content

Use the contents of .git/info/exclude when useGitignore is set to true. Fixes #375#391

Merged
yamadashy merged 2 commits intoyamadashy:mainfrom
motlin:git-info-exclude
Mar 8, 2025
Merged

Use the contents of .git/info/exclude when useGitignore is set to true. Fixes #375#391
yamadashy merged 2 commits intoyamadashy:mainfrom
motlin:git-info-exclude

Conversation

@motlin
Copy link
Contributor

@motlin motlin commented Mar 6, 2025

Checklist

  • Run npm run test
  • Run npm run lint

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

📝 Walkthrough

Walkthrough

The pull request enhances the getIgnorePatterns function in src/core/file/fileSearch.ts by incorporating ignore patterns from the .git/info/exclude file when the useGitignore configuration option is enabled. The function now constructs the file path for .git/info/exclude and attempts to read it asynchronously. On successful file reading, the content is parsed into ignore patterns that are added to the existing set. In the event of a read failure—due to file absence or access issues—a trace message is logged without interrupting the execution flow. Additionally, a new test case has been added in the test suite to verify that the patterns from the Git exclusion file are correctly included when the corresponding configuration is active.

Sequence Diagram(s)

sequenceDiagram
    participant FS as getIgnorePatterns
    participant CFG as Configuration
    participant FSYS as File System
    participant LOGGER as Logger

    FS->>CFG: Check useGitignore option
    alt useGitignore is true
        FS->>FSYS: Construct .git/info/exclude path and read file
        alt File read is successful
            FSYS-->>FS: Return file content
            FS->>FS: Parse content and add patterns
        else File read fails
            FSYS-->>FS: Return error or no content
            FS->>LOGGER: Log trace message
        end
    else useGitignore is false
        FS->>FS: Proceed without .git/info/exclude patterns
    end
Loading

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf60ab4 and 7e0d28c.

📒 Files selected for processing (2)
  • src/core/file/fileSearch.ts (1 hunks)
  • tests/core/file/fileSearch.test.ts (1 hunks)
🔇 Additional comments (2)
src/core/file/fileSearch.ts (1)

223-238:

Details

✅ Verification successful

Implementation looks good! A few minor points to consider.

The implementation correctly reads .git/info/exclude patterns when useGitignore is enabled. The error handling is appropriate, as it gracefully handles cases where the file doesn't exist or can't be read.

Two small considerations:

  1. The implementation follows the existing pattern in the codebase, which is good for consistency.
  2. The error handling logs a trace message without interrupting execution, which is the correct behavior since .git/info/exclude is optional.

🏁 Script executed:

#!/bin/bash
# Verify potential usage in other functions or places where gitignore is handled

# Check if there are other places in the codebase where .gitignore is handled
# that might need similar .git/info/exclude handling
rg -A 2 -B 2 "\.gitignore" --type ts

Length of output: 8465


Code Consistency & Error Handling Confirmed

The code in src/core/file/fileSearch.ts correctly reads and parses the contents of the .git/info/exclude file when useGitignore is enabled. The try-catch block ensures that any issues—such as the file not existing or being inaccessible—don’t interrupt execution, and the error is appropriately logged at trace level. This implementation aligns with the existing approach for handling .gitignore files elsewhere in the codebase.

  • The use of await fs.readFile combined with parseIgnoreContent is implemented as expected.
  • Error handling via logger.trace maintains non-disruptive execution for optional configurations.

Overall, the implementation is solid and consistent with our patterns.

tests/core/file/fileSearch.test.ts (1)

147-174: Test case is thorough and properly validates the new functionality.

The test correctly verifies that patterns from .git/info/exclude are included when useGitignore is true. It uses appropriate mocking techniques and makes specific assertions about the expected patterns.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@yamadashy yamadashy requested review from Copilot and yamadashy and removed request for yamadashy March 8, 2025 06:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR implements the feature to include patterns from the .git/info/exclude file when the useGitignore configuration is enabled.

  • Added a new test case in tests/core/file/fileSearch.test.ts to verify that patterns in .git/info/exclude are correctly considered.
  • Extended getIgnorePatterns in src/core/file/fileSearch.ts to read and include exclude file patterns.

Reviewed Changes

File Description
tests/core/file/fileSearch.test.ts Added a test to confirm that exclude file patterns are applied when useGitignore is true.
src/core/file/fileSearch.ts Added functionality to read .git/info/exclude and include its patterns based on configuration.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

@yamadashy yamadashy self-requested a review March 8, 2025 07:51
@codecov
Copy link

codecov bot commented Mar 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.21%. Comparing base (d13bba2) to head (0c8fbb0).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #391      +/-   ##
==========================================
+ Coverage   90.17%   90.21%   +0.03%     
==========================================
  Files          72       72              
  Lines        3472     3484      +12     
  Branches      750      755       +5     
==========================================
+ Hits         3131     3143      +12     
  Misses        341      341              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yamadashy yamadashy requested a review from Copilot March 8, 2025 08:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR implements support for reading ignore patterns from the .git/info/exclude file when the useGitignore configuration option is enabled, addressing issue #375.

  • Added functionality in fileSearch.ts to load and parse the .git/info/exclude file.
  • Introduced a new test in fileSearch.test.ts to verify that the exclude file patterns are correctly included.

Reviewed Changes

File Description
tests/core/file/fileSearch.test.ts Added tests to validate the .git/info/exclude file support.
src/core/file/fileSearch.ts Implemented reading and parsing of .git/info/exclude file.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

tests/core/file/fileSearch.test.ts:165

  • [nitpick] Using 'endsWith' to compare paths can lead to false positives if part of the file path matches. Consider comparing resolved absolute paths for a more robust check.
if (filePath.toString().endsWith(excludePath)) {

@yamadashy
Copy link
Owner

@motlin
The code implementation and functionality are perfect! Thank you for your contribution.

I'll go ahead and merge this, then include it in the next release!

If you have any other ideas or suggestions, please feel free to reach out!

@yamadashy yamadashy merged commit 43d8095 into yamadashy:main Mar 8, 2025
52 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 8, 2025
2 tasks
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.

3 participants