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' '
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
24 cat >expected.swt <<-\EOF &&
32 echo modified >>init.t &&
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" &&
39 git commit -m removed &&
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 &&
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 &&
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 &&
85 test_expect_success
'match directories with trailing slash' '
86 cat >expected.swt-noinit <<-\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 &&
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 &&
110 test_expect_success
'match directories with negated patterns' '
111 cat >expected.swt-negation <<\EOF &&
118 cat >.git/info/sparse-checkout <<\EOF &&
122 git read-tree -m -u HEAD &&
123 git ls-files -t >result &&
124 test_cmp expected.swt-negation result &&
126 test ! -f sub/added &&
130 test_expect_success
'match directories with negated patterns (2)' '
131 cat >expected.swt-negation2 <<\EOF &&
138 cat >.git/info/sparse-checkout <<\EOF &&
143 git read-tree -m -u HEAD &&
144 git ls-files -t >result &&
145 test_cmp expected.swt-negation2 result &&
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 &&
160 test_expect_success
'checkout area changes' '
161 cat >expected.swt-nosub <<-\EOF &&
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 &&
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^ &&
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 &&
192 test_expect_success
'read-tree removes worktree, dirty case' '
193 echo init.t >.git/info/sparse-checkout &&
194 git checkout -f top &&
196 read_tree_u_must_succeed -m -u HEAD^ &&
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^ &&
207 test_expect_success
'read-tree adds to worktree, dirty case' '
208 echo init.t >.git/info/sparse-checkout &&
209 git checkout -f removed &&
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' '
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' '
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