format-patch: make zero-length subject prefixes prettier
[git/jnareb-git.git] / t / t1011-read-tree-sparse-checkout.sh
blob20a50eba5b77e23b6e540402b4eabb311feabd0d
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
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
22 EOF
23 cat >expected.swt <<-\EOF &&
24 H init.t
25 H sub/added
26 H sub/addedtoo
27 H subsub/added
28 EOF
30 test_commit init &&
31 echo modified >>init.t &&
32 mkdir sub subsub &&
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" &&
36 git tag top &&
37 git rm sub/added &&
38 git commit -m removed &&
39 git tag removed &&
40 git checkout top &&
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 &&
58 test -f init.t &&
59 test -f sub/added
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 &&
68 test -f init.t &&
69 test -f sub/added
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 &&
80 test -f init.t &&
81 test -f sub/added
84 test_expect_success 'match directories with trailing slash' '
85 cat >expected.swt-noinit <<-\EOF &&
86 S init.t
87 H sub/added
88 H sub/addedtoo
89 S subsub/added
90 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 &&
96 test ! -f init.t &&
97 test -f sub/added
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 &&
105 test ! -f init.t &&
106 test -f sub/added
109 test_expect_success 'match directories with negated patterns' '
110 cat >expected.swt-negation <<\EOF &&
111 S init.t
112 S sub/added
113 H sub/addedtoo
114 S subsub/added
117 cat >.git/info/sparse-checkout <<\EOF &&
119 !sub/added
121 git read-tree -m -u HEAD &&
122 git ls-files -t >result &&
123 test_cmp expected.swt-negation result &&
124 test ! -f init.t &&
125 test ! -f sub/added &&
126 test -f sub/addedtoo
129 test_expect_success 'match directories with negated patterns (2)' '
130 cat >expected.swt-negation2 <<\EOF &&
131 H init.t
132 H sub/added
133 S sub/addedtoo
134 H subsub/added
137 cat >.git/info/sparse-checkout <<\EOF &&
139 !sub
140 sub/added
142 git read-tree -m -u HEAD &&
143 git ls-files -t >result &&
144 test_cmp expected.swt-negation2 result &&
145 test -f init.t &&
146 test -f sub/added &&
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 &&
155 test ! -f init.t &&
156 test -f sub/added
159 test_expect_success 'checkout area changes' '
160 cat >expected.swt-nosub <<-\EOF &&
161 H init.t
162 S sub/added
163 S sub/addedtoo
164 S subsub/added
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 &&
171 test -f init.t &&
172 test ! -f sub/added
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^ &&
179 test ! -f init.t
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 &&
188 rm 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 &&
194 echo dirty >added &&
195 git read-tree -m -u HEAD^ &&
196 grep -q dirty added
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^ &&
203 test ! -f sub/added
206 test_expect_success 'read-tree adds to worktree, dirty case' '
207 echo init.t >.git/info/sparse-checkout &&
208 git checkout -f removed &&
209 mkdir sub &&
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' '
216 >empty &&
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' '
228 >empty &&
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
236 test_done