t7002: add tests for moving out-of-cone file/directory
Add corresponding tests to test following situations: We do not have sufficient coverage of moving files outside of a sparse-checkout cone. Create new tests covering this behavior, keeping in mind that the user can include --sparse (or not), move a file or directory, and the destination can already exist in the index (in this case user can use --force to overwrite existing entry). Helped-by: Victoria Dye <vdye@github.com> Helped-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> Acked-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Shaoxuan Yuan committed
Jun 30, 2022 at 10:37 UTC
367844e5b747883f4456fd17201da6e6f5320f4a
1 file changed
+84
t/t7002-mv-sparse-checkout.sh
+84
@@ -4,6 +4,18 @@ test_description='git mv in sparse working trees'
4
5
. ./test-lib.sh
6
7
+setup_sparse_checkout () {
8
+ mkdir folder1 &&
9
+ touch folder1/file1 &&
10
+ git add folder1 &&
11
+ git sparse-checkout set --cone sub
12
+}
13
+
14
+cleanup_sparse_checkout () {
15
+ git sparse-checkout disable &&
16
+ git reset --hard
17
+}
18
+
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 &&
@@ -196,6 +208,7 @@ test_expect_success 'can move files to non-sparse dir' '
208
'
209
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 &&
@@ -206,4 +219,75 @@ test_expect_success 'refuse to move file to non-skip-worktree sparse path' '
219
test_cmp expect stderr
220
'
221
222
+test_expect_failure 'refuse to move out-of-cone directory without --sparse' '
223
+ test_when_finished "cleanup_sparse_checkout" &&
224
+ setup_sparse_checkout &&
225
+
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
231
+'
232
+
233
+test_expect_failure 'can move out-of-cone directory with --sparse' '
234
+ test_when_finished "cleanup_sparse_checkout" &&
235
+ setup_sparse_checkout &&
236
+
237
+ git mv --sparse folder1 sub 2>stderr &&
238
+ test_must_be_empty stderr &&
239
+
240
+ test_path_is_dir sub/folder1 &&
241
+ test_path_is_file sub/folder1/file1
242
+'
243
+
244
+test_expect_failure 'refuse to move out-of-cone file without --sparse' '
245
+ test_when_finished "cleanup_sparse_checkout" &&
246
+ setup_sparse_checkout &&
247
+
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
253
+'
254
+
255
+test_expect_failure 'can move out-of-cone file with --sparse' '
256
+ test_when_finished "cleanup_sparse_checkout" &&
257
+ setup_sparse_checkout &&
258
+
259
+ git mv --sparse folder1/file1 sub 2>stderr &&
260
+ test_must_be_empty stderr &&
261
+
262
+ test_path_is_file sub/file1
263
+'
264
+
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 &&
272
+
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
276
+'
277
+
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 &&
286
+
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
291
+'
292
+
293
test_done