3 test_description
='sparse checkout tests
5 * (tag: removed, master) removed
7 * (HEAD, tag: top) modified and added
15 .
"$TEST_DIRECTORY"/lib-read-tree.sh
17 test_expect_success
'setup' '
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
27 cat >expected.swt <<-\EOF &&
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" &&
40 git commit -m removed &&
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 &&
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 &&
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 &&
86 test_expect_success
'match directories with trailing slash' '
87 cat >expected.swt-noinit <<-\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 &&
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 &&
111 test_expect_success
'match directories with negated patterns' '
112 cat >expected.swt-negation <<\EOF &&
119 cat >.git/info/sparse-checkout <<\EOF &&
123 git read-tree -m -u HEAD &&
124 git ls-files -t >result &&
125 test_cmp expected.swt-negation result &&
127 test ! -f sub/added &&
131 test_expect_success
'match directories with negated patterns (2)' '
132 cat >expected.swt-negation2 <<\EOF &&
139 cat >.git/info/sparse-checkout <<\EOF &&
144 git read-tree -m -u HEAD &&
145 git ls-files -t >result &&
146 test_cmp expected.swt-negation2 result &&
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 &&
161 test_expect_success
'checkout area changes' '
162 cat >expected.swt-nosub <<-\EOF &&
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 &&
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^ &&
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 &&
193 test_expect_success
'read-tree removes worktree, dirty case' '
194 echo init.t >.git/info/sparse-checkout &&
195 git checkout -f top &&
197 read_tree_u_must_succeed -m -u HEAD^ &&
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^ &&
208 test_expect_success
'read-tree adds to worktree, dirty case' '
209 echo init.t >.git/info/sparse-checkout &&
210 git checkout -f removed &&
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' '
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 &&
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:
247 Please move or remove them before you switch branches.
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 &&
259 echo modified >> sub/added &&
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 &&
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