Skip to content

Commit 8837d33

Browse files
chmallongitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 593ce2b commit 8837d33

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
18881888

18891889
ecbdata.ws_rule = data.ws_rule;
18901890
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;
18921892

18931893
if (blank_at_eof) {
18941894
static char *err;

t/t4019-diff-wserror.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ test_expect_success 'trailing empty lines (2)' '
178178
179179
'
180180

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+
181190
test_expect_success 'do not color trailing cr in context' '
182191
git config --unset core.whitespace
183192
rm -f .gitattributes &&

0 commit comments

Comments
 (0)