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_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 &&
87 test_cmp expected.swt result &&
92 test_expect_success 'match directories with trailing slash' '
93 cat >expected.swt-noinit <<-\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 &&
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 &&
117 test_expect_success 'match directories with negated patterns' '
118 cat >expected.swt-negation <<\EOF &&
125 cat >.git/info/sparse-checkout <<\EOF &&
129 git read-tree -m -u HEAD &&
130 git ls-files -t >result &&
131 test_cmp expected.swt-negation result &&
133 test ! -f sub/added &&
137 test_expect_success 'match directories with negated patterns (2)' '
138 cat >expected.swt-negation2 <<\EOF &&
145 cat >.git/info/sparse-checkout <<\EOF &&
150 git read-tree -m -u HEAD &&
151 git ls-files -t >result &&
152 test_cmp expected.swt-negation2 result &&
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 &&
167 test_expect_success 'checkout area changes' '
168 cat >expected.swt-nosub <<-\EOF &&
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 &&
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^ &&
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 &&
199 test_expect_success 'read-tree removes worktree, dirty case' '
200 echo init.t >.git/info/sparse-checkout &&
201 git checkout -f top &&
203 read_tree_u_must_succeed -m -u HEAD^ &&
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^ &&
214 test_expect_success 'read-tree adds to worktree, dirty case' '
215 echo init.t >.git/info/sparse-checkout &&
216 git checkout -f removed &&
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 &&
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:
254 After fixing the above paths, you may want to run `git sparse-checkout reapply`.
256 test_i18ncmp 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 &&
265 echo modified >> sub/added &&
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 &&
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