Skip to content

fix(grep): strip ripgrep-only flags when falling back to system grep - #2224

Closed
mikeangstadt wants to merge 1 commit into
rtk-ai:developfrom
mikeangstadt:fix/grep-ripgrep-fallback
Closed

mikeangstadt wants to merge 1 commit into
rtk-ai:developfrom
mikeangstadt:fix/grep-ripgrep-fallback

Conversation

@mikeangstadt

@mikeangstadt mikeangstadt commented Jun 2, 2026 •

Copy link
Copy Markdown

Summary

When ripgrep is not on $PATH, rtk grep falls back to system grep but was passing ripgrep-specific flags (e.g. -g/--glob, --hidden, --pcre2, --json, --sort) directly to grep, which does not understand them. This causes silent failures or wrong results (e.g. grep: invalid option -- g).

Changes

  • Added RG_ONLY_FLAGS constant table of ripgrep-only flags with their value-taking semantics
  • Added filter_rg_flags() that strips rg-only flags (and their value arguments) from extra_args before passing to the grep fallback
  • Handles both standalone flags (--json) and value-taking flags (-g *.ts, --glob=*.ts)
  • The main rg path is unaffected; only the .or_else(|_| ...) fallback is changed

Testing

  • Manual review of the filter logic:
    • extra_args = ["-g", "*.rs", "-i"] -> ["-i"] (skips -g and its value *.rs)
    • extra_args = ["--glob=*.rs", "-i"] -> ["-i"] (embedded value skipped)
    • extra_args = ["--json", "--stats", "-i"] -> ["-i"]
    • extra_args = ["--hidden", "--no-ignore", "-n"] -> ["-n"]
    • No rg-only flags -> all args pass through unchanged

Closes #2167


Collaborated & orchestrated by ClosedLoop.AI | GitHub

When ripgrep is not on $PATH, rtk grep falls back to system grep but
was passing ripgrep-specific flags like -g/--glob, --hidden, --pcre2,
--json, etc. that grep does not understand, causing silent failures or
wrong results.

Adds a stateful filter that removes rg-only flags (and their value
arguments) from the extra_args before passing them to grep.

Closes rtk-ai#2167
@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot rtk-release-bot Bot added the stale label Sep 3, 2026
@KuSh

KuSh commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the detailed flag table. This was overtaken twice: #2550 (merged 2026-06-23) folded rg-only flag stripping into its own fallback handling, and #2641 (merged 2026-06-26) then removed the fallback altogether by making rtk grep run real grep and adding rtk rg for ripgrep, with the hook rewriting rg ... accordingly. The file you patched, src/cmds/system/grep_cmd.rs, no longer exists on develop, and issue #2167 was closed as fixed by that work. If you still see ripgrep flags reaching system grep on the current develop, please comment here or reopen with the command.

@KuSh KuSh closed this Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk grep calls system grep instead of ripgrep — breaks -g/--glob flags

2 participants