commit 4125b1eff8d9dfcd961dc70ebbd5d54c97bdc3f6 from: Tom Jones via: tj date: Mon Oct 10 13:15:27 2022 UTC diff: handle missing new lines in trailing context If there is a missing new line in the context we currently miss it and fail to print the warning. This trips up patch and leads to failures. Catch these cases in for unidiff output and add a test case. ok stsp@ commit - 9f5da0913af47a525ab2a2422c7911cdb08866d0 commit + 4125b1eff8d9dfcd961dc70ebbd5d54c97bdc3f6 blob - 74b22eb8207ab2c5f154a22229051900a3d7b1ce blob + b20dabf6658691770d21bfe3c1227ae815223474 --- lib/diff_output_unidiff.c +++ lib/diff_output_unidiff.c @@ -391,6 +391,11 @@ output_unidiff_chunk(struct diff_output_info *outinfo, cc->left.end - chunk_end_line); if (rc) return rc; + + rc = diff_output_trailing_newline_msg(outinfo, dest, + &result->chunks.head[result->chunks.len - 1]); + if (rc != DIFF_RC_OK) + return rc; } return DIFF_RC_OK; blob - /dev/null blob + dc9ca80aa498390f1b6acbcf3ac017176a05d4be (mode 644) --- /dev/null +++ test/expect125.diff @@ -0,0 +1,12 @@ +--- test125.left.txt ++++ test125.right.txt +@@ -1,7 +1,7 @@ + This is a test + of missing trailing new lines + in context +-this line has a change ++this line has the change + this is the same + this is too + and this one +\ No newline at end of file blob - /dev/null blob + ecce2a6d7d492d0bd0090f27093c54a876d3dca6 (mode 644) --- /dev/null +++ test/test125.left.txt @@ -0,0 +1,7 @@ +This is a test +of missing trailing new lines +in context +this line has a change +this is the same +this is too +and this one \ No newline at end of file blob - /dev/null blob + 1242106e06a77ee483209c2b43420bc94a7de383 (mode 644) --- /dev/null +++ test/test125.right.txt @@ -0,0 +1,7 @@ +This is a test +of missing trailing new lines +in context +this line has the change +this is the same +this is too +and this one \ No newline at end of file