3 test_description
='sparse checkout tests
5 * (tag: removed, main) removed
7 * (HEAD, tag: top) modified and added
15 .
"$TEST_DIRECTORY"/lib-read-tree.sh
17 test_expect_success
'setup' '
19 echo modified >>init.t &&
21 cat >expected <<-EOF &&
22 100644 $(git hash-object init.t) 0 init.t
23 100644 $EMPTY_BLOB 0 sub/added
24 100644 $EMPTY_BLOB 0 sub/addedtoo
25 100644 $EMPTY_BLOB 0 subsub/added
27 cat >expected.swt <<-\EOF &&
35 touch sub/added sub/addedtoo subsub/added &&
36 git add init.t sub/added sub/addedtoo subsub/added &&
37 git commit -m "modified and added" &&
40 git commit -m removed &&
43 git ls-files --stage >result &&
44 test_cmp expected result
47 test_expect_success
'read-tree without .git/info/sparse-checkout' '
48 read_tree_u_must_succeed -m -u HEAD &&
49 git ls-files --stage >result &&
50 test_cmp expected result &&
51 git ls-files -t >result &&
52 test_cmp expected.swt result
55 test_expect_success
'read-tree with .git/info/sparse-checkout but disabled' '
56 echo >.git/info/sparse-checkout &&
57 read_tree_u_must_succeed -m -u HEAD &&
58 git ls-files -t >result &&
59 test_cmp expected.swt result &&
64 test_expect_success
'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
65 git config core.sparsecheckout true &&
66 echo >.git/info/sparse-checkout &&
67 read_tree_u_must_succeed --no-sparse-checkout -m -u HEAD &&
68 git ls-files -t >result &&
69 test_cmp expected.swt result &&
74 test_expect_success
'read-tree with empty .git/info/sparse-checkout' '
75 git config core.sparsecheckout true &&
76 echo >.git/info/sparse-checkout &&
77 read_tree_u_must_succeed -m -u HEAD &&
78 git ls-files --stage >result &&
79 test_cmp expected result &&
80 git ls-files -t >result &&
81 cat >expected.swt <<-\EOF &&
87 test_cmp expected.swt result &&
92 test_expect_success
'match directories with trailing slash' '
93 cat >expected.swt-noinit <<-\EOF &&
100 echo sub/ > .git/info/sparse-checkout &&
101 read_tree_u_must_succeed -m -u HEAD &&
102 git ls-files -t > result &&
103 test_cmp expected.swt-noinit result &&
108 test_expect_success
'match directories without trailing slash' '
109 echo sub >.git/info/sparse-checkout &&
110 read_tree_u_must_succeed -m -u HEAD &&
111 git ls-files -t >result &&
112 test_cmp expected.swt-noinit result &&
117 test_expect_success
'match directories with negated patterns' '
118 cat >expected.swt-negation <<\EOF &&
125 cat >.git/info/sparse-checkout <<\EOF &&
129 git read-tree -m -u HEAD &&
130 git ls-files -t >result &&
131 test_cmp expected.swt-negation result &&
133 test ! -f sub/added &&
137 test_expect_success
'match directories with negated patterns (2)' '
138 cat >expected.swt-negation2 <<\EOF &&
145 cat >.git/info/sparse-checkout <<\EOF &&
150 git read-tree -m -u HEAD &&
151 git ls-files -t >result &&
152 test_cmp expected.swt-negation2 result &&
155 test ! -f sub/addedtoo
158 test_expect_success
'match directory pattern' '
159 echo "s?b" >.git/info/sparse-checkout &&
160 read_tree_u_must_succeed -m -u HEAD &&
161 git ls-files -t >result &&
162 test_cmp expected.swt-noinit result &&
167 test_expect_success
'checkout area changes' '
168 cat >expected.swt-nosub <<-\EOF &&
175 echo init.t >.git/info/sparse-checkout &&
176 read_tree_u_must_succeed -m -u HEAD &&
177 git ls-files -t >result &&
178 test_cmp expected.swt-nosub result &&
183 test_expect_success
'read-tree updates worktree, absent case' '
184 echo sub/added >.git/info/sparse-checkout &&
185 git checkout -f top &&
186 read_tree_u_must_succeed -m -u HEAD^ &&
190 test_expect_success
'read-tree will not throw away dirty changes, non-sparse' '
191 echo "/*" >.git/info/sparse-checkout &&
192 read_tree_u_must_succeed -m -u HEAD &&
194 echo dirty >init.t &&
195 read_tree_u_must_fail -m -u HEAD^ &&
196 test_path_is_file init.t &&
200 test_expect_success
'read-tree will not throw away dirty changes, sparse' '
201 echo "/*" >.git/info/sparse-checkout &&
202 read_tree_u_must_succeed -m -u HEAD &&
204 echo dirty >init.t &&
205 echo sub/added >.git/info/sparse-checkout &&
206 read_tree_u_must_fail -m -u HEAD^ &&
207 test_path_is_file init.t &&
211 test_expect_success
'read-tree updates worktree, dirty case' '
212 echo sub/added >.git/info/sparse-checkout &&
213 git checkout -f top &&
214 echo dirty >init.t &&
215 read_tree_u_must_fail -m -u HEAD^ &&
216 grep -q dirty init.t &&
220 test_expect_success
'read-tree removes worktree, dirty case' '
221 echo init.t >.git/info/sparse-checkout &&
222 git checkout -f top &&
224 read_tree_u_must_succeed -m -u HEAD^ &&
228 test_expect_success
'read-tree adds to worktree, absent case' '
229 echo init.t >.git/info/sparse-checkout &&
230 git checkout -f removed &&
231 read_tree_u_must_succeed -u -m HEAD^ &&
235 test_expect_success
'read-tree adds to worktree, dirty case' '
236 echo init.t >.git/info/sparse-checkout &&
237 git checkout -f removed &&
239 echo dirty >sub/added &&
240 read_tree_u_must_succeed -u -m HEAD^ &&
241 grep -q dirty sub/added
244 test_expect_success
'index removal and worktree narrowing at the same time' '
245 echo init.t >.git/info/sparse-checkout &&
246 echo sub/added >>.git/info/sparse-checkout &&
247 git checkout -f top &&
248 echo init.t >.git/info/sparse-checkout &&
249 git checkout removed &&
250 git ls-files sub/added >result &&
251 test ! -f sub/added &&
252 test_must_be_empty result
255 test_expect_success
'read-tree --reset removes outside worktree' '
256 echo init.t >.git/info/sparse-checkout &&
257 git checkout -f top &&
258 git reset --hard removed &&
259 git ls-files sub/added >result &&
260 test_must_be_empty result
263 test_expect_success
'print warnings when some worktree updates disabled' '
264 echo sub >.git/info/sparse-checkout &&
265 git checkout -f init &&
267 touch sub/added sub/addedtoo &&
268 # Use -q to suppress "Previous HEAD position" and "Head is now at" msgs
269 git checkout -q top 2>actual &&
270 cat >expected <<\EOF &&
271 warning: The following paths were already present and thus not updated despite sparse patterns:
275 After fixing the above paths, you may want to run `git sparse-checkout reapply`.
277 test_cmp expected actual
280 test_expect_success
'checkout without --ignore-skip-worktree-bits' '
281 echo "*" >.git/info/sparse-checkout &&
282 git checkout -f top &&
283 test_path_is_file init.t &&
284 echo sub >.git/info/sparse-checkout &&
286 echo modified >> sub/added &&
288 test_path_is_missing init.t &&
289 git diff --exit-code HEAD
292 test_expect_success
'checkout with --ignore-skip-worktree-bits' '
293 echo "*" >.git/info/sparse-checkout &&
294 git checkout -f top &&
295 test_path_is_file init.t &&
296 echo sub >.git/info/sparse-checkout &&
298 echo modified >> sub/added &&
299 git checkout --ignore-skip-worktree-bits . &&
300 test_path_is_file init.t &&
301 git diff --exit-code HEAD