diff --git a/src/diff.rs b/src/diff.rs index 7931d4c1..dc045658 100644 --- a/src/diff.rs +++ b/src/diff.rs @@ -132,6 +132,13 @@ pub fn compare_files(params: &Params, header: Option<&[u8]>) -> Outcome { return Outcome::Trouble; } + // identical contents need no diff, unless side by side output shows their + // lines or an ed script warns about a missing newline + if from_content == to_content && !matches!(params.format, Format::SideBySide | Format::Ed) { + maybe_report_identical_files(); + return Outcome::Identical; + } + if !params.text && (is_binary(&from_content) || is_binary(&to_content)) { if from_content == to_content { maybe_report_identical_files(); diff --git a/tests/by-util/test_diff.rs b/tests/by-util/test_diff.rs index 2955704d..74c12453 100644 --- a/tests/by-util/test_diff.rs +++ b/tests/by-util/test_diff.rs @@ -36,6 +36,18 @@ fn no_differences_report_identical_files( .stdout_is(format!("Files file1 and {second} are identical\n")); } +// Side by side output still shows the lines of two identical files. +#[test] +fn no_differences_side_by_side() { + let (at, ts) = at_and_ts!(); + at.write("file1", "foo\nbar\n"); + at.write("file2", "foo\nbar\n"); + ts.ucmd() + .args(&["-y", "--width=40", "file1", "file2"]) + .succeeds() + .stdout_is("foo\t\t foo\nbar\t\t bar\n"); +} + #[rstest] fn differences(#[values(&[][..], &["-u"], &["-c"], &["-e"])] format: &[&str]) { let (at, ts) = at_and_ts!();