mv: check if out-of-cone file exists in index with SKIP_WORKTREE bit
[alt-git.git] / t / t7002-mv-sparse-checkout.sh
blob1510b5ed6a79040920f59fe6a72c4f16a1b71eff
1 #!/bin/sh
3 test_description='git mv in sparse working trees'
5 . ./test-lib.sh
7 setup_sparse_checkout () {
8 mkdir folder1 &&
9 touch folder1/file1 &&
10 git add folder1 &&
11 git sparse-checkout set --cone sub
14 cleanup_sparse_checkout () {
15 git sparse-checkout disable &&
16 git reset --hard
19 test_expect_success 'setup' "
20 mkdir -p sub/dir sub/dir2 &&
21 touch a b c sub/d sub/dir/e sub/dir2/e &&
22 git add -A &&
23 git commit -m files &&
25 cat >sparse_error_header <<-EOF &&
26 The following paths and/or pathspecs matched paths that exist
27 outside of your sparse-checkout definition, so will not be
28 updated in the index:
29 EOF
31 cat >sparse_hint <<-EOF
32 hint: If you intend to update such entries, try one of the following:
33 hint: * Use the --sparse option.
34 hint: * Disable or modify the sparsity rules.
35 hint: Disable this message with \"git config advice.updateSparsePath false\"
36 EOF
39 test_expect_success 'mv refuses to move sparse-to-sparse' '
40 test_when_finished rm -f e &&
41 git reset --hard &&
42 git sparse-checkout set --no-cone a &&
43 touch b &&
44 test_must_fail git mv b e 2>stderr &&
45 cat sparse_error_header >expect &&
46 echo b >>expect &&
47 echo e >>expect &&
48 cat sparse_hint >>expect &&
49 test_cmp expect stderr &&
50 git mv --sparse b e 2>stderr &&
51 test_must_be_empty stderr
54 test_expect_success 'mv refuses to move sparse-to-sparse, ignores failure' '
55 test_when_finished rm -f b c e &&
56 git reset --hard &&
57 git sparse-checkout set a &&
59 # tracked-to-untracked
60 touch b &&
61 git mv -k b e 2>stderr &&
62 test_path_exists b &&
63 test_path_is_missing e &&
64 cat sparse_error_header >expect &&
65 echo b >>expect &&
66 echo e >>expect &&
67 cat sparse_hint >>expect &&
68 test_cmp expect stderr &&
70 git mv --sparse b e 2>stderr &&
71 test_must_be_empty stderr &&
72 test_path_is_missing b &&
73 test_path_exists e &&
75 # tracked-to-tracked
76 git reset --hard &&
77 touch b &&
78 git mv -k b c 2>stderr &&
79 test_path_exists b &&
80 test_path_is_missing c &&
81 cat sparse_error_header >expect &&
82 echo b >>expect &&
83 echo c >>expect &&
84 cat sparse_hint >>expect &&
85 test_cmp expect stderr &&
87 git mv --sparse b c 2>stderr &&
88 test_must_be_empty stderr &&
89 test_path_is_missing b &&
90 test_path_exists c
93 test_expect_success 'mv refuses to move non-sparse-to-sparse' '
94 test_when_finished rm -f b c e &&
95 git reset --hard &&
96 git sparse-checkout set a &&
98 # tracked-to-untracked
99 test_must_fail git mv a e 2>stderr &&
100 test_path_exists a &&
101 test_path_is_missing e &&
102 cat sparse_error_header >expect &&
103 echo e >>expect &&
104 cat sparse_hint >>expect &&
105 test_cmp expect stderr &&
106 git mv --sparse a e 2>stderr &&
107 test_must_be_empty stderr &&
108 test_path_is_missing a &&
109 test_path_exists e &&
111 # tracked-to-tracked
112 rm e &&
113 git reset --hard &&
114 test_must_fail git mv a c 2>stderr &&
115 test_path_exists a &&
116 test_path_is_missing c &&
117 cat sparse_error_header >expect &&
118 echo c >>expect &&
119 cat sparse_hint >>expect &&
120 test_cmp expect stderr &&
121 git mv --sparse a c 2>stderr &&
122 test_must_be_empty stderr &&
123 test_path_is_missing a &&
124 test_path_exists c
127 test_expect_success 'mv refuses to move sparse-to-non-sparse' '
128 test_when_finished rm -f b c e &&
129 git reset --hard &&
130 git sparse-checkout set a e &&
132 # tracked-to-untracked
133 touch b &&
134 test_must_fail git mv b e 2>stderr &&
135 cat sparse_error_header >expect &&
136 echo b >>expect &&
137 cat sparse_hint >>expect &&
138 test_cmp expect stderr &&
139 git mv --sparse b e 2>stderr &&
140 test_must_be_empty stderr
143 test_expect_success 'recursive mv refuses to move (possible) sparse' '
144 test_when_finished rm -rf b c e sub2 &&
145 git reset --hard &&
146 # Without cone mode, "sub" and "sub2" do not match
147 git sparse-checkout set sub/dir sub2/dir &&
149 # Add contained contents to ensure we avoid non-existence errors
150 mkdir sub/dir2 &&
151 touch sub/d sub/dir2/e &&
153 test_must_fail git mv sub sub2 2>stderr &&
154 cat sparse_error_header >expect &&
155 cat >>expect <<-\EOF &&
156 sub/d
157 sub2/d
158 sub/dir2/e
159 sub2/dir2/e
161 cat sparse_hint >>expect &&
162 test_cmp expect stderr &&
163 git mv --sparse sub sub2 2>stderr &&
164 test_must_be_empty stderr &&
165 git commit -m "moved sub to sub2" &&
166 git rev-parse HEAD~1:sub >expect &&
167 git rev-parse HEAD:sub2 >actual &&
168 test_cmp expect actual &&
169 git reset --hard HEAD~1
172 test_expect_success 'recursive mv refuses to move sparse' '
173 git reset --hard &&
174 # Use cone mode so "sub/" matches the sparse-checkout patterns
175 git sparse-checkout init --cone &&
176 git sparse-checkout set sub/dir sub2/dir &&
178 # Add contained contents to ensure we avoid non-existence errors
179 mkdir sub/dir2 &&
180 touch sub/dir2/e &&
182 test_must_fail git mv sub sub2 2>stderr &&
183 cat sparse_error_header >expect &&
184 cat >>expect <<-\EOF &&
185 sub/dir2/e
186 sub2/dir2/e
188 cat sparse_hint >>expect &&
189 test_cmp expect stderr &&
190 git mv --sparse sub sub2 2>stderr &&
191 test_must_be_empty stderr &&
192 git commit -m "moved sub to sub2" &&
193 git rev-parse HEAD~1:sub >expect &&
194 git rev-parse HEAD:sub2 >actual &&
195 test_cmp expect actual &&
196 git reset --hard HEAD~1
199 test_expect_success 'can move files to non-sparse dir' '
200 git reset --hard &&
201 git sparse-checkout init --no-cone &&
202 git sparse-checkout set a b c w !/x y/ &&
203 mkdir -p w x/y &&
205 git mv a w/new-a 2>stderr &&
206 git mv b x/y/new-b 2>stderr &&
207 test_must_be_empty stderr
210 test_expect_success 'refuse to move file to non-skip-worktree sparse path' '
211 test_when_finished "cleanup_sparse_checkout" &&
212 git reset --hard &&
213 git sparse-checkout init --no-cone &&
214 git sparse-checkout set a !/x y/ !x/y/z &&
215 mkdir -p x/y/z &&
217 test_must_fail git mv a x/y/z/new-a 2>stderr &&
218 echo x/y/z/new-a | cat sparse_error_header - sparse_hint >expect &&
219 test_cmp expect stderr
222 test_expect_failure 'refuse to move out-of-cone directory without --sparse' '
223 test_when_finished "cleanup_sparse_checkout" &&
224 setup_sparse_checkout &&
226 test_must_fail git mv folder1 sub 2>stderr &&
227 cat sparse_error_header >expect &&
228 echo folder1/file1 >>expect &&
229 cat sparse_hint >>expect &&
230 test_cmp expect stderr
233 test_expect_failure 'can move out-of-cone directory with --sparse' '
234 test_when_finished "cleanup_sparse_checkout" &&
235 setup_sparse_checkout &&
237 git mv --sparse folder1 sub 2>stderr &&
238 test_must_be_empty stderr &&
240 test_path_is_dir sub/folder1 &&
241 test_path_is_file sub/folder1/file1
244 test_expect_success 'refuse to move out-of-cone file without --sparse' '
245 test_when_finished "cleanup_sparse_checkout" &&
246 setup_sparse_checkout &&
248 test_must_fail git mv folder1/file1 sub 2>stderr &&
249 cat sparse_error_header >expect &&
250 echo folder1/file1 >>expect &&
251 cat sparse_hint >>expect &&
252 test_cmp expect stderr
255 test_expect_success 'can move out-of-cone file with --sparse' '
256 test_when_finished "cleanup_sparse_checkout" &&
257 setup_sparse_checkout &&
259 git mv --sparse folder1/file1 sub 2>stderr &&
260 test_must_be_empty stderr &&
262 test_path_is_file sub/file1
265 test_expect_failure 'refuse to move sparse file to existing destination' '
266 test_when_finished "cleanup_sparse_checkout" &&
267 mkdir folder1 &&
268 touch folder1/file1 &&
269 touch sub/file1 &&
270 git add folder1 sub/file1 &&
271 git sparse-checkout set --cone sub &&
273 test_must_fail git mv --sparse folder1/file1 sub 2>stderr &&
274 echo "fatal: destination exists, source=folder1/file1, destination=sub/file1" >expect &&
275 test_cmp expect stderr
278 test_expect_failure 'move sparse file to existing destination with --force and --sparse' '
279 test_when_finished "cleanup_sparse_checkout" &&
280 mkdir folder1 &&
281 touch folder1/file1 &&
282 touch sub/file1 &&
283 echo "overwrite" >folder1/file1 &&
284 git add folder1 sub/file1 &&
285 git sparse-checkout set --cone sub &&
287 git mv --sparse --force folder1/file1 sub 2>stderr &&
288 test_must_be_empty stderr &&
289 echo "overwrite" >expect &&
290 test_cmp expect sub/file1
293 test_done