t/README: add missing value for GIT_TEST_DEFAULT_REF_FORMAT
[git/gitster.git] / t / t1011-read-tree-sparse-checkout.sh
blob595b24c0adb3081230fe65884fd436e1f12896d4
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_CREATE_REPO_NO_TEMPLATE=1
15 TEST_PASSES_SANITIZE_LEAK=true
16 . ./test-lib.sh
17 . "$TEST_DIRECTORY"/lib-read-tree.sh
19 test_expect_success 'setup' '
20 test_commit init &&
21 echo modified >>init.t &&
23 cat >expected <<-EOF &&
24 100644 $(git hash-object init.t) 0 init.t
25 100644 $EMPTY_BLOB 0 sub/added
26 100644 $EMPTY_BLOB 0 sub/addedtoo
27 100644 $EMPTY_BLOB 0 subsub/added
28 EOF
29 cat >expected.swt <<-\EOF &&
30 H init.t
31 H sub/added
32 H sub/addedtoo
33 H subsub/added
34 EOF
36 mkdir sub subsub &&
37 touch sub/added sub/addedtoo subsub/added &&
38 git add init.t sub/added sub/addedtoo subsub/added &&
39 git commit -m "modified and added" &&
40 git tag top &&
41 git rm sub/added &&
42 git commit -m removed &&
43 git tag removed &&
44 git checkout top &&
45 git ls-files --stage >result &&
46 test_cmp expected result
49 test_expect_success 'read-tree without .git/info/sparse-checkout' '
50 read_tree_u_must_succeed -m -u HEAD &&
51 git ls-files --stage >result &&
52 test_cmp expected result &&
53 git ls-files -t >result &&
54 test_cmp expected.swt result
57 test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
58 mkdir .git/info &&
59 echo >.git/info/sparse-checkout &&
60 read_tree_u_must_succeed -m -u HEAD &&
61 git ls-files -t >result &&
62 test_cmp expected.swt result &&
63 test_path_is_file init.t &&
64 test_path_is_file sub/added
67 test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
68 git config core.sparsecheckout true &&
69 echo >.git/info/sparse-checkout &&
70 read_tree_u_must_succeed --no-sparse-checkout -m -u HEAD &&
71 git ls-files -t >result &&
72 test_cmp expected.swt result &&
73 test_path_is_file init.t &&
74 test_path_is_file sub/added
77 test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
78 git config core.sparsecheckout true &&
79 echo >.git/info/sparse-checkout &&
80 read_tree_u_must_succeed -m -u HEAD &&
81 git ls-files --stage >result &&
82 test_cmp expected result &&
83 git ls-files -t >result &&
84 cat >expected.swt <<-\EOF &&
85 S init.t
86 S sub/added
87 S sub/addedtoo
88 S subsub/added
89 EOF
90 test_cmp expected.swt result &&
91 test_path_is_missing init.t &&
92 test_path_is_missing sub/added
95 test_expect_success 'match directories with trailing slash' '
96 cat >expected.swt-noinit <<-\EOF &&
97 S init.t
98 H sub/added
99 H sub/addedtoo
100 S subsub/added
103 echo sub/ > .git/info/sparse-checkout &&
104 read_tree_u_must_succeed -m -u HEAD &&
105 git ls-files -t > result &&
106 test_cmp expected.swt-noinit result &&
107 test_path_is_missing init.t &&
108 test_path_is_file sub/added
111 test_expect_success 'match directories without trailing slash' '
112 echo sub >.git/info/sparse-checkout &&
113 read_tree_u_must_succeed -m -u HEAD &&
114 git ls-files -t >result &&
115 test_cmp expected.swt-noinit result &&
116 test_path_is_missing init.t &&
117 test_path_is_file sub/added
120 test_expect_success 'match directories with negated patterns' '
121 cat >expected.swt-negation <<\EOF &&
122 S init.t
123 S sub/added
124 H sub/addedtoo
125 S subsub/added
128 cat >.git/info/sparse-checkout <<\EOF &&
130 !sub/added
132 git read-tree -m -u HEAD &&
133 git ls-files -t >result &&
134 test_cmp expected.swt-negation result &&
135 test_path_is_missing init.t &&
136 test_path_is_missing sub/added &&
137 test_path_is_file sub/addedtoo
140 test_expect_success 'match directories with negated patterns (2)' '
141 cat >expected.swt-negation2 <<\EOF &&
142 H init.t
143 H sub/added
144 S sub/addedtoo
145 H subsub/added
148 cat >.git/info/sparse-checkout <<\EOF &&
150 !sub
151 sub/added
153 git read-tree -m -u HEAD &&
154 git ls-files -t >result &&
155 test_cmp expected.swt-negation2 result &&
156 test_path_is_file init.t &&
157 test_path_is_file sub/added &&
158 test_path_is_missing sub/addedtoo
161 test_expect_success 'match directory pattern' '
162 echo "s?b" >.git/info/sparse-checkout &&
163 read_tree_u_must_succeed -m -u HEAD &&
164 git ls-files -t >result &&
165 test_cmp expected.swt-noinit result &&
166 test_path_is_missing init.t &&
167 test_path_is_file sub/added
170 test_expect_success 'checkout area changes' '
171 cat >expected.swt-nosub <<-\EOF &&
172 H init.t
173 S sub/added
174 S sub/addedtoo
175 S subsub/added
178 echo init.t >.git/info/sparse-checkout &&
179 read_tree_u_must_succeed -m -u HEAD &&
180 git ls-files -t >result &&
181 test_cmp expected.swt-nosub result &&
182 test_path_is_file init.t &&
183 test_path_is_missing sub/added
186 test_expect_success 'read-tree updates worktree, absent case' '
187 echo sub/added >.git/info/sparse-checkout &&
188 git checkout -f top &&
189 read_tree_u_must_succeed -m -u HEAD^ &&
190 test_path_is_missing init.t
193 test_expect_success 'read-tree will not throw away dirty changes, non-sparse' '
194 echo "/*" >.git/info/sparse-checkout &&
195 read_tree_u_must_succeed -m -u HEAD &&
197 echo dirty >init.t &&
198 read_tree_u_must_fail -m -u HEAD^ &&
199 test_path_is_file init.t &&
200 grep -q dirty init.t
203 test_expect_success 'read-tree will not throw away dirty changes, sparse' '
204 echo "/*" >.git/info/sparse-checkout &&
205 read_tree_u_must_succeed -m -u HEAD &&
207 echo dirty >init.t &&
208 echo sub/added >.git/info/sparse-checkout &&
209 read_tree_u_must_fail -m -u HEAD^ &&
210 test_path_is_file init.t &&
211 grep -q dirty init.t
214 test_expect_success 'read-tree updates worktree, dirty case' '
215 echo sub/added >.git/info/sparse-checkout &&
216 git checkout -f top &&
217 echo dirty >init.t &&
218 read_tree_u_must_fail -m -u HEAD^ &&
219 grep -q dirty init.t &&
220 rm init.t
223 test_expect_success 'read-tree removes worktree, dirty case' '
224 echo init.t >.git/info/sparse-checkout &&
225 git checkout -f top &&
226 echo dirty >added &&
227 read_tree_u_must_succeed -m -u HEAD^ &&
228 grep -q dirty added
231 test_expect_success 'read-tree adds to worktree, absent case' '
232 echo init.t >.git/info/sparse-checkout &&
233 git checkout -f removed &&
234 read_tree_u_must_succeed -u -m HEAD^ &&
235 test_path_is_missing sub/added
238 test_expect_success 'read-tree adds to worktree, dirty case' '
239 echo init.t >.git/info/sparse-checkout &&
240 git checkout -f removed &&
241 mkdir sub &&
242 echo dirty >sub/added &&
243 read_tree_u_must_succeed -u -m HEAD^ &&
244 grep -q dirty sub/added
247 test_expect_success 'index removal and worktree narrowing at the same time' '
248 echo init.t >.git/info/sparse-checkout &&
249 echo sub/added >>.git/info/sparse-checkout &&
250 git checkout -f top &&
251 echo init.t >.git/info/sparse-checkout &&
252 git checkout removed &&
253 git ls-files sub/added >result &&
254 test_path_is_missing sub/added &&
255 test_must_be_empty result
258 test_expect_success 'read-tree --reset removes outside worktree' '
259 echo init.t >.git/info/sparse-checkout &&
260 git checkout -f top &&
261 git reset --hard removed &&
262 git ls-files sub/added >result &&
263 test_must_be_empty result
266 test_expect_success 'print warnings when some worktree updates disabled' '
267 echo sub >.git/info/sparse-checkout &&
268 git checkout -f init &&
269 mkdir sub &&
270 touch sub/added sub/addedtoo &&
271 # Use -q to suppress "Previous HEAD position" and "Head is now at" msgs
272 git checkout -q top 2>actual &&
273 cat >expected <<\EOF &&
274 warning: The following paths were already present and thus not updated despite sparse patterns:
275 sub/added
276 sub/addedtoo
278 After fixing the above paths, you may want to run `git sparse-checkout reapply`.
280 test_cmp expected actual
283 test_expect_success 'checkout without --ignore-skip-worktree-bits' '
284 echo "*" >.git/info/sparse-checkout &&
285 git checkout -f top &&
286 test_path_is_file init.t &&
287 echo sub >.git/info/sparse-checkout &&
288 git checkout &&
289 echo modified >> sub/added &&
290 git checkout . &&
291 test_path_is_missing init.t &&
292 git diff --exit-code HEAD
295 test_expect_success 'checkout with --ignore-skip-worktree-bits' '
296 echo "*" >.git/info/sparse-checkout &&
297 git checkout -f top &&
298 test_path_is_file init.t &&
299 echo sub >.git/info/sparse-checkout &&
300 git checkout &&
301 echo modified >> sub/added &&
302 git checkout --ignore-skip-worktree-bits . &&
303 test_path_is_file init.t &&
304 git diff --exit-code HEAD
307 test_done