3 test_description
='sparse checkout builtin tests'
7 test_expect_success
'setup' '
12 mkdir folder1 folder2 deep &&
13 mkdir deep/deeper1 deep/deeper2 &&
14 mkdir deep/deeper1/deepest &&
20 cp a deep/deeper1/deepest &&
22 git commit -m "initial commit"
26 test_expect_success
'git sparse-checkout list (empty)' '
27 git -C repo sparse-checkout list >list 2>err &&
28 test_must_be_empty list &&
29 test_i18ngrep "this worktree is not sparse (sparse-checkout file may not exist)" err
32 test_expect_success
'git sparse-checkout list (populated)' '
33 test_when_finished rm -f repo/.git/info/sparse-checkout &&
34 cat >repo/.git/info/sparse-checkout <<-EOF &&
40 cp repo/.git/info/sparse-checkout expect &&
41 git -C repo sparse-checkout list >list &&
45 test_expect_success
'git sparse-checkout init' '
46 git -C repo sparse-checkout init &&
51 test_cmp expect repo/.git/info/sparse-checkout &&
52 test_cmp_config -C repo true core.sparsecheckout &&
58 test_expect_success
'git sparse-checkout list after init' '
59 git -C repo sparse-checkout list >actual &&
64 test_cmp expect actual
67 test_expect_success
'init with existing sparse-checkout' '
68 echo "*folder*" >> repo/.git/info/sparse-checkout &&
69 git -C repo sparse-checkout init &&
75 test_cmp expect repo/.git/info/sparse-checkout &&
85 test_expect_success
'clone --sparse' '
86 git clone --sparse repo clone &&
87 git -C clone sparse-checkout list >actual &&
92 test_cmp expect actual &&
98 test_expect_success
'set enables config' '
99 git init empty-config &&
102 test_commit test file &&
103 test_path_is_missing .git/config.worktree &&
104 test_must_fail git sparse-checkout set nothing &&
105 test_path_is_file .git/config.worktree &&
106 test_must_fail git config core.sparseCheckout &&
107 git sparse-checkout set "/*" &&
108 test_cmp_config true core.sparseCheckout
112 test_expect_success
'set sparse-checkout using builtin' '
113 git -C repo sparse-checkout set "/*" "!/*/" "*folder*" &&
114 cat >expect <<-EOF &&
119 git -C repo sparse-checkout list >actual &&
120 test_cmp expect actual &&
121 test_cmp expect repo/.git/info/sparse-checkout &&
123 cat >expect <<-EOF &&
131 test_expect_success
'set sparse-checkout using --stdin' '
132 cat >expect <<-EOF &&
138 git -C repo sparse-checkout set --stdin <expect &&
139 git -C repo sparse-checkout list >actual &&
140 test_cmp expect actual &&
141 test_cmp expect repo/.git/info/sparse-checkout &&
143 cat >expect <<-EOF &&
151 test_expect_success
'cone mode: match patterns' '
152 git -C repo config --worktree core.sparseCheckoutCone true &&
153 rm -rf repo/a repo/folder1 repo/folder2 &&
154 git -C repo read-tree -mu HEAD 2>err &&
155 test_i18ngrep ! "disabling cone patterns" err &&
156 git -C repo reset --hard &&
158 cat >expect <<-EOF &&
166 test_expect_success
'cone mode: warn on bad pattern' '
167 test_when_finished mv sparse-checkout repo/.git/info/ &&
168 cp repo/.git/info/sparse-checkout . &&
169 echo "!/deep/deeper/*" >>repo/.git/info/sparse-checkout &&
170 git -C repo read-tree -mu HEAD 2>err &&
171 test_i18ngrep "unrecognized negative pattern" err
174 test_expect_success
'sparse-checkout disable' '
175 test_when_finished rm -rf repo/.git/info/sparse-checkout &&
176 git -C repo sparse-checkout disable &&
177 test_path_is_file repo/.git/info/sparse-checkout &&
178 git -C repo config --list >config &&
179 test_must_fail git config core.sparseCheckout &&
181 cat >expect <<-EOF &&
190 test_expect_success
'cone mode: init and set' '
191 git -C repo sparse-checkout init --cone &&
192 git -C repo config --list >config &&
193 test_i18ngrep "core.sparsecheckoutcone=true" config &&
196 test_cmp expect dir &&
197 git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
198 test_must_be_empty err &&
200 cat >expect <<-EOF &&
204 test_cmp expect dir &&
206 cat >expect <<-EOF &&
210 test_cmp expect dir &&
211 ls repo/deep/deeper1 >dir &&
212 cat >expect <<-EOF &&
216 test_cmp expect dir &&
217 cat >expect <<-EOF &&
224 /deep/deeper1/deepest/
226 test_cmp expect repo/.git/info/sparse-checkout &&
227 git -C repo sparse-checkout set --stdin 2>err <<-EOF &&
231 test_must_be_empty err &&
232 cat >expect <<-EOF &&
241 test_expect_success
'cone mode: set with nested folders' '
242 git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err &&
243 test_line_count = 0 err &&
244 cat >expect <<-EOF &&
249 test_cmp repo/.git/info/sparse-checkout expect
252 test_expect_success
'revert to old sparse-checkout on bad update' '
253 echo update >repo/deep/deeper2/a &&
254 cp repo/.git/info/sparse-checkout expect &&
255 test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err &&
256 test_i18ngrep "Cannot update sparse checkout" err &&
257 test_cmp repo/.git/info/sparse-checkout expect &&
259 cat >expect <<-EOF &&
267 test_expect_success
'revert to old sparse-checkout on empty update' '
268 git init empty-test &&
272 git commit -m "test" &&
273 test_must_fail git sparse-checkout set nothing 2>err &&
274 test_i18ngrep "Sparse checkout leaves no entry on working directory" err &&
275 test_i18ngrep ! ".git/index.lock" err &&
276 git sparse-checkout set file
280 test_expect_success
'fail when lock is taken' '
281 test_when_finished rm -rf repo/.git/info/sparse-checkout.lock &&
282 touch repo/.git/info/sparse-checkout.lock &&
283 test_must_fail git -C repo sparse-checkout set deep 2>err &&
284 test_i18ngrep "File exists" err