Skip to content

fix(#2820): --files now correctly handles implicit pattern argument#3343

Open
xingzihai wants to merge 1 commit intoBurntSushi:masterfrom
xingzihai:fix-issue-2820-files-path
Open

fix(#2820): --files now correctly handles implicit pattern argument#3343
xingzihai wants to merge 1 commit intoBurntSushi:masterfrom
xingzihai:fix-issue-2820-files-path

Conversation

@xingzihai
Copy link
Copy Markdown

When using --files with positional arguments, the first positional was incorrectly treated as a path when it would have been a pattern in search mode. This caused --files to list files outside the intended search path.

The fix: When --files (or other non-search modes) has multiple positional arguments and no explicit patterns via -e/-f, skip the first positional as it would be the pattern in search mode.

Example:

rg "." node_modules --files

Before: Listed files from "." (current dir) and node_modules
After: Only lists files from node_modules (the intended search path)

This ensures --files lists files that would actually be searched.

Fixes #2820

…argument

When using --files with positional arguments, the first positional was
incorrectly treated as a path when it would have been a pattern in search
mode. This caused --files to list files outside the intended search path.

The fix: When --files (or other non-search modes) has multiple positional
arguments and no explicit patterns via -e/-f, skip the first positional as
it would be the pattern in search mode.

Example:
  rg '.' node_modules --files

Before: Listed files from '.' (current dir) and node_modules
After: Only lists files from node_modules (the intended search path)

We only apply this when there are >= 2 positionals:
- Single positional (like --files .) is an intentional path
- Multiple positionals suggests pattern + path(s)

This ensures --files lists files that would actually be searched.

Signed-off-by: xingzihai <xingzihai@users.noreply.github.com>
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.

--files is listing files that won't be searched into

1 participant