Skip to content

Commit e63f87a

Browse files
committed
Merge branch 'jc/apply-blank-at-eof-fix' into maint
* jc/apply-blank-at-eof-fix: apply --whitespace=error: correctly report new blank lines at end
2 parents 6e89b37 + 8557263 commit e63f87a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

builtin/apply.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
24502450
char *old, *oldlines;
24512451
struct strbuf newlines;
24522452
int new_blank_lines_at_end = 0;
2453+
int found_new_blank_lines_at_end = 0;
2454+
int hunk_linenr = frag->linenr;
24532455
unsigned long leading, trailing;
24542456
int pos, applied_pos;
24552457
struct image preimage;
@@ -2543,14 +2545,18 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
25432545
error("invalid start of line: '%c'", first);
25442546
return -1;
25452547
}
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;
25472551
new_blank_lines_at_end++;
2552+
}
25482553
else if (is_blank_context)
25492554
;
25502555
else
25512556
new_blank_lines_at_end = 0;
25522557
patch += len;
25532558
size -= len;
2559+
hunk_linenr++;
25542560
}
25552561
if (inaccurate_eof &&
25562562
old > oldlines && old[-1] == '\n' &&
@@ -2632,7 +2638,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
26322638
preimage.nr + applied_pos >= img->nr &&
26332639
(ws_rule & WS_BLANK_AT_EOF) &&
26342640
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);
26362643
if (ws_error_action == correct_ws_error) {
26372644
while (new_blank_lines_at_end--)
26382645
remove_last_line(&postimage);

0 commit comments

Comments
 (0)