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>maint
parent
77b15bbd88
commit
94ea026b35
|
@ -1957,7 +1957,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
|
||||||
is_blank_context = 1;
|
is_blank_context = 1;
|
||||||
break;
|
break;
|
||||||
case ' ':
|
case ' ':
|
||||||
if (plen && patch[1] == '\n')
|
if (plen && (ws_rule & WS_BLANK_AT_EOF) &&
|
||||||
|
ws_blank_line(patch + 1, plen, ws_rule))
|
||||||
is_blank_context = 1;
|
is_blank_context = 1;
|
||||||
case '-':
|
case '-':
|
||||||
memcpy(old, patch + 1, plen);
|
memcpy(old, patch + 1, plen);
|
||||||
|
@ -1985,7 +1986,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
|
||||||
(first == '+' ? 0 : LINE_COMMON));
|
(first == '+' ? 0 : LINE_COMMON));
|
||||||
new += added;
|
new += added;
|
||||||
if (first == '+' &&
|
if (first == '+' &&
|
||||||
added == 1 && new[-1] == '\n')
|
(ws_rule & WS_BLANK_AT_EOF) &&
|
||||||
|
ws_blank_line(patch + 1, plen, ws_rule))
|
||||||
added_blank_line = 1;
|
added_blank_line = 1;
|
||||||
break;
|
break;
|
||||||
case '@': case '\\':
|
case '@': case '\\':
|
||||||
|
|
|
@ -227,4 +227,17 @@ test_expect_success 'blank at EOF with --whitespace=error' '
|
||||||
grep "new blank line at EOF" error
|
grep "new blank line at EOF" error
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'blank but not empty at EOF' '
|
||||||
|
{ echo a; echo b; echo c; } >one &&
|
||||||
|
git add one &&
|
||||||
|
echo " " >>one &&
|
||||||
|
cat one >expect &&
|
||||||
|
git diff -- one >patch &&
|
||||||
|
|
||||||
|
git checkout one &&
|
||||||
|
git apply --whitespace=warn patch 2>error &&
|
||||||
|
test_cmp expect one &&
|
||||||
|
grep "new blank line at EOF" error
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue