merge: tweak --rerere-autoupdate documentation
[git/raj.git] / t / t1011-read-tree-sparse-checkout.sh
blobba71b159ba8ce1aae9c13d470bdceb7963da58da
1 #!/bin/sh
3 test_description='sparse checkout tests
5 * (tag: removed, master) 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_fail -m -u HEAD &&
78 git ls-files --stage >result &&
79 test_cmp expected result &&
80 git ls-files -t >result &&
81 test_cmp expected.swt result &&
82 test -f init.t &&
83 test -f sub/added
86 test_expect_success 'match directories with trailing slash' '
87 cat >expected.swt-noinit <<-\EOF &&
88 S init.t
89 H sub/added
90 H sub/addedtoo
91 S subsub/added
92 EOF
94 echo sub/ > .git/info/sparse-checkout &&
95 read_tree_u_must_succeed -m -u HEAD &&
96 git ls-files -t > result &&
97 test_cmp expected.swt-noinit result &&
98 test ! -f init.t &&
99 test -f sub/added
102 test_expect_success 'match directories without trailing slash' '
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 ! -f init.t &&
108 test -f sub/added
111 test_expect_success 'match directories with negated patterns' '
112 cat >expected.swt-negation <<\EOF &&
113 S init.t
114 S sub/added
115 H sub/addedtoo
116 S subsub/added
119 cat >.git/info/sparse-checkout <<\EOF &&
121 !sub/added
123 git read-tree -m -u HEAD &&
124 git ls-files -t >result &&
125 test_cmp expected.swt-negation result &&
126 test ! -f init.t &&
127 test ! -f sub/added &&
128 test -f sub/addedtoo
131 test_expect_success 'match directories with negated patterns (2)' '
132 cat >expected.swt-negation2 <<\EOF &&
133 H init.t
134 H sub/added
135 S sub/addedtoo
136 H subsub/added
139 cat >.git/info/sparse-checkout <<\EOF &&
141 !sub
142 sub/added
144 git read-tree -m -u HEAD &&
145 git ls-files -t >result &&
146 test_cmp expected.swt-negation2 result &&
147 test -f init.t &&
148 test -f sub/added &&
149 test ! -f sub/addedtoo
152 test_expect_success 'match directory pattern' '
153 echo "s?b" >.git/info/sparse-checkout &&
154 read_tree_u_must_succeed -m -u HEAD &&
155 git ls-files -t >result &&
156 test_cmp expected.swt-noinit result &&
157 test ! -f init.t &&
158 test -f sub/added
161 test_expect_success 'checkout area changes' '
162 cat >expected.swt-nosub <<-\EOF &&
163 H init.t
164 S sub/added
165 S sub/addedtoo
166 S subsub/added
169 echo init.t >.git/info/sparse-checkout &&
170 read_tree_u_must_succeed -m -u HEAD &&
171 git ls-files -t >result &&
172 test_cmp expected.swt-nosub result &&
173 test -f init.t &&
174 test ! -f sub/added
177 test_expect_success 'read-tree updates worktree, absent case' '
178 echo sub/added >.git/info/sparse-checkout &&
179 git checkout -f top &&
180 read_tree_u_must_succeed -m -u HEAD^ &&
181 test ! -f init.t
184 test_expect_success 'read-tree updates worktree, dirty case' '
185 echo sub/added >.git/info/sparse-checkout &&
186 git checkout -f top &&
187 echo dirty >init.t &&
188 read_tree_u_must_succeed -m -u HEAD^ &&
189 grep -q dirty init.t &&
190 rm init.t
193 test_expect_success 'read-tree removes worktree, dirty case' '
194 echo init.t >.git/info/sparse-checkout &&
195 git checkout -f top &&
196 echo dirty >added &&
197 read_tree_u_must_succeed -m -u HEAD^ &&
198 grep -q dirty added
201 test_expect_success 'read-tree adds to worktree, absent case' '
202 echo init.t >.git/info/sparse-checkout &&
203 git checkout -f removed &&
204 read_tree_u_must_succeed -u -m HEAD^ &&
205 test ! -f sub/added
208 test_expect_success 'read-tree adds to worktree, dirty case' '
209 echo init.t >.git/info/sparse-checkout &&
210 git checkout -f removed &&
211 mkdir sub &&
212 echo dirty >sub/added &&
213 read_tree_u_must_succeed -u -m HEAD^ &&
214 grep -q dirty sub/added
217 test_expect_success 'index removal and worktree narrowing at the same time' '
218 >empty &&
219 echo init.t >.git/info/sparse-checkout &&
220 echo sub/added >>.git/info/sparse-checkout &&
221 git checkout -f top &&
222 echo init.t >.git/info/sparse-checkout &&
223 git checkout removed &&
224 git ls-files sub/added >result &&
225 test ! -f sub/added &&
226 test_cmp empty result
229 test_expect_success 'read-tree --reset removes outside worktree' '
230 echo init.t >.git/info/sparse-checkout &&
231 git checkout -f top &&
232 git reset --hard removed &&
233 git ls-files sub/added >result &&
234 test_must_be_empty result
237 test_expect_success 'print errors when failed to update worktree' '
238 echo sub >.git/info/sparse-checkout &&
239 git checkout -f init &&
240 mkdir sub &&
241 touch sub/added sub/addedtoo &&
242 test_must_fail git checkout top 2>actual &&
243 cat >expected <<\EOF &&
244 error: The following untracked working tree files would be overwritten by checkout:
245 sub/added
246 sub/addedtoo
247 Please move or remove them before you switch branches.
248 Aborting
250 test_i18ncmp expected actual
253 test_expect_success 'checkout without --ignore-skip-worktree-bits' '
254 echo "*" >.git/info/sparse-checkout &&
255 git checkout -f top &&
256 test_path_is_file init.t &&
257 echo sub >.git/info/sparse-checkout &&
258 git checkout &&
259 echo modified >> sub/added &&
260 git checkout . &&
261 test_path_is_missing init.t &&
262 git diff --exit-code HEAD
265 test_expect_success 'checkout with --ignore-skip-worktree-bits' '
266 echo "*" >.git/info/sparse-checkout &&
267 git checkout -f top &&
268 test_path_is_file init.t &&
269 echo sub >.git/info/sparse-checkout &&
270 git checkout &&
271 echo modified >> sub/added &&
272 git checkout --ignore-skip-worktree-bits . &&
273 test_path_is_file init.t &&
274 git diff --exit-code HEAD
277 test_done