t1092: stress test 'git sparse-checkout set'
[git/debian.git] / t / t1011-read-tree-sparse-checkout.sh
blobdd957be1b78c5690fc79495f501eea52e4467600
1 #!/bin/sh
3 test_description='sparse checkout tests
5 * (tag: removed, main) removed
6 | D sub/added
7 * (HEAD, tag: top) modified and added
8 | M init.t
9 | A sub/added
10 * (tag: init) init
11 A init.t
14 . ./test-lib.sh
15 . "$TEST_DIRECTORY"/lib-read-tree.sh
17 test_expect_success 'setup' '
18 test_commit init &&
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
26 EOF
27 cat >expected.swt <<-\EOF &&
28 H init.t
29 H sub/added
30 H sub/addedtoo
31 H subsub/added
32 EOF
34 mkdir sub subsub &&
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" &&
38 git tag top &&
39 git rm sub/added &&
40 git commit -m removed &&
41 git tag removed &&
42 git checkout top &&
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 &&
60 test -f init.t &&
61 test -f sub/added
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 &&
70 test -f init.t &&
71 test -f sub/added
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 &&
82 S init.t
83 S sub/added
84 S sub/addedtoo
85 S subsub/added
86 EOF
87 test_cmp expected.swt result &&
88 ! test -f init.t &&
89 ! test -f sub/added
92 test_expect_success 'match directories with trailing slash' '
93 cat >expected.swt-noinit <<-\EOF &&
94 S init.t
95 H sub/added
96 H sub/addedtoo
97 S subsub/added
98 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 &&
104 test ! -f init.t &&
105 test -f sub/added
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 &&
113 test ! -f init.t &&
114 test -f sub/added
117 test_expect_success 'match directories with negated patterns' '
118 cat >expected.swt-negation <<\EOF &&
119 S init.t
120 S sub/added
121 H sub/addedtoo
122 S subsub/added
125 cat >.git/info/sparse-checkout <<\EOF &&
127 !sub/added
129 git read-tree -m -u HEAD &&
130 git ls-files -t >result &&
131 test_cmp expected.swt-negation result &&
132 test ! -f init.t &&
133 test ! -f sub/added &&
134 test -f sub/addedtoo
137 test_expect_success 'match directories with negated patterns (2)' '
138 cat >expected.swt-negation2 <<\EOF &&
139 H init.t
140 H sub/added
141 S sub/addedtoo
142 H subsub/added
145 cat >.git/info/sparse-checkout <<\EOF &&
147 !sub
148 sub/added
150 git read-tree -m -u HEAD &&
151 git ls-files -t >result &&
152 test_cmp expected.swt-negation2 result &&
153 test -f init.t &&
154 test -f sub/added &&
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 &&
163 test ! -f init.t &&
164 test -f sub/added
167 test_expect_success 'checkout area changes' '
168 cat >expected.swt-nosub <<-\EOF &&
169 H init.t
170 S sub/added
171 S sub/addedtoo
172 S subsub/added
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 &&
179 test -f init.t &&
180 test ! -f sub/added
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^ &&
187 test ! -f init.t
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 &&
197 grep -q dirty 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 &&
208 grep -q dirty 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 &&
217 rm 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 &&
223 echo dirty >added &&
224 read_tree_u_must_succeed -m -u HEAD^ &&
225 grep -q dirty added
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^ &&
232 test ! -f sub/added
235 test_expect_success 'read-tree adds to worktree, dirty case' '
236 echo init.t >.git/info/sparse-checkout &&
237 git checkout -f removed &&
238 mkdir sub &&
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 &&
266 mkdir sub &&
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:
272 sub/added
273 sub/addedtoo
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 &&
285 git checkout &&
286 echo modified >> sub/added &&
287 git checkout . &&
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 &&
297 git 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
304 test_done