1340
grep "160000 $(git -C initial-repo rev-parse HEAD) 0 modules/sub" cache
1341
'
1342
1343
+test_expect_success 'git apply functionality' '
1344
+ init_repos &&
1345
+
1346
+ test_all_match git checkout base &&
1347
+
1348
+ git -C full-checkout diff base..merge-right -- deep >patch-in-sparse &&
1349
+ git -C full-checkout diff base..merge-right -- folder2 >patch-outside &&
1350
+
1351
+ # Apply a patch to a file inside the sparse definition
1352
+ test_all_match git apply --index --stat ../patch-in-sparse &&
1353
+ test_all_match git status --porcelain=v2 &&
1354
+
1355
+ # Apply a patch to a file outside the sparse definition
1356
+ test_sparse_match test_must_fail git apply ../patch-outside &&
1357
+ grep "No such file or directory" sparse-checkout-err &&
1358
+
1359
+ # But it works with --index and --cached
1360
+ test_all_match git apply --index --stat ../patch-outside &&
1361
+ test_all_match git status --porcelain=v2 &&
1362
+ test_all_match git reset --hard &&
1363
+ test_all_match git apply --cached --stat ../patch-outside &&
1364
+ test_all_match git status --porcelain=v2
1365
+'
1366
+
1367
# When working with a sparse index, some commands will need to expand the
1368
# index to operate properly. If those commands also write the index back
1369
# to disk, they need to convert the index to sparse before writing.
2371
ensure_not_expanded check-attr -a --cached -- folder1/a
2372
'
2373
2374
+test_expect_success 'sparse-index is not expanded: git apply' '
2375
+ init_repos &&
2376
+
2377
+ git -C sparse-index checkout base &&
2378
+ git -C full-checkout diff base..merge-right -- deep >patch-in-sparse &&
2379
+ git -C full-checkout diff base..merge-right -- folder2 >patch-outside &&
2380
+
2381
+ # Apply a patch to a file inside the sparse definition
2382
+ ensure_not_expanded apply --index --stat ../patch-in-sparse &&
2383
+
2384
+ # Apply a patch to a file outside the sparse definition
2385
+ # Fails when caring about the worktree.
2386
+ ensure_not_expanded ! apply ../patch-outside &&
2387
+
2388
+ # Expands when using --index.
2389
+ ensure_expanded apply --index ../patch-outside &&
2390
+
2391
+ # Does not when index is partially expanded.
2392
+ git -C sparse-index reset --hard &&
2393
+ ensure_not_expanded apply --cached ../patch-outside &&
2394
+
2395
+ # Try again with a reset and collapsed index.
2396
+ git -C sparse-index reset --hard &&
2397
+ git -C sparse-index sparse-checkout reapply &&
2398
+
2399
+ # Expands when index is collapsed.
2400
+ ensure_expanded apply --cached ../patch-outside
2401
+'
2402
+
2403
test_expect_success 'advice.sparseIndexExpanded' '
2404
init_repos &&
2405