Skip to content

fix(grep): report honest match counts in header when --max caps output#2522

Open
lesbass wants to merge 1 commit into
rtk-ai:developfrom
lesbass:fix/grep-header-honest-counts
Open

fix(grep): report honest match counts in header when --max caps output#2522
lesbass wants to merge 1 commit into
rtk-ai:developfrom
lesbass:fix/grep-header-honest-counts

Conversation

@lesbass

@lesbass lesbass commented Jun 20, 2026

Copy link
Copy Markdown

Fixes #2436

Problem

In rtk grep, the header line "N matches in M files" reports the raw rg/grep
match count, even when --max or grep_max_results caps the displayed output.
For example, with --max 5 the output shows 5 results but the header says
"211 matches in 50 files".

Root Cause

The header was constructed before the truncation loop, using the raw parsed
match count (total_matches). The loop correctly enforces caps, but the
already-written header was oblivious.

Fix

Defer the header until after the truncation loop. When output is capped,
the header now shows two numbers:

  • Before: 211 matches in 50 files:
  • After: 211 matches (5 shown) in 50 files:

When output is not capped, the header format is unchanged.

The [+N more] footer remains accurate.

Changes

1 file: src/cmds/system/grep_cmd.rs — restructure header construction
to occur after the truncation loop, with a conditional format for capped output.

Verification

  • cargo fmt --all --check passes
  • Build requires a C compiler (not available in this environment); changes are
    a mechanical restructuring with no logic modifications

@CLAassistant

CLAassistant commented Jun 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@lesbass lesbass force-pushed the fix/grep-header-honest-counts branch from e512cc7 to 49d2695 Compare June 20, 2026 06:36
@lesbass

lesbass commented Jun 20, 2026

Copy link
Copy Markdown
Author

Commit authorship has been corrected: author changed from RepoScout to Stefano Maffeis (GitHub user lesbass). This should allow the CLA check to properly identify the contributor. The CLA still needs signing via the CLA Assistant link above.

@lesbass lesbass force-pushed the fix/grep-header-honest-counts branch 3 times, most recently from 629f496 to e748cbe Compare July 1, 2026 06:37
@lesbass

lesbass commented Jul 1, 2026

Copy link
Copy Markdown
Author

I rebased this PR onto the latest develop branch. Unfortunately, GitHub Actions now requires a maintainer to approve the workflow run for fork PRs after a force push. Could someone approve the run so CI can confirm the change is clean? No code changes — just a rebase to resolve the merge conflict.

When --max or grep_max_results caps the displayed matches, the header
previously reported the raw total match count, misleading users about
what was actually shown. Defer the header until after the truncation
loop and show two numbers when output is capped:
'N matches (K shown) in M files'.

Footer [+N more] remains accurate.

Fixes rtk-ai#2436

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@lesbass lesbass force-pushed the fix/grep-header-honest-counts branch from e748cbe to 9b1571a Compare July 1, 2026 06:40
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] header reports raw match counts even when --max caps output

2 participants