3 test_description
='sparse checkout builtin tests'
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' '
20 mkdir folder1 folder2 deep &&
21 mkdir deep/deeper1 deep/deeper2 &&
22 mkdir deep/deeper1/deepest &&
28 cp a deep/deeper1/deepest &&
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 &&
48 cp repo/.git/info/sparse-checkout expect &&
49 git -C repo sparse-checkout list >list &&
53 test_expect_success
'git sparse-checkout init' '
54 git -C repo sparse-checkout init &&
59 test_cmp expect repo/.git/info/sparse-checkout &&
60 test_cmp_config -C repo true core.sparsecheckout &&
61 list_files repo >dir &&
66 test_expect_success
'git sparse-checkout list after init' '
67 git -C repo sparse-checkout list >actual &&
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 &&
83 test_cmp expect repo/.git/info/sparse-checkout &&
84 list_files repo >dir &&
93 test_expect_success
'clone --sparse' '
94 git clone --sparse repo clone &&
95 git -C clone sparse-checkout list >actual &&
100 test_cmp expect actual &&
101 list_files clone >dir &&
106 test_expect_success
'set enables config' '
107 git init 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 &&
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 &&
139 test_expect_success
'set sparse-checkout using --stdin' '
140 cat >expect <<-EOF &&
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 &&
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 &&
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 &&
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 &&
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 &&
212 test_cmp expect dir &&
213 list_files repo/deep >dir &&
214 cat >expect <<-EOF &&
218 test_cmp expect dir &&
219 list_files repo/deep/deeper1 >dir &&
220 cat >expect <<-EOF &&
224 test_cmp expect dir &&
225 cat >expect <<-EOF &&
232 /deep/deeper1/deepest/
234 test_cmp expect repo/.git/info/sparse-checkout &&
235 git -C repo sparse-checkout set --stdin 2>err <<-EOF &&
239 test_must_be_empty err &&
240 cat >expect <<-EOF &&
245 list_files repo >dir &&
249 test_expect_success
'cone mode: list' '
250 cat >expect <<-EOF &&
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 &&
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 &&
287 test_expect_success
'revert to old sparse-checkout on empty update' '
288 git init empty-test &&
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 &&
334 test_cmp expect repo/.git/info/sparse-checkout &&
335 list_files repo >dir &&
336 cat >expect <<-EOF &&
343 test_expect_success
'interaction with submodules' '
344 git clone repo super &&
348 git submodule add ../repo modules/child &&
350 git commit -m "add submodule" &&
351 git sparse-checkout init --cone &&
352 git sparse-checkout set folder1
354 list_files super >dir &&
355 cat >expect <<-\EOF &&
360 test_cmp expect dir &&
361 list_files super/modules/child >dir &&
362 cat >expect <<-\EOF &&