Repository navigation
Description
GNU diff's -I RE / --ignore-matching-lines=RE drops a hunk when every inserted and
deleted line in it matches the basic regular expression RE. The option may be repeated.
uutils does not know the option in any form (-I RE, -IRE, --ignore-matching-lines RE,
--ignore-matching-lines=RE) and fails with unrecognized option and exit 2.
Two GNU tests expose it: ignore-matching-lines (a hunk whose changed lines all match
3 is kept only as context) and invalid-re (-Ix -I\\ must report
diff: '\': Trailing backslash and exit 2; see also #394 for the missing diff: prefix).
Reproduction
printf '1a\n2\n3a\n' > m1; printf '1b\n2\n3b\n' > m2Rust (incorrect)
$ ./target/release/diffutils diff -I 3 m1 m2
unrecognized option '-I'
# Exit code: 2
$ ./target/release/diffutils diff --ignore-matching-lines=3 m1 m2
unrecognized option '--ignore-matching-lines=3'
# Exit code: 2GNU (correct)
$ LC_ALL=C diff -I 3 m1 m2
1c1
< 1a
---
> 1b
# Exit code: 1
$ LC_ALL=C diff --ignore-matching-lines=3 m1 m2
1c1
< 1a
---
> 1b
# Exit code: 1Root cause
parse_params in src/params.rs has no -I branch and Params (src/params.rs:35)
has no list of ignore patterns, so the word reaches src/params.rs:324-326:
if param.to_string_lossy().starts_with('-') {
return Err(format!("unrecognized option '{}'", param.to_string_lossy()));
}The pieces needed already exist for -F: option_argument/argument_value for the
option forms and the Bre type in src/bre.rs (which already reports
Trailing backslash).
Test
Add to tests/by-util/test_diff.rs:
#[test]
fn ignore_matching_lines() -> Result<(), Box<dyn std::error::Error>> {
let mut a = NamedTempFile::new()?;
a.write_all(b"1a\n2\n3a\n")?;
let mut b = NamedTempFile::new()?;
b.write_all(b"1b\n2\n3b\n")?;
for args in [vec!["-I", "3"], vec!["-I3"], vec!["--ignore-matching-lines=3"]] {
let mut cmd = cargo_bin_cmd!("diffutils");
cmd.arg("diff").args(&args).arg(a.path()).arg(b.path());
cmd.assert()
.code(predicate::eq(1))
.stdout(predicate::eq("1c1\n< 1a\n---\n> 1b\n"));
}
// An invalid pattern is a usage error.
let mut cmd = cargo_bin_cmd!("diffutils");
cmd.arg("diff").arg("-Ix").arg("-I\\").arg(a.path()).arg(b.path());
cmd.assert()
.code(predicate::eq(2))
.stdout(predicate::str::is_empty())
.stderr(predicate::str::contains("'\\': Trailing backslash"));
Ok(())
}Exposed by the GNU diffutils test suite: ignore-matching-lines, invalid-re.
Activity
ilainy commentedon Nov 16, 2026
I'd like to work on this.
ilainy commentedon Nov 16, 2026
Opened #402 for this.