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 <gitster@pobox.com>
Junio C Hamano committed
Sep 4, 2009 at 02:25 UTC
94ea026b358f9fd5395d9344a80f2d5a50e93e1f
2 files changed
+17
-2
builtin-apply.c
+4
-2
@@ -1957,7 +1957,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
1957
is_blank_context = 1;
1958
break;
1959
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))
1962
is_blank_context = 1;
1963
case '-':
1964
memcpy(old, patch + 1, plen);
@@ -1985,7 +1986,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
1986
(first == '+' ? 0 : LINE_COMMON));
1987
new += added;
1988
if (first == '+' &&
1988
- added == 1 && new[-1] == '\n')
1989
+ (ws_rule & WS_BLANK_AT_EOF) &&
1990
+ ws_blank_line(patch + 1, plen, ws_rule))
1991
added_blank_line = 1;
1992
break;
1993
case '@': case '\\':
t/t4124-apply-ws-rule.sh
+13
@@ -227,4 +227,17 @@ test_expect_success 'blank at EOF with --whitespace=error' '
227
grep "new blank line at EOF" error
228
'
229
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
+
243
test_done