git-completion: fix regression in zsh support
[git.git] / t / t1011-read-tree-sparse-checkout.sh
blobde84e35c4357c7329b3fae749228df28f31a9d3f
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 subsub/added
21 EOF
22 cat >expected.swt <<-\EOF &&
23 H init.t
24 H sub/added
25 H subsub/added
26 EOF
28 test_commit init &&
29 echo modified >>init.t &&
30 mkdir sub subsub &&
31 touch sub/added subsub/added &&
32 git add init.t sub/added subsub/added &&
33 git commit -m "modified and added" &&
34 git tag top &&
35 git rm sub/added &&
36 git commit -m removed &&
37 git tag removed &&
38 git checkout top &&
39 git ls-files --stage >result &&
40 test_cmp expected result
43 test_expect_success 'read-tree without .git/info/sparse-checkout' '
44 git read-tree -m -u HEAD &&
45 git ls-files --stage >result &&
46 test_cmp expected result &&
47 git ls-files -t >result &&
48 test_cmp expected.swt result
51 test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' '
52 echo >.git/info/sparse-checkout &&
53 git read-tree -m -u HEAD &&
54 git ls-files -t >result &&
55 test_cmp expected.swt result &&
56 test -f init.t &&
57 test -f sub/added
60 test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' '
61 git config core.sparsecheckout true &&
62 echo >.git/info/sparse-checkout &&
63 git read-tree --no-sparse-checkout -m -u HEAD &&
64 git ls-files -t >result &&
65 test_cmp expected.swt result &&
66 test -f init.t &&
67 test -f sub/added
70 test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
71 git config core.sparsecheckout true &&
72 echo >.git/info/sparse-checkout &&
73 test_must_fail git read-tree -m -u HEAD &&
74 git ls-files --stage >result &&
75 test_cmp expected result &&
76 git ls-files -t >result &&
77 test_cmp expected.swt result &&
78 test -f init.t &&
79 test -f sub/added
82 test_expect_success 'match directories with trailing slash' '
83 cat >expected.swt-noinit <<-\EOF &&
84 S init.t
85 H sub/added
86 S subsub/added
87 EOF
89 echo sub/ > .git/info/sparse-checkout &&
90 git read-tree -m -u HEAD &&
91 git ls-files -t > result &&
92 test_cmp expected.swt-noinit result &&
93 test ! -f init.t &&
94 test -f sub/added
97 test_expect_success 'match directories without trailing slash' '
98 echo sub >>.git/info/sparse-checkout &&
99 git read-tree -m -u HEAD &&
100 git ls-files -t >result &&
101 test_cmp expected.swt-noinit result &&
102 test ! -f init.t &&
103 test -f sub/added
106 test_expect_success 'match directory pattern' '
107 echo "s?b" >>.git/info/sparse-checkout &&
108 git read-tree -m -u HEAD &&
109 git ls-files -t >result &&
110 test_cmp expected.swt-noinit result &&
111 test ! -f init.t &&
112 test -f sub/added
115 test_expect_success 'checkout area changes' '
116 cat >expected.swt-nosub <<-\EOF &&
117 H init.t
118 S sub/added
119 S subsub/added
122 echo init.t >.git/info/sparse-checkout &&
123 git read-tree -m -u HEAD &&
124 git ls-files -t >result &&
125 test_cmp expected.swt-nosub result &&
126 test -f init.t &&
127 test ! -f sub/added
130 test_expect_success 'read-tree updates worktree, absent case' '
131 echo sub/added >.git/info/sparse-checkout &&
132 git checkout -f top &&
133 git read-tree -m -u HEAD^ &&
134 test ! -f init.t
137 test_expect_success 'read-tree updates worktree, dirty case' '
138 echo sub/added >.git/info/sparse-checkout &&
139 git checkout -f top &&
140 echo dirty >init.t &&
141 git read-tree -m -u HEAD^ &&
142 grep -q dirty init.t &&
143 rm init.t
146 test_expect_success 'read-tree removes worktree, dirty case' '
147 echo init.t >.git/info/sparse-checkout &&
148 git checkout -f top &&
149 echo dirty >added &&
150 git read-tree -m -u HEAD^ &&
151 grep -q dirty added
154 test_expect_success 'read-tree adds to worktree, absent case' '
155 echo init.t >.git/info/sparse-checkout &&
156 git checkout -f removed &&
157 git read-tree -u -m HEAD^ &&
158 test ! -f sub/added
161 test_expect_success 'read-tree adds to worktree, dirty case' '
162 echo init.t >.git/info/sparse-checkout &&
163 git checkout -f removed &&
164 mkdir sub &&
165 echo dirty >sub/added &&
166 git read-tree -u -m HEAD^ &&
167 grep -q dirty sub/added
170 test_expect_success 'index removal and worktree narrowing at the same time' '
171 >empty &&
172 echo init.t >.git/info/sparse-checkout &&
173 echo sub/added >>.git/info/sparse-checkout &&
174 git checkout -f top &&
175 echo init.t >.git/info/sparse-checkout &&
176 git checkout removed &&
177 git ls-files sub/added >result &&
178 test ! -f sub/added &&
179 test_cmp empty result
182 test_expect_success 'read-tree --reset removes outside worktree' '
183 >empty &&
184 echo init.t >.git/info/sparse-checkout &&
185 git checkout -f top &&
186 git reset --hard removed &&
187 git ls-files sub/added >result &&
188 test_cmp empty result
191 test_done