1#!/bin/sh
23
test_description='diff whitespace error detection'
45
. ./test-lib.sh
67
test_expect_success setup '
89
git config diff.color.whitespace "blue reverse" &&
10>F &&
11git add F &&
12echo " Eight SP indent" >>F &&
13echo " HT and SP indent" >>F &&
14echo "With trailing SP " >>F &&
15echo "No problem" >>F
1617
'
1819
blue_grep='7;34m' ;# ESC [ 7 ; 3 4 m
2021
test_expect_success default '
2223
git diff --color >output
24grep "$blue_grep" output >error
25grep -v "$blue_grep" output >normal
2627
grep Eight normal >/dev/null &&
28grep HT error >/dev/null &&
29grep With error >/dev/null &&
30grep No normal >/dev/null
3132
'
3334
test_expect_success 'without -trail' '
3536
git config core.whitespace -trail
37git diff --color >output
38grep "$blue_grep" output >error
39grep -v "$blue_grep" output >normal
4041
grep Eight normal >/dev/null &&
42grep HT error >/dev/null &&
43grep With normal >/dev/null &&
44grep No normal >/dev/null
4546
'
4748
test_expect_success 'without -trail (attribute)' '
4950
git config --unset core.whitespace
51echo "F whitespace=-trail" >.gitattributes
52git diff --color >output
53grep "$blue_grep" output >error
54grep -v "$blue_grep" output >normal
5556
grep Eight normal >/dev/null &&
57grep HT error >/dev/null &&
58grep With normal >/dev/null &&
59grep No normal >/dev/null
6061
'
6263
test_expect_success 'without -space' '
6465
rm -f .gitattributes
66git config core.whitespace -space
67git diff --color >output
68grep "$blue_grep" output >error
69grep -v "$blue_grep" output >normal
7071
grep Eight normal >/dev/null &&
72grep HT normal >/dev/null &&
73grep With error >/dev/null &&
74grep No normal >/dev/null
7576
'
7778
test_expect_success 'without -space (attribute)' '
7980
git config --unset core.whitespace
81echo "F whitespace=-space" >.gitattributes
82git diff --color >output
83grep "$blue_grep" output >error
84grep -v "$blue_grep" output >normal
8586
grep Eight normal >/dev/null &&
87grep HT normal >/dev/null &&
88grep With error >/dev/null &&
89grep No normal >/dev/null
9091
'
9293
test_expect_success 'with indent-non-tab only' '
9495
rm -f .gitattributes
96git config core.whitespace indent,-trailing,-space
97git diff --color >output
98grep "$blue_grep" output >error
99grep -v "$blue_grep" output >normal
100101
grep Eight error >/dev/null &&
102grep HT normal >/dev/null &&
103grep With normal >/dev/null &&
104grep No normal >/dev/null
105106
'
107108
test_expect_success 'with indent-non-tab only (attribute)' '
109110
git config --unset core.whitespace
111echo "F whitespace=indent,-trailing,-space" >.gitattributes
112git diff --color >output
113grep "$blue_grep" output >error
114grep -v "$blue_grep" output >normal
115116
grep Eight error >/dev/null &&
117grep HT normal >/dev/null &&
118grep With normal >/dev/null &&
119grep No normal >/dev/null
120121
'
122123
test_done