tree-wide: apply equals-null.cocci
[alt-git.git] / t / t1011-read-tree-sparse-checkout.sh
blob24092c09a95771df742337e8d6c1c9eac77221ba
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 updates worktree, dirty case' '
191 echo sub/added >.git/info/sparse-checkout &&
192 git checkout -f top &&
193 echo dirty >init.t &&
194 read_tree_u_must_succeed -m -u HEAD^ &&
195 grep -q dirty init.t &&
196 rm init.t
199 test_expect_success 'read-tree removes worktree, dirty case' '
200 echo init.t >.git/info/sparse-checkout &&
201 git checkout -f top &&
202 echo dirty >added &&
203 read_tree_u_must_succeed -m -u HEAD^ &&
204 grep -q dirty added
207 test_expect_success 'read-tree adds to worktree, absent case' '
208 echo init.t >.git/info/sparse-checkout &&
209 git checkout -f removed &&
210 read_tree_u_must_succeed -u -m HEAD^ &&
211 test ! -f sub/added
214 test_expect_success 'read-tree adds to worktree, dirty case' '
215 echo init.t >.git/info/sparse-checkout &&
216 git checkout -f removed &&
217 mkdir sub &&
218 echo dirty >sub/added &&
219 read_tree_u_must_succeed -u -m HEAD^ &&
220 grep -q dirty sub/added
223 test_expect_success 'index removal and worktree narrowing at the same time' '
224 echo init.t >.git/info/sparse-checkout &&
225 echo sub/added >>.git/info/sparse-checkout &&
226 git checkout -f top &&
227 echo init.t >.git/info/sparse-checkout &&
228 git checkout removed &&
229 git ls-files sub/added >result &&
230 test ! -f sub/added &&
231 test_must_be_empty result
234 test_expect_success 'read-tree --reset removes outside worktree' '
235 echo init.t >.git/info/sparse-checkout &&
236 git checkout -f top &&
237 git reset --hard removed &&
238 git ls-files sub/added >result &&
239 test_must_be_empty result
242 test_expect_success 'print warnings when some worktree updates disabled' '
243 echo sub >.git/info/sparse-checkout &&
244 git checkout -f init &&
245 mkdir sub &&
246 touch sub/added sub/addedtoo &&
247 # Use -q to suppress "Previous HEAD position" and "Head is now at" msgs
248 git checkout -q top 2>actual &&
249 cat >expected <<\EOF &&
250 warning: The following paths were already present and thus not updated despite sparse patterns:
251 sub/added
252 sub/addedtoo
254 After fixing the above paths, you may want to run `git sparse-checkout reapply`.
256 test_cmp expected actual
259 test_expect_success 'checkout without --ignore-skip-worktree-bits' '
260 echo "*" >.git/info/sparse-checkout &&
261 git checkout -f top &&
262 test_path_is_file init.t &&
263 echo sub >.git/info/sparse-checkout &&
264 git checkout &&
265 echo modified >> sub/added &&
266 git checkout . &&
267 test_path_is_missing init.t &&
268 git diff --exit-code HEAD
271 test_expect_success 'checkout with --ignore-skip-worktree-bits' '
272 echo "*" >.git/info/sparse-checkout &&
273 git checkout -f top &&
274 test_path_is_file init.t &&
275 echo sub >.git/info/sparse-checkout &&
276 git checkout &&
277 echo modified >> sub/added &&
278 git checkout --ignore-skip-worktree-bits . &&
279 test_path_is_file init.t &&
280 git diff --exit-code HEAD
283 test_done