mailinfo: treat header values as C strings
[git/debian.git] / t / t1091-sparse-checkout-builtin.sh
blobff7f8f7a1fac6674286233b43c63d62cfcef448f
1 #!/bin/sh
3 test_description='sparse checkout builtin tests'
5 . ./test-lib.sh
7 list_files() {
8 # Do not replace this with 'ls "$1"', as "ls" with BSD-lineage
9 # enables "-A" by default for root and ends up including ".git" and
10 # such in its output. (Note, though, that running the test suite as
11 # root is generally not recommended.)
12 (cd "$1" && printf '%s\n' *)
15 test_expect_success 'setup' '
16 git init repo &&
18 cd repo &&
19 echo "initial" >a &&
20 mkdir folder1 folder2 deep &&
21 mkdir deep/deeper1 deep/deeper2 &&
22 mkdir deep/deeper1/deepest &&
23 cp a folder1 &&
24 cp a folder2 &&
25 cp a deep &&
26 cp a deep/deeper1 &&
27 cp a deep/deeper2 &&
28 cp a deep/deeper1/deepest &&
29 git add . &&
30 git commit -m "initial commit"
34 test_expect_success 'git sparse-checkout list (empty)' '
35 git -C repo sparse-checkout list >list 2>err &&
36 test_must_be_empty list &&
37 test_i18ngrep "this worktree is not sparse (sparse-checkout file may not exist)" err
40 test_expect_success 'git sparse-checkout list (populated)' '
41 test_when_finished rm -f repo/.git/info/sparse-checkout &&
42 cat >repo/.git/info/sparse-checkout <<-EOF &&
43 /folder1/*
44 /deep/
45 **/a
46 !*bin*
47 EOF
48 cp repo/.git/info/sparse-checkout expect &&
49 git -C repo sparse-checkout list >list &&
50 test_cmp expect list
53 test_expect_success 'git sparse-checkout init' '
54 git -C repo sparse-checkout init &&
55 cat >expect <<-EOF &&
57 !/*/
58 EOF
59 test_cmp expect repo/.git/info/sparse-checkout &&
60 test_cmp_config -C repo true core.sparsecheckout &&
61 list_files repo >dir &&
62 echo a >expect &&
63 test_cmp expect dir
66 test_expect_success 'git sparse-checkout list after init' '
67 git -C repo sparse-checkout list >actual &&
68 cat >expect <<-EOF &&
70 !/*/
71 EOF
72 test_cmp expect actual
75 test_expect_success 'init with existing sparse-checkout' '
76 echo "*folder*" >> repo/.git/info/sparse-checkout &&
77 git -C repo sparse-checkout init &&
78 cat >expect <<-EOF &&
80 !/*/
81 *folder*
82 EOF
83 test_cmp expect repo/.git/info/sparse-checkout &&
84 list_files repo >dir &&
85 cat >expect <<-EOF &&
87 folder1
88 folder2
89 EOF
90 test_cmp expect dir
93 test_expect_success 'clone --sparse' '
94 git clone --sparse repo clone &&
95 git -C clone sparse-checkout list >actual &&
96 cat >expect <<-EOF &&
98 !/*/
99 EOF
100 test_cmp expect actual &&
101 list_files clone >dir &&
102 echo a >expect &&
103 test_cmp expect dir
106 test_expect_success 'set enables config' '
107 git init empty-config &&
109 cd empty-config &&
110 test_commit test file &&
111 test_path_is_missing .git/config.worktree &&
112 test_must_fail git sparse-checkout set nothing &&
113 test_path_is_file .git/config.worktree &&
114 test_must_fail git config core.sparseCheckout &&
115 git sparse-checkout set "/*" &&
116 test_cmp_config true core.sparseCheckout
120 test_expect_success 'set sparse-checkout using builtin' '
121 git -C repo sparse-checkout set "/*" "!/*/" "*folder*" &&
122 cat >expect <<-EOF &&
124 !/*/
125 *folder*
127 git -C repo sparse-checkout list >actual &&
128 test_cmp expect actual &&
129 test_cmp expect repo/.git/info/sparse-checkout &&
130 list_files repo >dir &&
131 cat >expect <<-EOF &&
133 folder1
134 folder2
136 test_cmp expect dir
139 test_expect_success 'set sparse-checkout using --stdin' '
140 cat >expect <<-EOF &&
142 !/*/
143 /folder1/
144 /folder2/
146 git -C repo sparse-checkout set --stdin <expect &&
147 git -C repo sparse-checkout list >actual &&
148 test_cmp expect actual &&
149 test_cmp expect repo/.git/info/sparse-checkout &&
150 list_files repo >dir &&
151 cat >expect <<-EOF &&
153 folder1
154 folder2
156 test_cmp expect dir
159 test_expect_success 'cone mode: match patterns' '
160 git -C repo config --worktree core.sparseCheckoutCone true &&
161 rm -rf repo/a repo/folder1 repo/folder2 &&
162 git -C repo read-tree -mu HEAD 2>err &&
163 test_i18ngrep ! "disabling cone patterns" err &&
164 git -C repo reset --hard &&
165 list_files repo >dir &&
166 cat >expect <<-EOF &&
168 folder1
169 folder2
171 test_cmp expect dir
174 test_expect_success 'cone mode: warn on bad pattern' '
175 test_when_finished mv sparse-checkout repo/.git/info/ &&
176 cp repo/.git/info/sparse-checkout . &&
177 echo "!/deep/deeper/*" >>repo/.git/info/sparse-checkout &&
178 git -C repo read-tree -mu HEAD 2>err &&
179 test_i18ngrep "unrecognized negative pattern" err
182 test_expect_success 'sparse-checkout disable' '
183 test_when_finished rm -rf repo/.git/info/sparse-checkout &&
184 git -C repo sparse-checkout disable &&
185 test_path_is_file repo/.git/info/sparse-checkout &&
186 git -C repo config --list >config &&
187 test_must_fail git config core.sparseCheckout &&
188 list_files repo >dir &&
189 cat >expect <<-EOF &&
191 deep
192 folder1
193 folder2
195 test_cmp expect dir
198 test_expect_success 'cone mode: init and set' '
199 git -C repo sparse-checkout init --cone &&
200 git -C repo config --list >config &&
201 test_i18ngrep "core.sparsecheckoutcone=true" config &&
202 list_files repo >dir &&
203 echo a >expect &&
204 test_cmp expect dir &&
205 git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
206 test_must_be_empty err &&
207 list_files repo >dir &&
208 cat >expect <<-EOF &&
210 deep
212 test_cmp expect dir &&
213 list_files repo/deep >dir &&
214 cat >expect <<-EOF &&
216 deeper1
218 test_cmp expect dir &&
219 list_files repo/deep/deeper1 >dir &&
220 cat >expect <<-EOF &&
222 deepest
224 test_cmp expect dir &&
225 cat >expect <<-EOF &&
227 !/*/
228 /deep/
229 !/deep/*/
230 /deep/deeper1/
231 !/deep/deeper1/*/
232 /deep/deeper1/deepest/
234 test_cmp expect repo/.git/info/sparse-checkout &&
235 git -C repo sparse-checkout set --stdin 2>err <<-EOF &&
236 folder1
237 folder2
239 test_must_be_empty err &&
240 cat >expect <<-EOF &&
242 folder1
243 folder2
245 list_files repo >dir &&
246 test_cmp expect dir
249 test_expect_success 'cone mode: list' '
250 cat >expect <<-EOF &&
251 folder1
252 folder2
254 git -C repo sparse-checkout set --stdin <expect &&
255 git -C repo sparse-checkout list >actual 2>err &&
256 test_must_be_empty err &&
257 test_cmp expect actual
260 test_expect_success 'cone mode: set with nested folders' '
261 git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err &&
262 test_line_count = 0 err &&
263 cat >expect <<-EOF &&
265 !/*/
266 /deep/
268 test_cmp repo/.git/info/sparse-checkout expect
271 test_expect_success 'revert to old sparse-checkout on bad update' '
272 test_when_finished git -C repo reset --hard &&
273 echo update >repo/deep/deeper2/a &&
274 cp repo/.git/info/sparse-checkout expect &&
275 test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err &&
276 test_i18ngrep "cannot set sparse-checkout patterns" err &&
277 test_cmp repo/.git/info/sparse-checkout expect &&
278 list_files repo/deep >dir &&
279 cat >expect <<-EOF &&
281 deeper1
282 deeper2
284 test_cmp dir expect
287 test_expect_success 'revert to old sparse-checkout on empty update' '
288 git init empty-test &&
290 echo >file &&
291 git add file &&
292 git commit -m "test" &&
293 test_must_fail git sparse-checkout set nothing 2>err &&
294 test_i18ngrep "Sparse checkout leaves no entry on working directory" err &&
295 test_i18ngrep ! ".git/index.lock" err &&
296 git sparse-checkout set file
300 test_expect_success 'fail when lock is taken' '
301 test_when_finished rm -rf repo/.git/info/sparse-checkout.lock &&
302 touch repo/.git/info/sparse-checkout.lock &&
303 test_must_fail git -C repo sparse-checkout set deep 2>err &&
304 test_i18ngrep "File exists" err
307 test_expect_success '.gitignore should not warn about cone mode' '
308 git -C repo config --worktree core.sparseCheckoutCone true &&
309 echo "**/bin/*" >repo/.gitignore &&
310 git -C repo reset --hard 2>err &&
311 test_i18ngrep ! "disabling cone patterns" err
314 test_expect_success 'sparse-checkout (init|set|disable) fails with dirty status' '
315 git clone repo dirty &&
316 echo dirty >dirty/folder1/a &&
317 test_must_fail git -C dirty sparse-checkout init &&
318 test_must_fail git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* &&
319 test_must_fail git -C dirty sparse-checkout disable &&
320 git -C dirty reset --hard &&
321 git -C dirty sparse-checkout init &&
322 git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* &&
323 git -C dirty sparse-checkout disable
326 test_expect_success 'cone mode: set with core.ignoreCase=true' '
327 git -C repo sparse-checkout init --cone &&
328 git -C repo -c core.ignoreCase=true sparse-checkout set folder1 &&
329 cat >expect <<-EOF &&
331 !/*/
332 /folder1/
334 test_cmp expect repo/.git/info/sparse-checkout &&
335 list_files repo >dir &&
336 cat >expect <<-EOF &&
338 folder1
340 test_cmp expect dir
343 test_expect_success 'interaction with submodules' '
344 git clone repo super &&
346 cd super &&
347 mkdir modules &&
348 git submodule add ../repo modules/child &&
349 git add . &&
350 git commit -m "add submodule" &&
351 git sparse-checkout init --cone &&
352 git sparse-checkout set folder1
353 ) &&
354 list_files super >dir &&
355 cat >expect <<-\EOF &&
357 folder1
358 modules
360 test_cmp expect dir &&
361 list_files super/modules/child >dir &&
362 cat >expect <<-\EOF &&
364 deep
365 folder1
366 folder2
368 test_cmp expect dir
371 test_done