Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Comment thread
KrushnXGIT marked this conversation as resolved.
Resolved
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();
Expand Down
12 changes: 12 additions & 0 deletions tests/by-util/test_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
Expand Down
Loading