@@ -12,6 +12,13 @@ list_files() {
12
12
(cd " $1 " && printf ' %s\n' * )
13
13
}
14
14
15
+ check_files () {
16
+ list_files " $1 " > actual &&
17
+ shift &&
18
+ printf " %s\n" $@ > expect &&
19
+ test_cmp expect actual
20
+ }
21
+
15
22
test_expect_success ' setup' '
16
23
git init repo &&
17
24
(
@@ -58,9 +65,7 @@ test_expect_success 'git sparse-checkout init' '
58
65
EOF
59
66
test_cmp expect repo/.git/info/sparse-checkout &&
60
67
test_cmp_config -C repo true core.sparsecheckout &&
61
- list_files repo >dir &&
62
- echo a >expect &&
63
- test_cmp expect dir
68
+ check_files repo a
64
69
'
65
70
66
71
test_expect_success ' git sparse-checkout list after init' '
@@ -81,13 +86,7 @@ test_expect_success 'init with existing sparse-checkout' '
81
86
*folder*
82
87
EOF
83
88
test_cmp expect repo/.git/info/sparse-checkout &&
84
- list_files repo >dir &&
85
- cat >expect <<-EOF &&
86
- a
87
- folder1
88
- folder2
89
- EOF
90
- test_cmp expect dir
89
+ check_files repo a folder1 folder2
91
90
'
92
91
93
92
test_expect_success ' clone --sparse' '
@@ -98,9 +97,7 @@ test_expect_success 'clone --sparse' '
98
97
!/*/
99
98
EOF
100
99
test_cmp expect actual &&
101
- list_files clone >dir &&
102
- echo a >expect &&
103
- test_cmp expect dir
100
+ check_files clone a
104
101
'
105
102
106
103
test_expect_success ' set enables config' '
@@ -127,13 +124,7 @@ test_expect_success 'set sparse-checkout using builtin' '
127
124
git -C repo sparse-checkout list >actual &&
128
125
test_cmp expect actual &&
129
126
test_cmp expect repo/.git/info/sparse-checkout &&
130
- list_files repo >dir &&
131
- cat >expect <<-EOF &&
132
- a
133
- folder1
134
- folder2
135
- EOF
136
- test_cmp expect dir
127
+ check_files repo a folder1 folder2
137
128
'
138
129
139
130
test_expect_success ' set sparse-checkout using --stdin' '
@@ -147,13 +138,7 @@ test_expect_success 'set sparse-checkout using --stdin' '
147
138
git -C repo sparse-checkout list >actual &&
148
139
test_cmp expect actual &&
149
140
test_cmp expect repo/.git/info/sparse-checkout &&
150
- list_files repo >dir &&
151
- cat >expect <<-EOF &&
152
- a
153
- folder1
154
- folder2
155
- EOF
156
- test_cmp expect dir
141
+ check_files repo "a folder1 folder2"
157
142
'
158
143
159
144
test_expect_success ' cone mode: match patterns' '
@@ -162,13 +147,7 @@ test_expect_success 'cone mode: match patterns' '
162
147
git -C repo read-tree -mu HEAD 2>err &&
163
148
test_i18ngrep ! "disabling cone patterns" err &&
164
149
git -C repo reset --hard &&
165
- list_files repo >dir &&
166
- cat >expect <<-EOF &&
167
- a
168
- folder1
169
- folder2
170
- EOF
171
- test_cmp expect dir
150
+ check_files repo a folder1 folder2
172
151
'
173
152
174
153
test_expect_success ' cone mode: warn on bad pattern' '
@@ -185,14 +164,7 @@ test_expect_success 'sparse-checkout disable' '
185
164
test_path_is_file repo/.git/info/sparse-checkout &&
186
165
git -C repo config --list >config &&
187
166
test_must_fail git config core.sparseCheckout &&
188
- list_files repo >dir &&
189
- cat >expect <<-EOF &&
190
- a
191
- deep
192
- folder1
193
- folder2
194
- EOF
195
- test_cmp expect dir
167
+ check_files repo a deep folder1 folder2
196
168
'
197
169
198
170
test_expect_success ' cone mode: init and set' '
@@ -204,24 +176,9 @@ test_expect_success 'cone mode: init and set' '
204
176
test_cmp expect dir &&
205
177
git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
206
178
test_must_be_empty err &&
207
- list_files repo >dir &&
208
- cat >expect <<-EOF &&
209
- a
210
- deep
211
- EOF
212
- test_cmp expect dir &&
213
- list_files repo/deep >dir &&
214
- cat >expect <<-EOF &&
215
- a
216
- deeper1
217
- EOF
218
- test_cmp expect dir &&
219
- list_files repo/deep/deeper1 >dir &&
220
- cat >expect <<-EOF &&
221
- a
222
- deepest
223
- EOF
224
- test_cmp expect dir &&
179
+ check_files repo a deep &&
180
+ check_files repo/deep a deeper1 &&
181
+ check_files repo/deep/deeper1 a deepest &&
225
182
cat >expect <<-EOF &&
226
183
/*
227
184
!/*/
@@ -237,13 +194,7 @@ test_expect_success 'cone mode: init and set' '
237
194
folder2
238
195
EOF
239
196
test_must_be_empty err &&
240
- cat >expect <<-EOF &&
241
- a
242
- folder1
243
- folder2
244
- EOF
245
- list_files repo >dir &&
246
- test_cmp expect dir
197
+ check_files repo a folder1 folder2
247
198
'
248
199
249
200
test_expect_success ' cone mode: list' '
@@ -275,13 +226,7 @@ test_expect_success 'revert to old sparse-checkout on bad update' '
275
226
test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err &&
276
227
test_i18ngrep "cannot set sparse-checkout patterns" err &&
277
228
test_cmp repo/.git/info/sparse-checkout expect &&
278
- list_files repo/deep >dir &&
279
- cat >expect <<-EOF &&
280
- a
281
- deeper1
282
- deeper2
283
- EOF
284
- test_cmp dir expect
229
+ check_files repo/deep a deeper1 deeper2
285
230
'
286
231
287
232
test_expect_success ' revert to old sparse-checkout on empty update' '
@@ -332,12 +277,7 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' '
332
277
/folder1/
333
278
EOF
334
279
test_cmp expect repo/.git/info/sparse-checkout &&
335
- list_files repo >dir &&
336
- cat >expect <<-EOF &&
337
- a
338
- folder1
339
- EOF
340
- test_cmp expect dir
280
+ check_files repo a folder1
341
281
'
342
282
343
283
test_expect_success ' interaction with submodules' '
@@ -351,21 +291,8 @@ test_expect_success 'interaction with submodules' '
351
291
git sparse-checkout init --cone &&
352
292
git sparse-checkout set folder1
353
293
) &&
354
- list_files super >dir &&
355
- cat >expect <<-\EOF &&
356
- a
357
- folder1
358
- modules
359
- EOF
360
- test_cmp expect dir &&
361
- list_files super/modules/child >dir &&
362
- cat >expect <<-\EOF &&
363
- a
364
- deep
365
- folder1
366
- folder2
367
- EOF
368
- test_cmp expect dir
294
+ check_files super a folder1 modules &&
295
+ check_files super/modules/child a deep folder1 folder2
369
296
'
370
297
371
298
test_done
0 commit comments