diff: Only output a unified/context header if there is a diff

This commit is contained in:
Shannon Booth 2023-07-06 20:39:35 +12:00 committed by Andreas Kling
parent c6c20d3bf3
commit 84b187e375

View file

@ -57,6 +57,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto hunks = TRY(Diff::from_text(TRY(file1->read_until_eof()), TRY(file2->read_until_eof()), number_context_lines));
if (hunks.is_empty())
return 0;
if (unified) {
TRY(Diff::write_unified_header(filename1, filename2, *out));
for (auto const& hunk : hunks)
@ -70,5 +73,5 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Diff::write_normal(hunk, *out, color_output));
}
return hunks.is_empty() ? 0 : 1;
return 1;
}