diff --check: correct line numbers of new blank lines at EOF
The whitespace check printed the value of the wrong variable, i.e. the beginning of the block of blank lines at the EOF (possibly absent) in the old file. As "git diff --check" is used by users to check their changes before making a commit, we should point at the line number in the file after the change. Signed-off-by: Christoph Mallon <christoph.mallon@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christoph Mallon committed
Oct 10, 2010 at 19:24 UTC
8837d33595b78dc4a52038856bc9a5c3f4b2ff50
2 files changed
+10
-1
diff.c
+1
-1
@@ -1888,7 +1888,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
1888
1889
ecbdata.ws_rule = data.ws_rule;
1890
check_blank_at_eof(&mf1, &mf2, &ecbdata);
1891
- blank_at_eof = ecbdata.blank_at_eof_in_preimage;
1891
+ blank_at_eof = ecbdata.blank_at_eof_in_postimage;
1892
1893
if (blank_at_eof) {
1894
static char *err;
t/t4019-diff-wserror.sh
+9
@@ -178,6 +178,15 @@ test_expect_success 'trailing empty lines (2)' '
178
179
'
180
181
+test_expect_success 'checkdiff shows correct line number for trailing blank lines' '
182
+
183
+ printf "a\nb\n" > G &&
184
+ git add G &&
185
+ printf "x\nx\nx\na\nb\nc\n\n" > G &&
186
+ [ "$(git diff --check -- G)" = "G:7: new blank line at EOF." ]
187
+
188
+'
189
+
190
test_expect_success 'do not color trailing cr in context' '
191
git config --unset core.whitespace
192
rm -f .gitattributes &&