3 test_description
='sparse checkout tests
5 * (tag: removed, master) removed
7 * (HEAD, tag: top) modified and added
16 test_expect_success
'setup' '
17 cat >expected <<-\EOF &&
18 100644 77f0ba1734ed79d12881f81b36ee134de6a3327b 0 init.t
19 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 sub/added
20 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 sub/addedtoo
21 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 subsub/added
23 cat >expected.swt <<-\EOF &&
31 echo modified >>init.t &&
33 touch sub/added sub/addedtoo subsub/added &&
34 git add init.t sub/added sub/addedtoo subsub/added &&
35 git commit -m "modified and added" &&
38 git commit -m removed &&
41 git ls-files --stage >result &&
42 test_cmp expected result
45 test_expect_success
'read-tree without .git/info/sparse-checkout' '
46 git read-tree -m -u HEAD &&
47 git ls-files --stage >result &&
48 test_cmp expected result &&
49 git ls-files -t >result &&
50 test_cmp expected.swt result
53 test_expect_success
'read-tree with .git/info/sparse-checkout but disabled' '
54 echo >.git/info/sparse-checkout &&
55 git read-tree -m -u HEAD &&
56 git ls-files -t >result &&
57 test_cmp expected.swt result &&
62 test_expect_success
'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
63 git config core.sparsecheckout true &&
64 echo >.git/info/sparse-checkout &&
65 git read-tree --no-sparse-checkout -m -u HEAD &&
66 git ls-files -t >result &&
67 test_cmp expected.swt result &&
72 test_expect_success
'read-tree with empty .git/info/sparse-checkout' '
73 git config core.sparsecheckout true &&
74 echo >.git/info/sparse-checkout &&
75 test_must_fail git read-tree -m -u HEAD &&
76 git ls-files --stage >result &&
77 test_cmp expected result &&
78 git ls-files -t >result &&
79 test_cmp expected.swt result &&
84 test_expect_success
'match directories with trailing slash' '
85 cat >expected.swt-noinit <<-\EOF &&
92 echo sub/ > .git/info/sparse-checkout &&
93 git read-tree -m -u HEAD &&
94 git ls-files -t > result &&
95 test_cmp expected.swt-noinit result &&
100 test_expect_success
'match directories without trailing slash' '
101 echo sub >.git/info/sparse-checkout &&
102 git read-tree -m -u HEAD &&
103 git ls-files -t >result &&
104 test_cmp expected.swt-noinit result &&
109 test_expect_success
'match directories with negated patterns' '
110 cat >expected.swt-negation <<\EOF &&
117 cat >.git/info/sparse-checkout <<\EOF &&
121 git read-tree -m -u HEAD &&
122 git ls-files -t >result &&
123 test_cmp expected.swt-negation result &&
125 test ! -f sub/added &&
129 test_expect_success
'match directories with negated patterns (2)' '
130 cat >expected.swt-negation2 <<\EOF &&
137 cat >.git/info/sparse-checkout <<\EOF &&
142 git read-tree -m -u HEAD &&
143 git ls-files -t >result &&
144 test_cmp expected.swt-negation2 result &&
147 test ! -f sub/addedtoo
150 test_expect_success
'match directory pattern' '
151 echo "s?b" >.git/info/sparse-checkout &&
152 git read-tree -m -u HEAD &&
153 git ls-files -t >result &&
154 test_cmp expected.swt-noinit result &&
159 test_expect_success
'checkout area changes' '
160 cat >expected.swt-nosub <<-\EOF &&
167 echo init.t >.git/info/sparse-checkout &&
168 git read-tree -m -u HEAD &&
169 git ls-files -t >result &&
170 test_cmp expected.swt-nosub result &&
175 test_expect_success
'read-tree updates worktree, absent case' '
176 echo sub/added >.git/info/sparse-checkout &&
177 git checkout -f top &&
178 git read-tree -m -u HEAD^ &&
182 test_expect_success
'read-tree updates worktree, dirty case' '
183 echo sub/added >.git/info/sparse-checkout &&
184 git checkout -f top &&
185 echo dirty >init.t &&
186 git read-tree -m -u HEAD^ &&
187 grep -q dirty init.t &&
191 test_expect_success
'read-tree removes worktree, dirty case' '
192 echo init.t >.git/info/sparse-checkout &&
193 git checkout -f top &&
195 git read-tree -m -u HEAD^ &&
199 test_expect_success
'read-tree adds to worktree, absent case' '
200 echo init.t >.git/info/sparse-checkout &&
201 git checkout -f removed &&
202 git read-tree -u -m HEAD^ &&
206 test_expect_success
'read-tree adds to worktree, dirty case' '
207 echo init.t >.git/info/sparse-checkout &&
208 git checkout -f removed &&
210 echo dirty >sub/added &&
211 git read-tree -u -m HEAD^ &&
212 grep -q dirty sub/added
215 test_expect_success
'index removal and worktree narrowing at the same time' '
217 echo init.t >.git/info/sparse-checkout &&
218 echo sub/added >>.git/info/sparse-checkout &&
219 git checkout -f top &&
220 echo init.t >.git/info/sparse-checkout &&
221 git checkout removed &&
222 git ls-files sub/added >result &&
223 test ! -f sub/added &&
224 test_cmp empty result
227 test_expect_success
'read-tree --reset removes outside worktree' '
229 echo init.t >.git/info/sparse-checkout &&
230 git checkout -f top &&
231 git reset --hard removed &&
232 git ls-files sub/added >result &&
233 test_cmp empty result