@@ -415,7 +415,7 @@ test_expect_success 'checkout and reset --hard' '
415
415
test_all_match git reset --hard update-folder2
416
416
'
417
417
418
- test_expect_success ' diff --staged ' '
418
+ test_expect_success ' diff --cached ' '
419
419
init_repos &&
420
420
421
421
write_script edit-contents <<-\EOF &&
@@ -424,10 +424,10 @@ test_expect_success 'diff --staged' '
424
424
run_on_all ../edit-contents &&
425
425
426
426
test_all_match git diff &&
427
- test_all_match git diff --staged &&
427
+ test_all_match git diff --cached &&
428
428
test_all_match git add README.md &&
429
429
test_all_match git diff &&
430
- test_all_match git diff --staged
430
+ test_all_match git diff --cached
431
431
'
432
432
433
433
# NEEDSWORK: sparse-checkout behaves differently from full-checkout when
@@ -444,8 +444,8 @@ test_expect_success 'diff with renames and conflicts' '
444
444
test_all_match git checkout rename-base &&
445
445
test_all_match git checkout $branch -- . &&
446
446
test_all_match git status --porcelain=v2 &&
447
- test_all_match git diff --staged --no-renames &&
448
- test_all_match git diff --staged --find-renames || return 1
447
+ test_all_match git diff --cached --no-renames &&
448
+ test_all_match git diff --cached --find-renames || return 1
449
449
done
450
450
'
451
451
@@ -464,8 +464,8 @@ test_expect_success 'diff with directory/file conflicts' '
464
464
test_all_match git checkout $branch &&
465
465
test_all_match git checkout rename-base -- . &&
466
466
test_all_match git status --porcelain=v2 &&
467
- test_all_match git diff --staged --no-renames &&
468
- test_all_match git diff --staged --find-renames || return 1
467
+ test_all_match git diff --cached --no-renames &&
468
+ test_all_match git diff --cached --find-renames || return 1
469
469
done
470
470
'
471
471
@@ -486,21 +486,36 @@ test_expect_success 'log with pathspec outside sparse definition' '
486
486
test_expect_success ' blame with pathspec inside sparse definition' '
487
487
init_repos &&
488
488
489
- test_all_match git blame a &&
490
- test_all_match git blame deep/a &&
491
- test_all_match git blame deep/deeper1/a &&
492
- test_all_match git blame deep/deeper1/deepest/a
489
+ for file in a \
490
+ deep/a \
491
+ deep/deeper1/a \
492
+ deep/deeper1/deepest/a
493
+ do
494
+ test_all_match git blame $file
495
+ done
493
496
'
494
497
495
- # TODO: blame currently does not support blaming files outside of the
496
- # sparse definition. It complains that the file doesn't exist locally.
497
- test_expect_failure ' blame with pathspec outside sparse definition' '
498
+ # Without a revision specified, blame will error if passed any file that
499
+ # is not present in the working directory (even if the file is tracked).
500
+ # Here we just verify that this is also true with sparse checkouts.
501
+ test_expect_success ' blame with pathspec outside sparse definition' '
498
502
init_repos &&
503
+ test_sparse_match git sparse-checkout set &&
499
504
500
- test_all_match git blame folder1/a &&
501
- test_all_match git blame folder2/a &&
502
- test_all_match git blame deep/deeper2/a &&
503
- test_all_match git blame deep/deeper2/deepest/a
505
+ for file in a \
506
+ deep/a \
507
+ deep/deeper1/a \
508
+ deep/deeper1/deepest/a
509
+ do
510
+ test_sparse_match test_must_fail git blame $file &&
511
+ cat >expect <<-EOF &&
512
+ fatal: Cannot lstat ' " '" ' $file' " '" ' : No such file or directory
513
+ EOF
514
+ # We compare sparse-checkout-err and sparse-index-err in
515
+ # `test_sparse_match`. Given we know they are the same, we
516
+ # only check the content of sparse-index-err here.
517
+ test_cmp expect sparse-index-err
518
+ done
504
519
'
505
520
506
521
test_expect_success ' checkout and reset (mixed)' '
@@ -936,6 +951,64 @@ test_expect_success 'sparse-index is not expanded: merge conflict in cone' '
936
951
)
937
952
'
938
953
954
+ test_expect_success ' sparse index is not expanded: diff' '
955
+ init_repos &&
956
+
957
+ write_script edit-contents <<-\EOF &&
958
+ echo text >>$1
959
+ EOF
960
+
961
+ # Add file within cone
962
+ test_sparse_match git sparse-checkout set deep &&
963
+ run_on_all ../edit-contents deep/testfile &&
964
+ test_all_match git add deep/testfile &&
965
+ run_on_all ../edit-contents deep/testfile &&
966
+
967
+ test_all_match git diff &&
968
+ test_all_match git diff --cached &&
969
+ ensure_not_expanded diff &&
970
+ ensure_not_expanded diff --cached &&
971
+
972
+ # Add file outside cone
973
+ test_all_match git reset --hard &&
974
+ run_on_all mkdir newdirectory &&
975
+ run_on_all ../edit-contents newdirectory/testfile &&
976
+ test_sparse_match git sparse-checkout set newdirectory &&
977
+ test_all_match git add newdirectory/testfile &&
978
+ run_on_all ../edit-contents newdirectory/testfile &&
979
+ test_sparse_match git sparse-checkout set &&
980
+
981
+ test_all_match git diff &&
982
+ test_all_match git diff --cached &&
983
+ ensure_not_expanded diff &&
984
+ ensure_not_expanded diff --cached &&
985
+
986
+ # Merge conflict outside cone
987
+ # The sparse checkout will report a warning that is not in the
988
+ # full checkout, so we use `run_on_all` instead of
989
+ # `test_all_match`
990
+ run_on_all git reset --hard &&
991
+ test_all_match git checkout merge-left &&
992
+ test_all_match test_must_fail git merge merge-right &&
993
+
994
+ test_all_match git diff &&
995
+ test_all_match git diff --cached &&
996
+ ensure_not_expanded diff &&
997
+ ensure_not_expanded diff --cached
998
+ '
999
+
1000
+ test_expect_success ' sparse index is not expanded: blame' '
1001
+ init_repos &&
1002
+
1003
+ for file in a \
1004
+ deep/a \
1005
+ deep/deeper1/a \
1006
+ deep/deeper1/deepest/a
1007
+ do
1008
+ ensure_not_expanded blame $file
1009
+ done
1010
+ '
1011
+
939
1012
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
940
1013
# in this scenario, but it shouldn't.
941
1014
test_expect_success ' reset mixed and checkout orphan' '
0 commit comments