From: Christoph Mallon Date: Sun, 10 Oct 2010 17:24:06 +0000 (+0200) Subject: diff --check: correct line numbers of new blank lines at EOF X-Git-Tag: v1.7.3.4~28^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8837d33595b78dc4a52038856bc9a5c3f4b2ff50;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/diff.c b/diff.c index a2d8c7f9a..38ba98932 100644 --- a/diff.c +++ b/diff.c @@ -1888,7 +1888,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b, ecbdata.ws_rule = data.ws_rule; check_blank_at_eof(&mf1, &mf2, &ecbdata); - blank_at_eof = ecbdata.blank_at_eof_in_preimage; + blank_at_eof = ecbdata.blank_at_eof_in_postimage; if (blank_at_eof) { static char *err; diff --git a/t/t4019-diff-wserror.sh b/t/t4019-diff-wserror.sh index f6d1f1eba..87df0aeb5 100755 --- a/t/t4019-diff-wserror.sh +++ b/t/t4019-diff-wserror.sh @@ -178,6 +178,15 @@ test_expect_success 'trailing empty lines (2)' ' ' +test_expect_success 'checkdiff shows correct line number for trailing blank lines' ' + + printf "a\nb\n" > G && + git add G && + printf "x\nx\nx\na\nb\nc\n\n" > G && + [ "$(git diff --check -- G)" = "G:7: new blank line at EOF." ] + +' + test_expect_success 'do not color trailing cr in context' ' git config --unset core.whitespace rm -f .gitattributes &&