Skip to content

feat: add support for respecting .gitignore files during file scanning - #206

Closed
binbandit wants to merge 16 commits into
openai:mainfrom
binbandit:gitignore-fix
Closed

binbandit wants to merge 16 commits into
openai:mainfrom
binbandit:gitignore-fix

Conversation

@binbandit

Copy link
Copy Markdown
Contributor

Description

This PR adds support for respecting .gitignore files when scanning project files. The system will now properly ignore files and directories that are specified in the project's .gitignore file, ensuring that we don't process files that the project owner has explicitly marked as ignored.

Changes

  • Added functionality to find .gitignore files in the current directory or parent directories
  • Implemented parsing of .gitignore patterns and converting them to RegExp patterns
  • Updated the file scanning logic to respect these patterns
  • Added comprehensive test suite with 23 unit tests covering all aspects of the functionality
  • Fixed a potential infinite loop issue in the directory traversal logic
  • Added proper error handling for edge cases

Known Limitations

The current implementation has a few known limitations:

  • Limited support for negation patterns (patterns starting with !)
  • Partial support for nested directory exclusions in some cases
  • Incomplete support for the ** glob syntax

These limitations are documented in the tests and could be addressed in future improvements.

Testing

  • Added 23 unit tests covering all aspects of the .gitignore handling functionality
  • Tests cover finding .gitignore files, reading patterns, converting patterns to RegExp, and path matching
  • Added tests for various edge cases like empty files, files with only comments, etc.
  • All existing tests continue to pass

…om parent directories and add extensive tests
@binbandit binbandit changed the title feat: Add support for respecting .gitignore files during file scanning feat: add support for respecting .gitignore files during file scanning Apr 17, 2025
@binbandit

Copy link
Copy Markdown
Contributor Author

Addresses #205

@tibo-openai

tibo-openai commented Apr 17, 2025 •

Copy link
Copy Markdown
Collaborator

Overall idea is sound, but there seem to be some spurious changes / files added and ci doesn't pass, let me know when this is fixed and ready for review!

Changed `mockImplementation` and `mockReturnValue` types from `any` to `unknown` to improve type safety and avoid complex type issues. Updated comment to reflect the use of `@ts-expect-error` for simplified mock types.
@binbandit

Copy link
Copy Markdown
Contributor Author

@tibo-openai Good to go

@lostmygithubaccount

Copy link
Copy Markdown
Contributor

any chance this will still be added?

@Kevinlearynet

Copy link
Copy Markdown

Related to #300

@binbandit

Copy link
Copy Markdown
Contributor Author

@fouad-openai @tibo-openai

Any chance on getting this one merged?

@binbandit

Copy link
Copy Markdown
Contributor Author

@bolinfest Maybe you can help us out here?

@binbandit

Copy link
Copy Markdown
Contributor Author

Bump

@codex-maintainers

Copy link
Copy Markdown

Thanks for the contribution! We're primarily focused on the native/Rust implementation of Codex CLI and would love to see if this is still an issue on the latest version. If it is, we're happy to take a look at a PR to the codex-rs/ implementation.

@github-actions github-actions Bot locked and limited conversation to collaborators Aug 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants