1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2024-12-12 19:18:24 +02:00

printer: fix path handling in summarizer

This commit fixes a bug where both of the following commands always
reported an error:

    rg --files-with-matches foo file
    rg --files-without-match foo file

In particular, the printer was erroneously respecting the `path` option
even the the summary kind was `PathWithMatch` or `PathWithoutMatch`. The
documented behavior is that those summary kinds always require a path,
and thus, the `path` option has no effect. We fix this by correcting the
case analysis.

This also fixes a bug where the exit code for `--files-without-match`
was not set correctly. We update the printer's `has_match` method to
report the correct value.

Fixes #1106, Closes #1130
This commit is contained in:
Mika Dede 2018-12-01 13:31:33 +01:00 committed by Andrew Gallant
parent 57500ad013
commit a7f2d48234
No known key found for this signature in database
GPG Key ID: B2E3A4923F8B0D44
3 changed files with 25 additions and 2 deletions

View File

@ -9,6 +9,11 @@ Feature enhancements:
* [FEATURE #1170](https://github.com/BurntSushi/ripgrep/pull/1170):
Add `--ignore-file-case-insensitive` for case insensitive .ignore globs.
Bug fixes:
* [BUG #1106](https://github.com/BurntSushi/ripgrep/issues/1106):
`--files-with-matches` and `--files-without-match` work with one file.
0.10.0 (2018-09-07)
===================

View File

@ -403,7 +403,7 @@ impl<W: WriteColor> Summary<W> {
where M: Matcher,
P: ?Sized + AsRef<Path>,
{
if !self.config.path {
if !self.config.path && !self.config.kind.requires_path() {
return self.sink(matcher);
}
let stats =
@ -477,7 +477,10 @@ impl<'p, 's, M: Matcher, W: WriteColor> SummarySink<'p, 's, M, W> {
/// This is unaffected by the result of searches before the previous
/// search.
pub fn has_match(&self) -> bool {
self.match_count > 0
match self.summary.config.kind {
SummaryKind::PathWithoutMatch => self.match_count == 0,
_ => self.match_count > 0,
}
}
/// If binary data was found in the previous search, this returns the

View File

@ -569,6 +569,21 @@ rgtest!(r1064, |dir: Dir, mut cmd: TestCommand| {
eqnice!("input:abc\n", cmd.arg("a(.*c)").stdout());
});
// See: https://github.com/BurntSushi/ripgrep/issues/1130
rgtest!(r1130, |dir: Dir, mut cmd: TestCommand| {
dir.create("foo", "test");
eqnice!(
"foo\n",
cmd.arg("--files-with-matches").arg("test").arg("foo").stdout()
);
let mut cmd = dir.command();
eqnice!(
"foo\n",
cmd.arg("--files-without-match").arg("nada").arg("foo").stdout()
);
});
// See: https://github.com/BurntSushi/ripgrep/issues/1164
rgtest!(r1164, |dir: Dir, mut cmd: TestCommand| {
dir.create_dir(".git");