1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
|
#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
begin_test "checkout"
(
set -e
reponame="$(basename "$0" ".sh")"
setup_remote_repo "$reponame"
clone_repo "$reponame" repo
rm -f clone.log
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
rm -f track.log
contents="something something"
contentsize=19
contents_oid=$(calc_oid "$contents")
# Same content everywhere is ok, just one object in lfs db
printf "%s" "$contents" > file1.dat
printf "%s" "$contents" > file2.dat
printf "%s" "$contents" > file3.dat
mkdir -p folder1 folder2/folder3/folder4
printf "%s" "$contents" > folder1/nested.dat
printf "%s" "$contents" > folder2/folder3/folder4/nested.dat
git add file1.dat file2.dat file3.dat folder1 folder2
git add .gitattributes
git commit -m "add files"
[ "$contents" = "$(cat file1.dat)" ]
[ "$contents" = "$(cat file2.dat)" ]
[ "$contents" = "$(cat file3.dat)" ]
[ "$contents" = "$(cat folder1/nested.dat)" ]
[ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ]
assert_pointer "main" "file1.dat" "$contents_oid" $contentsize
# Remove the working directory
rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2
echo "checkout should replace all"
GIT_TRACE=1 git lfs checkout 2>&1 | tee checkout.log
[ "$contents" = "$(cat file1.dat)" ]
[ "$contents" = "$(cat file2.dat)" ]
[ "$contents" = "$(cat file3.dat)" ]
[ "$contents" = "$(cat folder1/nested.dat)" ]
[ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ]
grep "Checking out LFS objects: 100% (5/5), 95 B" checkout.log
grep 'accepting "file1.dat"' checkout.log
grep 'rejecting "file1.dat"' checkout.log && exit 1
rm -f checkout.log
assert_clean_status
git rm file1.dat
echo "checkout should skip replacing files deleted in index"
git lfs checkout
[ ! -f file1.dat ]
assert_clean_worktree_with_exceptions "file1\.dat"
git reset --hard
# Remove the working directory
rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2
echo "checkout with filters"
git lfs checkout file2.dat
[ "$contents" = "$(cat file2.dat)" ]
[ ! -f file1.dat ]
[ ! -f file3.dat ]
[ ! -f folder1/nested.dat ]
[ ! -e folder2 ]
assert_clean_worktree_with_exceptions "(file[13]|nested)\.dat"
echo "quotes to avoid shell globbing"
git lfs checkout "file*.dat"
[ "$contents" = "$(cat file1.dat)" ]
[ "$contents" = "$(cat file3.dat)" ]
[ ! -f folder1/nested.dat ]
[ ! -e folder2 ]
assert_clean_worktree_with_exceptions "nested\.dat"
echo "test subdir context"
rm file1.dat
pushd folder1
git lfs checkout nested.dat
[ "$contents" = "$(cat nested.dat)" ]
[ ! -f ../file1.dat ]
[ ! -e ../folder2 ]
assert_clean_worktree_with_exceptions "(file1|folder4/nested)\.dat"
# test '.' in current dir
rm nested.dat
git lfs checkout .
[ "$contents" = "$(cat nested.dat)" ]
[ ! -f ../file1.dat ]
[ ! -e ../folder2 ]
assert_clean_worktree_with_exceptions "(file1|folder4/nested)\.dat"
# test '..' in current dir
git lfs checkout ..
[ "$contents" = "$(cat ../file1.dat)" ]
[ "$contents" = "$(cat ../folder2/folder3/folder4/nested.dat)" ]
assert_clean_status
# test glob match with '..' in current dir
rm -rf ../folder2
git lfs checkout '../folder2/**'
[ "$contents" = "$(cat ../folder2/folder3/folder4/nested.dat)" ]
assert_clean_status
popd
echo "test folder param"
rm -rf folder2
git lfs checkout folder2
[ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ]
assert_clean_status
echo "test folder param with pre-existing directory"
rm -rf folder2
mkdir folder2
git lfs checkout folder2
[ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ]
assert_clean_status
echo "test folder param with glob match"
rm -rf folder2
git lfs checkout 'folder2/**'
[ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ]
assert_clean_status
echo "test '.' in current dir"
rm -rf file1.dat file2.dat file3.dat folder1 folder2
git lfs checkout .
[ "$contents" = "$(cat file1.dat)" ]
[ "$contents" = "$(cat file2.dat)" ]
[ "$contents" = "$(cat file3.dat)" ]
[ "$contents" = "$(cat folder1/nested.dat)" ]
[ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ]
assert_clean_status
echo "test pre-existing directories"
rm -rf folder1/nested.dat folder2/folder3/folder4
git lfs checkout
[ "$contents" = "$(cat folder1/nested.dat)" ]
[ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ]
assert_clean_status
echo "test checkout with missing data doesn't fail"
git push origin main
rm -rf .git/lfs/objects
rm file*.dat
git lfs checkout
[ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ]
[ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ]
[ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ]
[ "$contents" = "$(cat folder1/nested.dat)" ]
[ "$contents" = "$(cat folder2/folder3/folder4/nested.dat)" ]
assert_clean_worktree_with_exceptions "file[123]\.dat"
)
end_test
begin_test "checkout: skip directory file conflicts"
(
set -e
reponame="checkout-skip-dir-file-conflicts"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
contents="a"
contents_oid="$(calc_oid "$contents")"
mkdir -p dir1 dir2/dir3/dir4
printf "%s" "$contents" >dir1/a.dat
printf "%s" "$contents" >dir2/dir3/dir4/a.dat
git add .gitattributes dir1 dir2
git commit -m "initial commit"
rm -rf dir1 dir2/dir3
touch dir1 dir2/dir3
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"dir1/a\.dat": not a directory' checkout.log
grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
[ -f "dir1" ]
[ -f "dir2/dir3" ]
assert_clean_index
pushd dir2
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"dir1/a\.dat": not a directory' checkout.log
grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
popd
[ -f "dir1" ]
[ -f "dir2/dir3" ]
assert_clean_index
)
end_test
begin_test "checkout: skip directory symlink conflicts"
(
set -e
skip_if_symlinks_unsupported
reponame="checkout-skip-dir-symlink-conflicts"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
contents="a"
contents_oid="$(calc_oid "$contents")"
mkdir -p dir1 dir2/dir3/dir4
printf "%s" "$contents" >dir1/a.dat
printf "%s" "$contents" >dir2/dir3/dir4/a.dat
git add .gitattributes dir1 dir2
git commit -m "initial commit"
# test with symlinks to directories
rm -rf dir1 dir2/dir3 ../link*
mkdir ../link1 ../link2
ln -s ../link1 dir1
ln -s ../../link2 dir2/dir3
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"dir1/a\.dat": not a directory' checkout.log
grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
[ -z "$(grep "is beyond a symbolic link" checkout.log)" ]
[ -L "dir1" ]
[ -L "dir2/dir3" ]
[ ! -e "../link1/a.dat" ]
[ ! -e "../link2/dir4" ]
assert_clean_index
rm -rf dir1 dir2/dir3
mkdir link1 link2
ln -s link1 dir1
ln -s ../link2 dir2/dir3
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"dir1/a\.dat": not a directory' checkout.log
grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
[ -z "$(grep "is beyond a symbolic link" checkout.log)" ]
[ -L "dir1" ]
[ -L "dir2/dir3" ]
[ ! -e "link1/a.dat" ]
[ ! -e "link2/dir4" ]
assert_clean_index
pushd dir2
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"dir1/a\.dat": not a directory' checkout.log
grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
[ -z "$(grep "is beyond a symbolic link" checkout.log)" ]
popd
[ -L "dir1" ]
[ -L "dir2/dir3" ]
[ ! -e "link1/a.dat" ]
[ ! -e "link2/dir4" ]
assert_clean_index
# test with symlink to file and dangling symlink
rm -rf dir1 dir2/dir3 ../link*
touch ../link1
ln -s ../link1 dir1
ln -s ../../link2 dir2/dir3
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"dir1/a\.dat": not a directory' checkout.log
grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
[ -L "dir1" ]
[ -L "dir2/dir3" ]
[ -f "../link1" ]
[ ! -e "../link2" ]
assert_clean_index
rm -rf dir1 dir2/dir3 link*
touch link1
ln -s link1 dir1
ln -s ../link2 dir2/dir3
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"dir1/a\.dat": not a directory' checkout.log
grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
[ -L "dir1" ]
[ -L "dir2/dir3" ]
[ -f "link1" ]
[ ! -e "link2" ]
assert_clean_index
pushd dir2
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"dir1/a\.dat": not a directory' checkout.log
grep '"dir2/dir3/dir4/a\.dat": not a directory' checkout.log
popd
[ -L "dir1" ]
[ -L "dir2/dir3" ]
[ -f "link1" ]
[ ! -e "link2" ]
assert_clean_index
)
end_test
begin_test "checkout: skip file symlink conflicts"
(
set -e
skip_if_symlinks_unsupported
reponame="checkout-skip-file-symlink-conflicts"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
contents="a"
contents_oid="$(calc_oid "$contents")"
mkdir -p dir1/dir2/dir3
printf "%s" "$contents" >a.dat
printf "%s" "$contents" >dir1/dir2/dir3/a.dat
git add .gitattributes a.dat dir1
git commit -m "initial commit"
# test with symlinks to pointer files
rm -rf a.dat dir1/dir2/dir3/a.dat ../link*
contents_pointer="$(git cat-file -p ":a.dat")"
printf "%s" "$contents_pointer" >../link1
printf "%s" "$contents_pointer" >../link2
ln -s ../link1 a.dat
ln -s ../../../../link2 dir1/dir2/dir3/a.dat
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"a\.dat": not a regular file' checkout.log
grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
[ -L "a.dat" ]
[ -L "dir1/dir2/dir3/a.dat" ]
[ -f "../link1" ]
[ "$contents_pointer" = "$(cat ../link1)" ]
[ -f "../link2" ]
[ "$contents_pointer" = "$(cat ../link2)" ]
assert_clean_index
rm -rf a.dat dir1/dir2/dir3/a.dat link*
printf "%s" "$contents_pointer" >link1
printf "%s" "$contents_pointer" >link2
ln -s link1 a.dat
ln -s ../../../link2 dir1/dir2/dir3/a.dat
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"a\.dat": not a regular file' checkout.log
grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
[ -L "a.dat" ]
[ -L "dir1/dir2/dir3/a.dat" ]
[ -f "link1" ]
[ "$contents_pointer" = "$(cat link1)" ]
[ -f "link2" ]
[ "$contents_pointer" = "$(cat link2)" ]
assert_clean_index
pushd dir1/dir2
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"a\.dat": not a regular file' checkout.log
grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
popd
[ -L "a.dat" ]
[ -L "dir1/dir2/dir3/a.dat" ]
[ -f "link1" ]
[ "$contents_pointer" = "$(cat link1)" ]
[ -f "link2" ]
[ "$contents_pointer" = "$(cat link2)" ]
assert_clean_index
# test with symlink to directory and dangling symlink
rm -rf a.dat dir1/dir2/dir3/a.dat ../link*
mkdir ../link1
ln -s ../link1 a.dat
ln -s ../../../../link2 dir1/dir2/dir3/a.dat
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"a\.dat": not a regular file' checkout.log
grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
[ -L "a.dat" ]
[ -L "dir1/dir2/dir3/a.dat" ]
[ -d "../link1" ]
[ ! -e "../link2" ]
assert_clean_index
rm -rf a.dat dir1/dir2/dir3/a.dat link*
mkdir link1
ln -s link1 a.dat
ln -s ../../../link2 dir1/dir2/dir3/a.dat
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"a\.dat": not a regular file' checkout.log
grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
[ -L "a.dat" ]
[ -L "dir1/dir2/dir3/a.dat" ]
[ -d "link1" ]
[ ! -e "link2" ]
assert_clean_index
pushd dir1/dir2
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep '"a\.dat": not a regular file' checkout.log
grep '"dir1/dir2/dir3/a\.dat": not a regular file' checkout.log
popd
[ -L "a.dat" ]
[ -L "dir1/dir2/dir3/a.dat" ]
[ -d "link1" ]
[ ! -e "link2" ]
assert_clean_index
)
end_test
# This test applies to case-preserving but case-insensitive filesystems,
# such as APFS and NTFS when in their default configurations.
# On case-sensitive filesystems this test has no particular value and
# should always pass.
begin_test "checkout: skip case-based symlink conflicts"
(
set -e
skip_if_symlinks_unsupported
# Only test with Git version 2.20.0 as it introduced detection of
# case-insensitive filesystems to the "git clone" command, which the
# test depends on to determine the filesystem type.
ensure_git_version_isnt "$VERSION_LOWER" "2.20.0"
reponame="checkout-skip-case-symlink-conflicts"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
mkdir dir1
ln -s ../link1 A.dat
ln -s ../../link2 dir1/a.dat
ln -s ../link3 DIR3
ln -s ../../link4 dir1/dir2
git add A.dat dir1 DIR3
git commit -m "initial commit"
rm A.dat dir1/* DIR3
echo "*.dat filter=lfs diff=lfs merge=lfs -text" >.gitattributes
contents="a"
contents_oid="$(calc_oid "$contents")"
mkdir dir3 dir1/DIR2
printf "%s" "$contents" >a.dat
printf "%s" "$contents" >dir1/A.dat
printf "%s" "$contents" >dir3/a.dat
printf "%s" "$contents" >dir1/DIR2/a.dat
git -c core.ignoreCase=false add .gitattributes a.dat dir1/A.dat \
dir3/a.dat dir1/DIR2/a.dat
git commit -m "case-conflicting commit"
git push origin main
assert_server_object "$reponame" "$contents_oid"
cd ..
GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert" 2>&1 | tee clone.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected clone to succeed ..."
exit 1
fi
collision="$(grep -c "collided" clone.log)" || true
cd "${reponame}-assert"
git lfs fetch origin main
assert_local_object "$contents_oid" 1
rm -rf *.dat dir1 *3 ../link*
mkdir ../link3 ../link4
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep -q 'Checking out LFS objects: 100% (4/4), 4 B' checkout.log
[ -f "a.dat" ]
[ "$contents" = "$(cat "a.dat")" ]
[ -f "dir1/A.dat" ]
[ "$contents" = "$(cat "dir1/A.dat")" ]
[ -f "dir3/a.dat" ]
[ "$contents" = "$(cat "dir3/a.dat")" ]
[ -f "dir1/DIR2/a.dat" ]
[ "$contents" = "$(cat "dir1/DIR2/a.dat")" ]
[ ! -e "../link1" ]
[ ! -e "../link2" ]
[ ! -e "../link3/a.dat" ]
[ ! -e "../link4/a.dat" ]
assert_clean_index
rm -rf a.dat dir1/A.dat dir3 dir1/DIR2
git checkout -- A.dat dir1/a.dat DIR3 dir1/dir2
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
if [ "$collision" -eq "0" ]; then
# case-sensitive filesystem
grep -q 'Checking out LFS objects: 100% (4/4), 4 B' checkout.log
else
# case-insensitive filesystem
grep '"a\.dat": not a regular file' checkout.log
grep '"dir1/A\.dat": not a regular file' checkout.log
grep '"dir3/a\.dat": not a directory' checkout.log
grep '"dir1/DIR2/a\.dat": not a directory' checkout.log
[ -z "$(grep "is beyond a symbolic link" checkout.log)" ]
fi
if [ "$collision" -eq "0" ]; then
# case-sensitive filesystem
[ -f "a.dat" ]
[ "$contents" = "$(cat "a.dat")" ]
[ -f "dir1/A.dat" ]
[ "$contents" = "$(cat "dir1/A.dat")" ]
[ -f "dir3/a.dat" ]
[ "$contents" = "$(cat "dir3/a.dat")" ]
[ -f "dir1/DIR2/a.dat" ]
[ "$contents" = "$(cat "dir1/DIR2/a.dat")" ]
else
# case-insensitive filesystem
[ -L "a.dat" ]
[ -L "dir1/A.dat" ]
[ -L "dir3" ]
[ -L "dir1/DIR2" ]
fi
[ ! -e "../link1" ]
[ ! -e "../link2" ]
[ ! -e "../link3/a.dat" ]
[ ! -e "../link4/a.dat" ]
assert_clean_index
)
end_test
begin_test "checkout: skip changed files"
(
set -e
reponame="checkout-skip-changed-files"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
contents="a"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" >a.dat
git add .gitattributes a.dat
git commit -m "initial commit"
contents_new="$contents +extra"
printf "%s" "$contents_new" >a.dat
git lfs checkout
[ "$contents_new" = "$(cat a.dat)" ]
assert_clean_index
rm a.dat
mkdir a.dat
git lfs checkout
[ -d "a.dat" ]
assert_clean_index
pushd a.dat
git lfs checkout
popd
[ -d "a.dat" ]
assert_clean_index
)
end_test
begin_test "checkout: break hard links to existing files"
(
set -e
reponame="checkout-break-file-hardlinks"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
contents="a"
contents_oid="$(calc_oid "$contents")"
mkdir -p dir1/dir2/dir3
printf "%s" "$contents" >a.dat
printf "%s" "$contents" >dir1/dir2/dir3/a.dat
git add .gitattributes a.dat dir1
git commit -m "initial commit"
git push origin main
assert_server_object "$reponame" "$contents_oid"
cd ..
GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert"
cd "${reponame}-assert"
git lfs fetch origin main
assert_local_object "$contents_oid" 1
rm -f a.dat dir1/dir2/dir3/a.dat ../link
pointer="$(git cat-file -p ":a.dat")"
echo "$pointer" >../link
ln ../link a.dat
ln ../link dir1/dir2/dir3/a.dat
git lfs checkout
[ "$contents" = "$(cat a.dat)" ]
[ "$contents" = "$(cat dir1/dir2/dir3/a.dat)" ]
[ "$pointer" = "$(cat ../link)" ]
assert_clean_status
rm a.dat dir1/dir2/dir3/a.dat
ln ../link a.dat
ln ../link dir1/dir2/dir3/a.dat
pushd dir1/dir2
git lfs checkout
popd
[ "$contents" = "$(cat a.dat)" ]
[ "$contents" = "$(cat dir1/dir2/dir3/a.dat)" ]
[ "$pointer" = "$(cat ../link)" ]
assert_clean_status
)
end_test
begin_test "checkout: without clean filter"
(
set -e
reponame="$(basename "$0" ".sh")"
git lfs uninstall
git clone "$GITSERVER/$reponame" checkout-without-clean
cd checkout-without-clean
echo "checkout without clean filter"
git lfs uninstall
git config --list > config.txt
grep "filter.lfs.clean" config.txt && {
echo "clean filter still configured:"
cat config.txt
exit 1
}
ls -al
git lfs checkout | tee checkout.txt
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
grep "Git LFS is not installed" checkout.txt
contentsize=19
contents_oid=$(calc_oid "something something")
[ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ]
[ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ]
[ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ]
[ "$(pointer $contents_oid $contentsize)" = "$(cat folder1/nested.dat)" ]
[ "$(pointer $contents_oid $contentsize)" = "$(cat folder2/folder3/folder4/nested.dat)" ]
)
end_test
begin_test "checkout: outside git repository"
(
set +e
git lfs checkout 2>&1 > checkout.log
res=$?
set -e
if [ "$res" = "0" ]; then
echo "Passes because $GIT_LFS_TEST_DIR is unset."
exit 0
fi
[ "$res" = "128" ]
grep "Not in a Git repository" checkout.log
)
end_test
begin_test "checkout: read-only directory"
(
set -e
skip_if_root_or_admin "$test_description"
reponame="checkout-read-only"
git init "$reponame"
cd "$reponame"
git lfs track "*.bin"
contents="a"
contents_oid=$(calc_oid "$contents")
mkdir dir
printf "%s" "$contents" > dir/a.bin
git add .gitattributes dir/a.bin
git commit -m "add dir/a.bin"
rm dir/a.bin
if [ "$IS_WINDOWS" -eq 1 ]; then
icacls dir /inheritance:r
icacls dir /grant:r Everyone:R
else
chmod a-w dir
fi
git lfs checkout 2>&1 | tee checkout.log
# Note that although the checkout command should log an error, at present
# we still expect a zero exit code.
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected 'git lfs checkout' to succeed ..."
exit 1
fi
assert_local_object "$contents_oid" 1
[ ! -e dir/a.bin ]
grep 'could not check out "dir/a.bin"' checkout.log
grep 'could not create working directory file' checkout.log
grep 'permission denied' checkout.log
)
end_test
begin_test "checkout: read-only file"
(
set -e
reponame="checkout-locked"
filename="a.txt"
setup_remote_repo_with_file "$reponame" "$filename"
pushd "$TRASHDIR" > /dev/null
GIT_LFS_SKIP_SMUDGE=1 clone_repo "$reponame" "${reponame}-assert"
chmod a-w "$filename"
refute_file_writeable "$filename"
assert_pointer "refs/heads/main" "$filename" "$(calc_oid "$filename\n")" 6
git lfs fetch
git lfs checkout "$filename"
refute_file_writeable "$filename"
[ "$filename" = "$(cat "$filename")" ]
popd > /dev/null
)
end_test
begin_test "checkout with empty file doesn't modify mtime"
(
set -e
git init checkout-empty-file
cd checkout-empty-file
git lfs track "*.bin"
git add .
git commit -m 'gitattributes'
printf abc > abc.bin
git add .
git commit -m 'abc'
touch foo.bin
lfstest-nanomtime foo.bin >foo.mtime
# This isn't necessary, but it takes a few cycles to make sure that our
# timestamp changes.
git add foo.bin
git commit -m 'foo'
git lfs checkout
lfstest-nanomtime foo.bin >foo.mtime2
diff -u foo.mtime foo.mtime2
)
end_test
begin_test "checkout: conflicts"
(
set -e
reponame="checkout-conflicts"
filename="file1.dat"
setup_remote_repo_with_file "$reponame" "$filename"
pushd "$TRASHDIR" > /dev/null
clone_repo "$reponame" "${reponame}_checkout"
git tag base
git checkout -b first
echo "abc123" > file1.dat
git add -u
echo "first" > other.txt
git add other.txt
git commit -m "first"
git lfs checkout --to base.txt 2>&1 | tee output.txt
grep -- '--to and exactly one of --theirs, --ours, and --base must be used together' output.txt
git lfs checkout --base 2>&1 | tee output.txt
grep -- '--to and exactly one of --theirs, --ours, and --base must be used together' output.txt
git lfs checkout --to base.txt --ours --theirs 2>&1 | tee output.txt
grep -- 'at most one of --base, --theirs, and --ours is allowed' output.txt
git lfs checkout --to base.txt --base 2>&1 | tee output.txt
grep -- '--to requires exactly one Git LFS object file path' output.txt
git lfs checkout --to base.txt --base 2>&1 abc def | tee output.txt
grep -- '--to requires exactly one Git LFS object file path' output.txt
git lfs checkout --to base.txt --base file1.dat 2>&1 | tee output.txt
grep 'Could not checkout.*not in the middle of a merge' output.txt
git checkout -b second main
echo "def456" > file1.dat
git add -u
echo "second" > other.txt
git add other.txt
git commit -m "second"
# This will cause a conflict.
git merge first && exit 1
abs_assert_dir="$(canonical_path "$TRASHDIR/${reponame}-assert")"
abs_theirs_file="$abs_assert_dir/dir1/dir2/theirs.txt"
rm -rf "$abs_assert_dir"
git lfs checkout --to base.txt --base file1.dat
git lfs checkout --to ../ours.txt --ours file1.dat
git lfs checkout --to "$abs_theirs_file" --theirs file1.dat
echo "file1.dat" | cmp - base.txt
echo "def456" | cmp - ../ours.txt
echo "abc123" | cmp - "$abs_theirs_file"
rm -rf base.txt ../ours.txt "$abs_assert_dir"
mkdir -p dir1/dir2
pushd dir1/dir2
git lfs checkout --to base.txt --base ../../file1.dat
git lfs checkout --to ../../../ours.txt --ours ../../file1.dat
git lfs checkout --to "$abs_theirs_file" --theirs ../../file1.dat
popd
echo "file1.dat" | cmp - dir1/dir2/base.txt
echo "def456" | cmp - ../ours.txt
echo "abc123" | cmp - "$abs_theirs_file"
has_native_symlinks && {
rm -rf "$abs_assert_dir"
mkdir -p "$abs_assert_dir/link1"
ln -s link1 "$abs_assert_dir/dir1"
git lfs checkout --to "$abs_theirs_file" --theirs file1.dat
[ -L "$abs_assert_dir/dir1" ]
echo "abc123" | cmp - "$abs_assert_dir/link1/dir2/theirs.txt"
}
rm -f base.txt link1 ../ours.txt ../link2
ln -s link1 base.txt
ln -s link2 ../ours.txt
git lfs checkout --to base.txt --base file1.dat
git lfs checkout --to ../ours.txt --ours file1.dat
[ ! -L "base.txt" ]
[ ! -L "../ours.txt" ]
[ ! -e "link1" ]
[ ! -e "../link2" ]
echo "file1.dat" | cmp - base.txt
echo "def456" | cmp - ../ours.txt
rm -f base.txt link1 ../ours.txt ../link2
printf "link1" >link1
printf "link2" >../link2
ln link1 base.txt
ln ../link2 ../ours.txt
git lfs checkout --to base.txt --base file1.dat
git lfs checkout --to ../ours.txt --ours file1.dat
[ -f "link1" ]
[ -f "../link2" ]
[ "link1" = "$(cat link1)" ]
[ "link2" = "$(cat ../link2)" ]
echo "file1.dat" | cmp - base.txt
echo "def456" | cmp - ../ours.txt
git lfs checkout --to base.txt --ours other.txt 2>&1 | tee output.txt
grep 'Could not find decoder pointer for object' output.txt
popd > /dev/null
)
end_test
begin_test "checkout: GIT_WORK_TREE"
(
set -e
reponame="checkout-work-tree"
remotename="$(basename "$0" ".sh")"
export GIT_WORK_TREE="$reponame" GIT_DIR="$reponame-git"
mkdir "$GIT_WORK_TREE" "$GIT_DIR"
git init
git remote add origin "$GITSERVER/$remotename"
git lfs uninstall --skip-repo
git fetch origin
git checkout -B main origin/main
git lfs install
git lfs fetch
git lfs checkout
contents="something something"
[ "$contents" = "$(cat "$reponame/file1.dat")" ]
)
end_test
begin_test "checkout: bare repository"
(
set -e
reponame="checkout-bare"
git init --bare "$reponame"
cd "$reponame"
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
[ "This operation must be run in a work tree." = "$(cat checkout.log)" ]
)
end_test
begin_test "checkout: sparse with partial clone and sparse index"
(
set -e
# Only test with Git version 2.25.0 as it introduced the
# "git sparse-checkout" command. (Note that this test also requires
# that the "git rev-list" command support the "tree:0" filter, which
# was introduced with Git version 2.20.0.)
ensure_git_version_isnt "$VERSION_LOWER" "2.25.0"
reponame="checkout-sparse"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
contents1="a"
contents1_oid=$(calc_oid "$contents1")
contents2="b"
contents2_oid=$(calc_oid "$contents2")
contents3="c"
contents3_oid=$(calc_oid "$contents3")
mkdir in-dir out-dir
printf "%s" "$contents1" >a.dat
printf "%s" "$contents2" >in-dir/b.dat
printf "%s" "$contents3" >out-dir/c.dat
git add .
git commit -m "add files"
git push origin main
assert_server_object "$reponame" "$contents1_oid"
assert_server_object "$reponame" "$contents2_oid"
assert_server_object "$reponame" "$contents3_oid"
# Create a partial clone with a cone-mode sparse checkout of one directory
# and a sparse index, which is important because otherwise the "git ls-files"
# command ignores the --sparse option and lists all Git LFS files.
cd ..
git clone --filter=tree:0 --depth=1 --no-checkout \
"$GITSERVER/$reponame" "${reponame}-partial"
cd "${reponame}-partial"
git sparse-checkout init --cone --sparse-index
git sparse-checkout set "in-dir"
git checkout main
[ -d "in-dir" ]
[ ! -e "out-dir" ]
assert_local_object "$contents1_oid" 1
assert_local_object "$contents2_oid" 1
refute_local_object "$contents3_oid"
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
# When Git version 2.42.0 or higher is available, the "git lfs checkout"
# command will use the "git ls-files" command rather than the
# "git ls-tree" command to list files. Git v2.42.0 introduced support
# in the "git ls-files" command for the "objecttype" format option and
# so Git LFS can use this command to avoid checking out objects outside
# the sparse cone. Otherwise, all Git LFS objects will be checked out.
gitversion="$(git version | cut -d" " -f3)"
set +e
compare_version "$gitversion" '2.42.0'
result=$?
set -e
if [ "$result" -eq "$VERSION_LOWER" ]; then
grep 'Skipped checkout for "out-dir/c.dat"' checkout.log
[ -f "out-dir/c.dat" ]
[ "$(pointer $contents3_oid 1)" = "$(cat "out-dir/c.dat")" ]
else
grep -q 'Skipped checkout for "out-dir/c.dat"' checkout.log && exit 1
[ ! -e "out-dir/c.dat" ]
fi
# Fetch all Git LFS objects, including those outside the sparse cone.
git lfs fetch origin main
assert_local_object "$contents3_oid" 1
git lfs checkout 2>&1 | tee checkout.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected checkout to succeed ..."
exit 1
fi
if [ "$result" -eq "$VERSION_LOWER" ]; then
grep 'Checking out LFS objects: 100% (3/3), 3 B' checkout.log
[ -f "out-dir/c.dat" ]
[ "$contents3" = "$(cat "out-dir/c.dat")" ]
else
grep -q 'Checking out LFS objects: 100% (3/3), 3 B' checkout.log && exit 1
[ ! -e "out-dir/c.dat" ]
fi
)
end_test
begin_test "checkout: pointer extension"
(
set -e
reponame="checkout-pointer-extension"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
setup_case_inverter_extension
contents="abc"
inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")"
mkdir dir1
printf "%s" "$contents" >dir1/abc.dat
git add .gitattributes dir1
git commit -m "initial commit"
assert_local_object "$inverted_contents_oid" 3
rm -rf dir1 "$LFSTEST_EXT_LOG"
git lfs checkout
[ "$contents" = "$(cat "dir1/abc.dat")" ]
grep "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG"
rm -rf dir1 "$LFSTEST_EXT_LOG"
mkdir dir2
pushd dir2
git lfs checkout
popd
[ "$contents" = "$(cat "dir1/abc.dat")" ]
grep "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG"
)
end_test
begin_test "checkout: pointer extension with conflict"
(
set -e
reponame="checkout-pointer-extension-conflict"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
setup_case_inverter_extension
contents="abc"
inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")"
mkdir dir1
printf "%s" "$contents" >dir1/abc.dat
git add .gitattributes dir1
git commit -m "initial commit"
assert_local_object "$inverted_contents_oid" 3
git checkout -b theirs
contents_theirs="Abc"
printf "%s" "$contents_theirs" >dir1/abc.dat
git add dir1
git commit -m "theirs"
git checkout main
contents_ours="aBc"
printf "%s" "$contents_ours" >dir1/abc.dat
git add dir1
git commit -m "ours"
git merge theirs && exit 1
rm -f "$LFSTEST_EXT_LOG"
git lfs checkout --to base.txt --base dir1/abc.dat
printf "%s" "$contents" | cmp - base.txt
# Note that at present we expect "git lfs checkout" to pass the argument
# from its --to option to the extension program instead of the pointer's
# file path, after converting the argument into an absolute path.
abs_curr_dir="$TRASHDIR/$reponame"
grep "smudge: $(canonical_path_escaped "$abs_curr_dir/base.txt")" "$LFSTEST_EXT_LOG"
rm -f "$LFSTEST_EXT_LOG"
pushd dir1
git lfs checkout --to ../ours.txt --ours abc.dat
popd
printf "%s" "$contents_ours" | cmp - ours.txt
# Note that at present we expect "git lfs checkout" to pass the argument
# from its --to option to the extension program instead of the pointer's
# file path, after converting the argument into an absolute path.
grep "smudge: $(canonical_path_escaped "$abs_curr_dir/ours.txt")" "$LFSTEST_EXT_LOG"
abs_assert_dir="$TRASHDIR/${reponame}-assert"
abs_theirs_file="$(canonical_path "$abs_assert_dir/dir1/dir2/theirs.txt")"
rm -rf "$abs_assert_dir" "$LFSTEST_EXT_LOG"
mkdir dir2
pushd dir2
git lfs checkout --to "$abs_theirs_file" --theirs ../dir1/abc.dat
popd
printf "%s" "$contents_theirs" | cmp - "$abs_theirs_file"
# Note that at present we expect "git lfs checkout" to pass the argument
# from its --to option to the extension program instead of the pointer's
# file path, after converting the argument into an absolute path.
grep "smudge: $(escape_path "$abs_theirs_file")" "$LFSTEST_EXT_LOG"
)
end_test
|