3 test_description
='git mv in sparse working trees'
7 setup_sparse_checkout
() {
11 git sparse-checkout
set --cone sub
14 cleanup_sparse_checkout
() {
15 git sparse-checkout disable
&&
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 &&
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
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\"
39 test_expect_success
'mv refuses to move sparse-to-sparse' '
40 test_when_finished rm -f e &&
42 git sparse-checkout set --no-cone a &&
44 test_must_fail git mv b e 2>stderr &&
45 cat sparse_error_header >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 &&
57 git sparse-checkout set a &&
59 # tracked-to-untracked
61 git mv -k b e 2>stderr &&
63 test_path_is_missing e &&
64 cat sparse_error_header >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 &&
78 git mv -k b c 2>stderr &&
80 test_path_is_missing c &&
81 cat sparse_error_header >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 &&
93 test_expect_success
'mv refuses to move non-sparse-to-sparse' '
94 test_when_finished rm -f b c e &&
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 &&
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 &&
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 &&
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 &&
127 test_expect_success
'mv refuses to move sparse-to-non-sparse' '
128 test_when_finished rm -f b c e &&
130 git sparse-checkout set a e &&
132 # tracked-to-untracked
134 test_must_fail git mv b e 2>stderr &&
135 cat sparse_error_header >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 &&
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
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 &&
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' '
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
182 test_must_fail git mv sub sub2 2>stderr &&
183 cat sparse_error_header >expect &&
184 cat >>expect <<-\EOF &&
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' '
201 git sparse-checkout init --no-cone &&
202 git sparse-checkout set a b c 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" &&
213 git sparse-checkout init --no-cone &&
214 git sparse-checkout set a !/x y/ !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_success
'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_success
'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_success
'refuse to move sparse file to existing destination' '
266 test_when_finished "cleanup_sparse_checkout" &&
268 touch folder1/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_success
'move sparse file to existing destination with --force and --sparse' '
279 test_when_finished "cleanup_sparse_checkout" &&
281 touch folder1/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