File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,9 @@ var JsDiff = (function() {
191191 ret . push ( "+++ " + fileName + "\t" + newHeader ) ;
192192
193193 var diff = LineDiff . diff ( oldStr , newStr ) ;
194+ if ( ! diff [ diff . length - 1 ] . value ) {
195+ diff . pop ( ) ; // Remove trailing newline add
196+ }
194197 diff . push ( { value : "" , lines : [ ] } ) ; // Append an empty value to make cleanup easier
195198
196199 function contextLines ( lines ) {
@@ -217,6 +220,14 @@ var JsDiff = (function() {
217220 }
218221 }
219222 curRange . push . apply ( curRange , lines . map ( function ( entry ) { return ( current . added ?"+" :"-" ) + entry ; } ) ) ;
223+
224+ // Figure out if this is the last line for the given file and missing NL
225+ if ( ! / \n $ / . test ( current . value )
226+ && ( i === diff . length - 2
227+ || ( i === diff . length - 3 && current . added === ! diff [ diff . length - 2 ] . added ) ) ) {
228+ curRange . push ( '\\ No newline at end of file' ) ;
229+ }
230+
220231 if ( current . added ) {
221232 newLine += lines . length ;
222233 } else {
@@ -245,11 +256,8 @@ var JsDiff = (function() {
245256 newLine += lines . length ;
246257 }
247258 }
248- if ( diff . length > 1 && ! / \n $ / . test ( diff [ diff . length - 2 ] . value ) ) {
249- ret . push ( "\\ No newline at end of file\n" ) ;
250- }
251-
252- return ret . join ( "\n" ) ;
259+
260+ return ret . join ( '\n' ) + '\n' ;
253261 } ,
254262
255263 convertChangesToXML : function ( changes ) {
You can’t perform that action at this time.
0 commit comments