diff --check: do not unconditionally complain about trailing empty lines
Recently "git diff --check" learned to detect new trailing blank lines just like "git apply --whitespace" does. However this check should not trigger unconditionally. This patch makes it honor the whitespace settings from core.whitespace and gitattributes. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 11, 2008 at 22:15 UTC
04c6e9e9ca34226db095bbaa1218030f99f0b7c6
2 files changed
+21
-2
diff.c
+2
-1
@@ -1631,7 +1631,8 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
1631
ecb.priv = &data;
1632
xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
1633
1634
- if (data.trailing_blanks_start) {
1634
+ if ((data.ws_rule & WS_TRAILING_SPACE) &&
1635
+ data.trailing_blanks_start) {
1636
fprintf(o->file, "%s:%d: ends with blank lines.\n",
1637
data.filename, data.trailing_blanks_start);
1638
data.status = 1; /* report errors */
t/t4019-diff-wserror.sh
+19
-1
@@ -13,7 +13,8 @@ test_expect_success setup '
13
echo " HT and SP indent" >>F &&
14
echo "With trailing SP " >>F &&
15
echo "Carriage ReturnQ" | tr Q "\015" >>F &&
16
- echo "No problem" >>F
16
+ echo "No problem" >>F &&
17
+ echo >>F
18
19
'
20
@@ -160,4 +161,21 @@ test_expect_success 'with cr-at-eol (attribute)' '
161
162
'
163
164
+test_expect_success 'trailing empty lines (1)' '
165
+
166
+ rm -f .gitattributes &&
167
+ test_must_fail git diff --check >output &&
168
+ grep "ends with blank lines." output &&
169
+ grep "trailing whitespace" output
170
+
171
+'
172
+
173
+test_expect_success 'trailing empty lines (2)' '
174
+
175
+ echo "F -whitespace" >.gitattributes &&
176
+ git diff --check >output &&
177
+ ! test -s output
178
+
179
+'
180
+
181
test_done