Skip to content

Commit 94ea026

Browse files
committed
apply --whitespace: warn blank but not necessarily empty lines at EOF
The whitespace error of adding blank lines at the end of file should trigger if you added a non-empty line at the end, if the contents of the line is full of whitespaces. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 77b15bb commit 94ea026

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

builtin-apply.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
19571957
is_blank_context = 1;
19581958
break;
19591959
case ' ':
1960-
if (plen && patch[1] == '\n')
1960+
if (plen && (ws_rule & WS_BLANK_AT_EOF) &&
1961+
ws_blank_line(patch + 1, plen, ws_rule))
19611962
is_blank_context = 1;
19621963
case '-':
19631964
memcpy(old, patch + 1, plen);
@@ -1985,7 +1986,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
19851986
(first == '+' ? 0 : LINE_COMMON));
19861987
new += added;
19871988
if (first == '+' &&
1988-
added == 1 && new[-1] == '\n')
1989+
(ws_rule & WS_BLANK_AT_EOF) &&
1990+
ws_blank_line(patch + 1, plen, ws_rule))
19891991
added_blank_line = 1;
19901992
break;
19911993
case '@': case '\\':

t/t4124-apply-ws-rule.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,17 @@ test_expect_success 'blank at EOF with --whitespace=error' '
227227
grep "new blank line at EOF" error
228228
'
229229

230+
test_expect_success 'blank but not empty at EOF' '
231+
{ echo a; echo b; echo c; } >one &&
232+
git add one &&
233+
echo " " >>one &&
234+
cat one >expect &&
235+
git diff -- one >patch &&
236+
237+
git checkout one &&
238+
git apply --whitespace=warn patch 2>error &&
239+
test_cmp expect one &&
240+
grep "new blank line at EOF" error
241+
'
242+
230243
test_done

0 commit comments

Comments
 (0)