Merge 'install-wincred' into HEAD
[git/mingw/4msysgit.git] / t / t1011-read-tree-sparse-checkout.sh
blob0c74beedd22600e8dfe852393a5a9a36350cfeb5
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 cat >expected <<-\EOF &&
19 100644 77f0ba1734ed79d12881f81b36ee134de6a3327b 0 init.t
20 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 sub/added
21 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 sub/addedtoo
22 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 subsub/added
23 EOF
24 cat >expected.swt <<-\EOF &&
25 H init.t
26 H sub/added
27 H sub/addedtoo
28 H subsub/added
29 EOF
31 test_commit init &&
32 echo modified >>init.t &&
33 mkdir sub subsub &&
34 touch sub/added sub/addedtoo subsub/added &&
35 git add init.t sub/added sub/addedtoo subsub/added &&
36 git commit -m "modified and added" &&
37 git tag top &&
38 git rm sub/added &&
39 git commit -m removed &&
40 git tag removed &&
41 git checkout top &&
42 git ls-files --stage >result &&
43 test_cmp expected result
46 test_expect_success 'read-tree without .git/info/sparse-checkout' '
47 read_tree_u_must_succeed -m -u HEAD &&
48 git ls-files --stage >result &&
49 test_cmp expected result &&
50 git ls-files -t >result &&
51 test_cmp expected.swt result
54 test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
55 echo >.git/info/sparse-checkout &&
56 read_tree_u_must_succeed -m -u HEAD &&
57 git ls-files -t >result &&
58 test_cmp expected.swt result &&
59 test -f init.t &&
60 test -f sub/added
63 test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
64 git config core.sparsecheckout true &&
65 echo >.git/info/sparse-checkout &&
66 read_tree_u_must_succeed --no-sparse-checkout -m -u HEAD &&
67 git ls-files -t >result &&
68 test_cmp expected.swt result &&
69 test -f init.t &&
70 test -f sub/added
73 test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
74 git config core.sparsecheckout true &&
75 echo >.git/info/sparse-checkout &&
76 read_tree_u_must_fail -m -u HEAD &&
77 git ls-files --stage >result &&
78 test_cmp expected result &&
79 git ls-files -t >result &&
80 test_cmp expected.swt result &&
81 test -f init.t &&
82 test -f sub/added
85 test_expect_success 'match directories with trailing slash' '
86 cat >expected.swt-noinit <<-\EOF &&
87 S init.t
88 H sub/added
89 H sub/addedtoo
90 S subsub/added
91 EOF
93 echo sub/ > .git/info/sparse-checkout &&
94 read_tree_u_must_succeed -m -u HEAD &&
95 git ls-files -t > result &&
96 test_cmp expected.swt-noinit result &&
97 test ! -f init.t &&
98 test -f sub/added
101 test_expect_success 'match directories without trailing slash' '
102 echo sub >.git/info/sparse-checkout &&
103 read_tree_u_must_succeed -m -u HEAD &&
104 git ls-files -t >result &&
105 test_cmp expected.swt-noinit result &&
106 test ! -f init.t &&
107 test -f sub/added
110 test_expect_success 'match directories with negated patterns' '
111 cat >expected.swt-negation <<\EOF &&
112 S init.t
113 S sub/added
114 H sub/addedtoo
115 S subsub/added
118 cat >.git/info/sparse-checkout <<\EOF &&
120 !sub/added
122 git read-tree -m -u HEAD &&
123 git ls-files -t >result &&
124 test_cmp expected.swt-negation result &&
125 test ! -f init.t &&
126 test ! -f sub/added &&
127 test -f sub/addedtoo
130 test_expect_success 'match directories with negated patterns (2)' '
131 cat >expected.swt-negation2 <<\EOF &&
132 H init.t
133 H sub/added
134 S sub/addedtoo
135 H subsub/added
138 cat >.git/info/sparse-checkout <<\EOF &&
140 !sub
141 sub/added
143 git read-tree -m -u HEAD &&
144 git ls-files -t >result &&
145 test_cmp expected.swt-negation2 result &&
146 test -f init.t &&
147 test -f sub/added &&
148 test ! -f sub/addedtoo
151 test_expect_success 'match directory pattern' '
152 echo "s?b" >.git/info/sparse-checkout &&
153 read_tree_u_must_succeed -m -u HEAD &&
154 git ls-files -t >result &&
155 test_cmp expected.swt-noinit result &&
156 test ! -f init.t &&
157 test -f sub/added
160 test_expect_success 'checkout area changes' '
161 cat >expected.swt-nosub <<-\EOF &&
162 H init.t
163 S sub/added
164 S sub/addedtoo
165 S subsub/added
168 echo init.t >.git/info/sparse-checkout &&
169 read_tree_u_must_succeed -m -u HEAD &&
170 git ls-files -t >result &&
171 test_cmp expected.swt-nosub result &&
172 test -f init.t &&
173 test ! -f sub/added
176 test_expect_success 'read-tree updates worktree, absent case' '
177 echo sub/added >.git/info/sparse-checkout &&
178 git checkout -f top &&
179 read_tree_u_must_succeed -m -u HEAD^ &&
180 test ! -f init.t
183 test_expect_success 'read-tree updates worktree, dirty case' '
184 echo sub/added >.git/info/sparse-checkout &&
185 git checkout -f top &&
186 echo dirty >init.t &&
187 read_tree_u_must_succeed -m -u HEAD^ &&
188 grep -q dirty init.t &&
189 rm init.t
192 test_expect_success 'read-tree removes worktree, dirty case' '
193 echo init.t >.git/info/sparse-checkout &&
194 git checkout -f top &&
195 echo dirty >added &&
196 read_tree_u_must_succeed -m -u HEAD^ &&
197 grep -q dirty added
200 test_expect_success 'read-tree adds to worktree, absent case' '
201 echo init.t >.git/info/sparse-checkout &&
202 git checkout -f removed &&
203 read_tree_u_must_succeed -u -m HEAD^ &&
204 test ! -f sub/added
207 test_expect_success 'read-tree adds to worktree, dirty case' '
208 echo init.t >.git/info/sparse-checkout &&
209 git checkout -f removed &&
210 mkdir sub &&
211 echo dirty >sub/added &&
212 read_tree_u_must_succeed -u -m HEAD^ &&
213 grep -q dirty sub/added
216 test_expect_success 'index removal and worktree narrowing at the same time' '
217 >empty &&
218 echo init.t >.git/info/sparse-checkout &&
219 echo sub/added >>.git/info/sparse-checkout &&
220 git checkout -f top &&
221 echo init.t >.git/info/sparse-checkout &&
222 git checkout removed &&
223 git ls-files sub/added >result &&
224 test ! -f sub/added &&
225 test_cmp empty result
228 test_expect_success 'read-tree --reset removes outside worktree' '
229 >empty &&
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_cmp 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 can switch branches.
248 Aborting
250 test_cmp 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