Skip to content

Conversation

@vitali87
Copy link
Owner

@vitali87 vitali87 commented Jan 6, 2026

Summary

Add support for a .cgrignore file that allows users to specify additional directories to exclude from parsing, similar to .gitignore but simpler.

  • Patterns from .cgrignore are merged with --exclude CLI flags and auto-detected directories
  • File format: one directory name per line, # comments, blank lines ignored
  • Integrates with the new interactive setup grouped directory display

Rebased from PR #219 (from @jxstanford's fork) to integrate with the new --interactive-setup feature from PR #221.

Changes

  • codebase_rag/config.py: Add load_cgrignore_patterns() function and CGRIGNORE_FILENAME constant
  • codebase_rag/main.py: Integrate .cgrignore loading into prompt_for_included_directories()
  • codebase_rag/constants.py: Add INTERACTIVE_STATUS_CGRIGNORE for UI display
  • codebase_rag/logs.py: Add log message templates
  • codebase_rag/tests/test_cgrignore.py: Add 6 unit tests
  • README.md: Document the feature

Example .cgrignore

# Comments start with #
vendor
.custom_cache
my_build_output

Test plan

  • Unit tests pass (pytest codebase_rag/tests/test_cgrignore.py)
  • Exclude patterns tests pass
  • Manual test with a .cgrignore file in a repository

Closes #219

Add support for a `.cgrignore` file that allows users to specify
additional directories to exclude from parsing. Patterns from this
file are merged with `--exclude` CLI flags and auto-detected directories.

- Add `load_cgrignore_patterns()` function in config.py
- Integrate with `prompt_exclude_directories()` in main.py
- Add EXCLUDE_STATUS_CGRIGNORE constant for UI display
- Add tests for .cgrignore loading
- Update README with documentation
Addresses PR review feedback:
- Move loguru import to module level in config.py
- Use log constants from logs.py instead of f-strings
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @vitali87, 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 directory exclusion capabilities by introducing support for a .cgrignore file. This file allows users to define custom exclusion patterns directly within their repository, providing a flexible way to manage which directories are processed. The patterns from this file are seamlessly integrated with existing exclusion methods, ensuring a consistent and powerful mechanism for controlling directory parsing, and are also reflected in the interactive setup.

Highlights

  • New .cgrignore file support: Introduces a new .cgrignore file that allows users to specify additional directories to exclude from parsing, similar to .gitignore.
  • Pattern Merging: Patterns defined in .cgrignore are merged with --exclude CLI flags and auto-detected directories for comprehensive exclusion.
  • File Format: The .cgrignore file supports one directory name per line, # for comments, and ignores blank lines, with patterns being exact directory name matches.
  • Interactive Setup Integration: The new exclusion patterns are integrated into the interactive setup's grouped directory display for better user experience.
  • Comprehensive Testing: A new test file with 6 unit tests has been added to validate the functionality of loading and parsing .cgrignore files, covering various edge cases.
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 introduces support for a .cgrignore file, allowing users to specify custom exclusion patterns for directory parsing. The implementation is clean, well-tested, and properly documented in the README. The new load_cgrignore_patterns function correctly handles file parsing, including comments and blank lines, and integrates smoothly into the existing configuration for excluded directories. The addition of unit tests for this new functionality is a great practice.

My feedback includes a couple of suggestions to enhance robustness: one to make the file check more specific in config.py, and another to add a test case for an edge scenario where .cgrignore might be a directory. Overall, this is a solid contribution that improves the tool's configurability.

@greptile-apps
Copy link

greptile-apps bot commented Jan 6, 2026

Greptile Summary

Added support for a .cgrignore file that allows users to specify custom directory exclusion patterns. Patterns from .cgrignore are treated as directory names and merged with CLI --exclude flags and auto-detected ignore patterns (node_modules, .git, etc.).

Key changes:

  • load_cgrignore_patterns() in config.py reads and parses .cgrignore with proper error handling
  • Integration into prompt_for_included_directories() merges patterns from three sources: auto-detected, CLI flags, and .cgrignore
  • File format supports comments (#), blank lines, and whitespace stripping
  • Patterns are directory names (not glob patterns), consistent with existing exclude logic
  • Comprehensive test coverage includes edge cases (missing file, parse errors, duplicates)

Integration notes:

  • The implementation correctly merges .cgrignore patterns with CLI patterns before combining with auto-detected directories
  • should_skip_path() in path_utils.py checks if any part of a path matches exclude patterns, so directory names work correctly
  • The grouped interactive display shows all patterns together, with the constant INTERACTIVE_STATUS_CGRIGNORE added but currently unused (the old flat display used status columns to show pattern sources)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is clean, well-tested, and follows project conventions. The feature is properly isolated with graceful error handling, comprehensive test coverage, and correct integration with existing exclude pattern logic. No breaking changes or security concerns identified.
  • No files require special attention

Important Files Changed

Filename Overview
codebase_rag/config.py Added load_cgrignore_patterns() function to parse .cgrignore file with proper error handling
codebase_rag/main.py Integrated .cgrignore patterns loading into prompt_for_included_directories() with proper merging logic
codebase_rag/tests/test_cgrignore.py Comprehensive test suite covering all functionality: empty file, pattern loading, comments, whitespace, errors, duplicates

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant main
    participant config
    participant path_utils
    participant filesystem

    User->>CLI: cgr start --interactive-setup
    CLI->>main: prompt_for_included_directories(repo_path, cli_excludes)
    
    main->>main: detect_excludable_directories(repo_path)
    main-->>main: detected directories (e.g., .git, node_modules)
    
    main->>config: load_cgrignore_patterns(repo_path)
    config->>filesystem: check if .cgrignore exists
    
    alt .cgrignore exists
        config->>filesystem: read .cgrignore file
        filesystem-->>config: file content
        config->>config: parse lines (strip whitespace, skip comments)
        config-->>main: frozenset of patterns (e.g., vendor, my_build)
    else .cgrignore not found
        config-->>main: empty frozenset
    end
    
    main->>main: merge cli_patterns | cgrignore_patterns
    main->>main: merge detected | pre_excluded
    main->>main: group paths by pattern
    main->>User: display grouped table
    
    User->>main: select patterns to keep/exclude
    main-->>CLI: frozenset of excluded directories
    
    CLI->>path_utils: should_skip_path(path, exclude_paths)
    path_utils->>path_utils: check if any path part in exclude_paths
    path_utils-->>CLI: true/false
Loading

@vitali87
Copy link
Owner Author

vitali87 commented Jan 6, 2026

/gemini review

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 introduces support for a .cgrignore file, allowing users to specify custom directories to exclude from parsing. The implementation is solid, including documentation updates in the README, new logic to load and merge ignore patterns, and comprehensive unit tests for the new functionality. My review includes a couple of suggestions for improvement: one to align with PEP 8 import conventions for better code style, and another to simplify and improve the robustness of a unit test. Overall, this is a well-executed feature addition.

@vitali87 vitali87 merged commit bb696b3 into main Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants