Skip to content

grep: detect format flags bundled inside short-flag clusters#2544

Open
EtaCassiopeia wants to merge 1 commit into
rtk-ai:developfrom
EtaCassiopeia:fix/grep-clustered-format-flags
Open

grep: detect format flags bundled inside short-flag clusters#2544
EtaCassiopeia wants to merge 1 commit into
rtk-ai:developfrom
EtaCassiopeia:fix/grep-clustered-format-flags

Conversation

@EtaCassiopeia

@EtaCassiopeia EtaCassiopeia commented Jun 22, 2026

Copy link
Copy Markdown

Follow-up to #2543 — this fixes the second part of it.

has_format_flag checks extra_args for things like -l/-c/-o so it knows to skip the usual match-line parsing and just pass rg's output straight through (since those flags change rg's output format entirely). That check only matches exact tokens though, and extract_pattern_path merges plain boolean short flags into one combined token before they get here — so -rln becomes -ln after r is stripped, and -ln never matches -l exactly.

End result: something like rtk grep -rln pattern path runs rg with -l correctly, but then tries to parse the (now filenames-only) output as if it were normal file:line:content matches, finds nothing that fits that shape, and reports "0 matches" even when there clearly are matches. That's worse than just erroring, since it looks identical to a real empty result.

Fix is small — has_format_flag now also scans the individual letters of a short cluster (long flags and exact single-flag matches are unaffected). Added a few tests for the clustered case plus one to make sure long flags like --ignore-case don't get walked character-by-character by mistake.

Tested locally:

  • rtk grep -rln pattern path now correctly falls through to passthrough and shows the real file list instead of "0 matches in 0 files"
  • rtk grep -rn pattern path unaffected
  • existing grep_cmd test suite passes (72 tests)

closes #2543

has_format_flag only matched exact tokens like "-l", but
extract_pattern_path merges boolean short flags into one cluster
(e.g. `-rln` becomes `-ln` after stripping `r`). A bundled -l/-c/-o/-L/-Z
never matched, so grep_cmd tried to NUL-parse rg's output as if it were
normal match lines, even though -l/-c/etc. change rg's output shape
entirely. The result was a false "0 matches" instead of the real answer.

Now has_format_flag also scans the individual letters of a short-flag
cluster, so a bundled format flag correctly falls through to the
existing passthrough path.
@CLAassistant

CLAassistant commented Jun 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

grep: -r / -rn rejected on 0.42.4 (and -rln returns a false "0 matches" on latest develop)

2 participants