@@ -5,20 +5,16 @@ test_description=gitattributes
5
5
. ./test-lib.sh
6
6
7
7
attr_check () {
8
-
9
- path=" $1 "
10
- expect=" $2 "
8
+ path=" $1 " expect=" $2 "
11
9
12
10
git check-attr test -- " $path " > actual 2> err &&
13
11
echo " $path : test: $2 " > expect &&
14
12
test_cmp expect actual &&
15
13
test_line_count = 0 err
16
-
17
14
}
18
15
19
16
20
17
test_expect_success ' setup' '
21
-
22
18
mkdir -p a/b/d a/c b &&
23
19
(
24
20
echo "[attr]notest !test"
@@ -40,29 +36,27 @@ test_expect_success 'setup' '
40
36
(
41
37
echo "global test=global"
42
38
) >"$HOME"/global-gitattributes &&
43
- cat <<EOF >expect-all
44
- f: test: f
45
- a/f: test: f
46
- a/c/f: test: f
47
- a/g: test: a/g
48
- a/b/g: test: a/b/g
49
- b/g: test: unspecified
50
- a/b/h: test: a/b/h
51
- a/b/d/g: test: a/b/d/*
52
- onoff: test: unset
53
- offon: test: set
54
- no: notest: set
55
- no: test: unspecified
56
- a/b/d/no: notest: set
57
- a/b/d/no: test: a/b/d/*
58
- a/b/d/yes: notest: set
59
- a/b/d/yes: test: unspecified
60
- EOF
61
-
39
+ cat <<-EOF >expect-all
40
+ f: test: f
41
+ a/f: test: f
42
+ a/c/f: test: f
43
+ a/g: test: a/g
44
+ a/b/g: test: a/b/g
45
+ b/g: test: unspecified
46
+ a/b/h: test: a/b/h
47
+ a/b/d/g: test: a/b/d/*
48
+ onoff: test: unset
49
+ offon: test: set
50
+ no: notest: set
51
+ no: test: unspecified
52
+ a/b/d/no: notest: set
53
+ a/b/d/no: test: a/b/d/*
54
+ a/b/d/yes: notest: set
55
+ a/b/d/yes: test: unspecified
56
+ EOF
62
57
'
63
58
64
59
test_expect_success ' command line checks' '
65
-
66
60
test_must_fail git check-attr &&
67
61
test_must_fail git check-attr -- &&
68
62
test_must_fail git check-attr test &&
@@ -72,11 +66,9 @@ test_expect_success 'command line checks' '
72
66
echo "f" | test_must_fail git check-attr --stdin -- f &&
73
67
echo "f" | test_must_fail git check-attr --stdin test -- f &&
74
68
test_must_fail git check-attr "" -- f
75
-
76
69
'
77
70
78
71
test_expect_success ' attribute test' '
79
-
80
72
attr_check f f &&
81
73
attr_check a/f f &&
82
74
attr_check a/c/f f &&
@@ -90,20 +82,16 @@ test_expect_success 'attribute test' '
90
82
attr_check no unspecified &&
91
83
attr_check a/b/d/no "a/b/d/*" &&
92
84
attr_check a/b/d/yes unspecified
93
-
94
85
'
95
86
96
87
test_expect_success ' unnormalized paths' '
97
-
98
88
attr_check ./f f &&
99
89
attr_check ./a/g a/g &&
100
90
attr_check a/./g a/g &&
101
91
attr_check a/c/../b/g a/b/g
102
-
103
92
'
104
93
105
94
test_expect_success ' relative paths' '
106
-
107
95
(cd a && attr_check ../f f) &&
108
96
(cd a && attr_check f f) &&
109
97
(cd a && attr_check i a/i) &&
@@ -112,7 +100,6 @@ test_expect_success 'relative paths' '
112
100
(cd b && attr_check ../a/f f) &&
113
101
(cd b && attr_check ../a/g a/g) &&
114
102
(cd b && attr_check ../a/b/g a/b/g)
115
-
116
103
'
117
104
118
105
test_expect_success ' core.attributesfile' '
@@ -121,41 +108,43 @@ test_expect_success 'core.attributesfile' '
121
108
attr_check global global &&
122
109
git config core.attributesfile "~/global-gitattributes" &&
123
110
attr_check global global &&
124
- echo "global test=precedence" >> .gitattributes &&
111
+ echo "global test=precedence" >>.gitattributes &&
125
112
attr_check global precedence
126
113
'
127
114
128
115
test_expect_success ' attribute test: read paths from stdin' '
129
-
130
- grep -v notest < expect-all > expect &&
131
- sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
116
+ grep -v notest <expect-all >expect &&
117
+ sed -e "s/:.*//" <expect | git check-attr --stdin test >actual &&
132
118
test_cmp expect actual
133
119
'
134
120
135
121
test_expect_success ' attribute test: --all option' '
122
+ grep -v unspecified <expect-all | sort >specified-all &&
123
+ sed -e "s/:.*//" <expect-all | uniq >stdin-all &&
124
+ git check-attr --stdin --all <stdin-all | sort >actual &&
125
+ test_cmp specified-all actual
126
+ '
136
127
137
- grep -v unspecified < expect-all | sort > expect &&
138
- sed -e "s/:.*//" < expect-all | uniq |
139
- git check-attr --stdin --all | sort > actual &&
140
- test_cmp expect actual
128
+ test_expect_success ' attribute test: --cached option' '
129
+ : >empty &&
130
+ git check-attr --cached --stdin --all <stdin-all | sort >actual &&
131
+ test_cmp empty actual &&
132
+ git add .gitattributes a/.gitattributes a/b/.gitattributes &&
133
+ git check-attr --cached --stdin --all <stdin-all | sort >actual &&
134
+ test_cmp specified-all actual
141
135
'
142
136
143
137
test_expect_success ' root subdir attribute test' '
144
-
145
138
attr_check a/i a/i &&
146
139
attr_check subdir/a/i unspecified
147
-
148
140
'
149
141
150
142
test_expect_success ' setup bare' '
151
-
152
143
git clone --bare . bare.git &&
153
144
cd bare.git
154
-
155
145
'
156
146
157
147
test_expect_success ' bare repository: check that .gitattribute is ignored' '
158
-
159
148
(
160
149
echo "f test=f"
161
150
echo "a/i test=a/i"
@@ -165,11 +154,16 @@ test_expect_success 'bare repository: check that .gitattribute is ignored' '
165
154
attr_check a/c/f unspecified &&
166
155
attr_check a/i unspecified &&
167
156
attr_check subdir/a/i unspecified
157
+ '
168
158
159
+ test_expect_success ' bare repository: check that --cached honors index' '
160
+ GIT_INDEX_FILE=../.git/index \
161
+ git check-attr --cached --stdin --all <../stdin-all |
162
+ sort >actual &&
163
+ test_cmp ../specified-all actual
169
164
'
170
165
171
166
test_expect_success ' bare repository: test info/attributes' '
172
-
173
167
(
174
168
echo "f test=f"
175
169
echo "a/i test=a/i"
@@ -179,7 +173,6 @@ test_expect_success 'bare repository: test info/attributes' '
179
173
attr_check a/c/f f &&
180
174
attr_check a/i a/i &&
181
175
attr_check subdir/a/i unspecified
182
-
183
176
'
184
177
185
178
test_done
0 commit comments