@@ -2450,6 +2450,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
2450
2450
char * old , * oldlines ;
2451
2451
struct strbuf newlines ;
2452
2452
int new_blank_lines_at_end = 0 ;
2453
+ int found_new_blank_lines_at_end = 0 ;
2454
+ int hunk_linenr = frag -> linenr ;
2453
2455
unsigned long leading , trailing ;
2454
2456
int pos , applied_pos ;
2455
2457
struct image preimage ;
@@ -2543,14 +2545,18 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
2543
2545
error ("invalid start of line: '%c'" , first );
2544
2546
return -1 ;
2545
2547
}
2546
- if (added_blank_line )
2548
+ if (added_blank_line ) {
2549
+ if (!new_blank_lines_at_end )
2550
+ found_new_blank_lines_at_end = hunk_linenr ;
2547
2551
new_blank_lines_at_end ++ ;
2552
+ }
2548
2553
else if (is_blank_context )
2549
2554
;
2550
2555
else
2551
2556
new_blank_lines_at_end = 0 ;
2552
2557
patch += len ;
2553
2558
size -= len ;
2559
+ hunk_linenr ++ ;
2554
2560
}
2555
2561
if (inaccurate_eof &&
2556
2562
old > oldlines && old [-1 ] == '\n' &&
@@ -2632,7 +2638,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
2632
2638
preimage .nr + applied_pos >= img -> nr &&
2633
2639
(ws_rule & WS_BLANK_AT_EOF ) &&
2634
2640
ws_error_action != nowarn_ws_error ) {
2635
- record_ws_error (WS_BLANK_AT_EOF , "+" , 1 , frag -> linenr );
2641
+ record_ws_error (WS_BLANK_AT_EOF , "+" , 1 ,
2642
+ found_new_blank_lines_at_end );
2636
2643
if (ws_error_action == correct_ws_error ) {
2637
2644
while (new_blank_lines_at_end -- )
2638
2645
remove_last_line (& postimage );
0 commit comments