From 0ea13c3368710a495f2c46cc481f8f2bb984a6ea Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Mon, 25 May 2026 15:16:46 +0000 Subject: [PATCH] fix(rg): preserve collected diagnostics in quiet match paths collect_rg_inputs accumulates read errors into collected_inputs.stderr, but quiet early-return paths used ExecResult::ok which dropped those diagnostics, causing 'rg -q needle missing.txt readable.txt' to lose missing-file messages when --messages is enabled. Thread stderr through rg_quiet_result so the quiet selected paths preserve collected diagnostics. Adds two differential cases: - -q with missing file + readable match - --no-messages -q to verify diagnostics are suppressed Rebased on current main; original PR #1755 by chaliy. --- crates/bashkit/src/builtins/rg/mod.rs | 56 ++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/crates/bashkit/src/builtins/rg/mod.rs b/crates/bashkit/src/builtins/rg/mod.rs index cb7184ab..4cbee008 100644 --- a/crates/bashkit/src/builtins/rg/mod.rs +++ b/crates/bashkit/src/builtins/rg/mod.rs @@ -4463,6 +4463,7 @@ fn rg_quiet_result( opts: &RgOptions, match_count: usize, any_match: &mut bool, + stderr: &str, ) -> Option { let selected = if opts.files_without_matches { match_count == 0 @@ -4472,7 +4473,12 @@ fn rg_quiet_result( if selected { *any_match = true; if !opts.stats { - return Some(ExecResult::ok(String::new())); + return Some(ExecResult { + stdout: String::new(), + stderr: stderr.to_string(), + exit_code: 0, + ..Default::default() + }); } } None @@ -4743,7 +4749,9 @@ impl Builtin for Rg { let matched = if opts.invert_match { !matched } else { matched }; if !matched { if opts.quiet { - if let Some(result) = rg_quiet_result(&opts, 0, &mut any_match) { + if let Some(result) = + rg_quiet_result(&opts, 0, &mut any_match, &collected_inputs.stderr) + { return Ok(result); } continue; @@ -4775,7 +4783,9 @@ impl Builtin for Rg { stats.matched_lines += 1; stats.files_with_matches += 1; if opts.quiet { - if let Some(result) = rg_quiet_result(&opts, 1, &mut any_match) { + if let Some(result) = + rg_quiet_result(&opts, 1, &mut any_match, &collected_inputs.stderr) + { return Ok(result); } continue; @@ -4952,7 +4962,12 @@ impl Builtin for Rg { } if opts.quiet { - if let Some(result) = rg_quiet_result(&opts, match_count, &mut any_match) { + if let Some(result) = rg_quiet_result( + &opts, + match_count, + &mut any_match, + &collected_inputs.stderr, + ) { return Ok(result); } continue; @@ -5113,7 +5128,12 @@ impl Builtin for Rg { } if opts.quiet { - if let Some(result) = rg_quiet_result(&opts, match_count, &mut any_match) { + if let Some(result) = rg_quiet_result( + &opts, + match_count, + &mut any_match, + &collected_inputs.stderr, + ) { return Ok(result); } continue; @@ -5543,7 +5563,9 @@ impl Builtin for Rg { } if opts.quiet { - if let Some(result) = rg_quiet_result(&opts, match_count, &mut any_match) { + if let Some(result) = + rg_quiet_result(&opts, match_count, &mut any_match, &collected_inputs.stderr) + { return Ok(result); } continue; @@ -6778,6 +6800,28 @@ mod tests { cwd: "/proj", output: RgDiffOutput::UnorderedLines, }, + RgDiffCase { + name: "quiet keeps missing file diagnostics when match found", + args: &["-q", "needle", "proj/missing.txt", "proj/a.txt"], + stdin: None, + files: DIFF_BASIC_FILES, + cwd: "/", + output: RgDiffOutput::Exact, + }, + RgDiffCase { + name: "quiet no messages suppresses missing file diagnostics", + args: &[ + "--no-messages", + "-q", + "needle", + "proj/missing.txt", + "proj/a.txt", + ], + stdin: None, + files: DIFF_BASIC_FILES, + cwd: "/", + output: RgDiffOutput::Exact, + }, RgDiffCase { name: "relative recursive display", args: &["needle", "proj"],