Skip to content

Commit

Permalink
Fix "diff --check" whitespace detection
Browse files Browse the repository at this point in the history
"diff --check" would only detect spaces before tabs if a tab was the
last character in the leading indent. Fix that and add a test case to
make sure the bug doesn't regress in the future.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Wincent Colaiuta authored and Junio C Hamano committed Dec 12, 2007
1 parent f604652 commit 86f8c23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 10 additions & 3 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,11 +1044,18 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
int i, spaces = 0, space_before_tab = 0, white_space_at_end = 0;

/* check space before tab */
for (i = 1; i < len && (line[i] == ' ' || line[i] == '\t'); i++)
for (i = 1; i < len; i++) {
if (line[i] == ' ')
spaces++;
if (line[i - 1] == '\t' && spaces)
space_before_tab = 1;
else if (line[i] == '\t') {
if (spaces) {
space_before_tab = 1;
break;
}
}
else
break;
}

/* check whitespace at line end */
if (line[len - 1] == '\n')
Expand Down
9 changes: 9 additions & 0 deletions t/t4015-diff-whitespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,13 @@ EOF
git diff -b > out
test_expect_success 'another test, with -b' 'git diff expect out'


test_expect_success 'check mixed spaces and tabs in indent' '
# This is indented with SP HT SP.
echo " foo();" > x &&
git diff --check | grep "space before tab"
'

test_done

0 comments on commit 86f8c23

Please sign in to comment.