Fix file filtering logic to handle file name patterns like output.txt #64
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This pull request resolves an issue where the --exclude flag did not correctly handle file name patterns such as output.txt. The bug caused unexpected behavior when attempting to exclude files based solely on their name, without using a glob pattern or a fully qualified path.
The issue also extends to relative patterns like ./output.txt. However, as output.txt provides a simpler and more conventional way to specify a file name, support for ./output.txt has been intentionally omitted to maintain clarity and reduce ambiguity.
Steps to Reproduce the Issue
code2prompt --tokens --output=output.txt . --exclude="output.txt"
Root Cause
Solution
The filtering logic was updated to:
Tests Added
How to Test
Build the project from this branch.
Run the following test commands:
Exclude a file by name:
code2prompt --tokens --output=output.txt . --exclude="output.txt"
Exclude a file using a glob pattern:
code2prompt --tokens --output=output.txt . --exclude="**/output.txt"
Verify that the file output.txt is excluded in all cases.
Notes
The version was incremented to 2.0.1.
Relative patterns like ./output.txt are not supported in this fix, as they introduce unnecessary complexity when specifying file names.