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 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
|
#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
begin_test "pre-push with good ref"
(
set -e
reponame="pre-push-main-branch-required"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
git lfs track "*.dat"
echo "hi" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
# for some reason, using 'tee' and $PIPESTATUS does not work here
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 > push.log
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
)
end_test
begin_test "pre-push with tracked ref"
(
set -e
reponame="pre-push-tracked-branch-required"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
git lfs track "*.dat"
echo "hi" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/tracked"
# for some reason, using 'tee' and $PIPESTATUS does not work here
echo "refs/heads/main main refs/heads/tracked 0000000000000000000000000000000000000000" |
git lfs pre-push origin main 2>&1 > push.log
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/tracked"
)
end_test
begin_test "pre-push with bad ref"
(
set -e
reponame="pre-push-other-branch-required"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
git lfs track "*.dat"
echo "hi" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/other"
# for some reason, using 'tee' and $PIPESTATUS does not work here
set +e
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/$reponame" 2> push.log
pushcode=$?
set -e
if [ "0" -eq "$pushcode" ]; then
echo "expected command to fail"
exit 1
fi
grep 'Expected ref "refs/heads/other", got "refs/heads/main"' push.log
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/other"
)
end_test
begin_test "pre-push"
(
set -e
reponame="$(basename "$0" ".sh")"
setup_remote_repo "$reponame"
clone_repo "$reponame" repo
git lfs track "*.dat"
git add .gitattributes
git commit -m "add git attributes"
git config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/$reponame" |
tee push.log
# no output if nothing to do
[ "$(du -k push.log | cut -f 1)" == "0" ]
git lfs track "*.dat"
echo "hi" > hi.dat
git add hi.dat
git commit -m "add hi.dat"
git show
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
# push file to the git lfs server
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
tee push.log
grep "Uploading LFS objects: 100% (1/1), 3 B" push.log
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
)
end_test
begin_test "pre-push dry-run"
(
set -e
reponame="$(basename "$0" ".sh")-dry-run"
setup_remote_repo "$reponame"
clone_repo "$reponame" repo-dry-run
git lfs track "*.dat"
git add .gitattributes
git commit -m "add git attributes"
git config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push --dry-run origin "$GITSERVER/$reponame" |
tee push.log
[ "" = "$(cat push.log)" ]
git lfs track "*.dat"
echo "dry" > hi.dat
git add hi.dat
git commit -m "add hi.dat"
git show
refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push --dry-run origin "$GITSERVER/$reponame" |
tee push.log
grep "push 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b => hi.dat" push.log
cat push.log
[ `wc -l < push.log` = 1 ]
refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
)
end_test
begin_test "pre-push skip-push"
(
set -e
reponame="$(basename "$0" ".sh")-skip-push"
setup_remote_repo "$reponame"
clone_repo "$reponame" repo-skip-push
git lfs track "*.dat"
git add .gitattributes
git commit -m "add git attributes"
git config "lfs.$(repo_endpoint $GITSERVER $reponame).locksverify" true
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
GIT_LFS_SKIP_PUSH=true git lfs pre-push origin "$GITSERVER/$reponame" |
tee push.log
[ "" = "$(cat push.log)" ]
git lfs track "*.dat"
echo "dry" > hi.dat
git add hi.dat
git commit -m "add hi.dat"
git show
refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
GIT_LFS_SKIP_PUSH=true git lfs pre-push origin "$GITSERVER/$reponame" |
tee push.log
[ "" = "$(cat push.log)" ]
refute_server_object "$reponame" 2840e0eafda1d0760771fe28b91247cf81c76aa888af28a850b5648a338dc15b
)
end_test
begin_test "pre-push 307 redirects"
(
set -e
reponame="$(basename "$0" ".sh")"
setup_remote_repo "$reponame"
clone_repo "$reponame" repo-307
git lfs track "*.dat"
git add .gitattributes
git commit -m "add git attributes"
# relative redirect
git config remote.origin.lfsurl "$GITSERVER/redirect307/rel/$reponame.git/info/lfs"
git lfs track "*.dat"
echo "hi" > hi.dat
git add hi.dat
git commit -m "add hi.dat"
git show
# push file to the git lfs server
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/redirect307/rel/$reponame.git/info/lfs" 2>&1 |
tee push.log
grep "Uploading LFS objects: 100% (1/1), 3 B" push.log
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4
# absolute redirect
git config remote.origin.lfsurl "$GITSERVER/redirect307/abs/$reponame.git/info/lfs"
echo "hi" > hi2.dat
git add hi2.dat
git commit -m "add hi2.dat"
git show
# push file to the git lfs server
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/redirect307/abs/$reponame.git/info/lfs" 2>&1 |
tee push.log
grep "Uploading LFS objects: 100% (1/1), 3 B" push.log
)
end_test
begin_test "pre-push with existing file"
(
set -e
reponame="$(basename "$0" ".sh")-existing-file"
setup_remote_repo "$reponame"
clone_repo "$reponame" existing-file
echo "existing" > existing.dat
git add existing.dat
git commit -m "add existing dat"
git lfs track "*.dat"
echo "new" > new.dat
git add new.dat
git add .gitattributes
git commit -m "add new file through git lfs"
# push file to the git lfs server
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
tee push.log
grep "Uploading LFS objects: 100% (1/1), 4 B" push.log
# now the file exists
assert_server_object "$reponame" 7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c
)
end_test
begin_test "pre-push with existing pointer"
(
set -e
reponame="$(basename "$0" ".sh")-existing-pointer"
setup_remote_repo "$reponame"
clone_repo "$reponame" existing-pointer
echo "$(pointer "7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c" 4)" > new.dat
git add new.dat
git commit -m "add new pointer"
mkdir -p .git/lfs/objects/7a/a7
echo "new" > .git/lfs/objects/7a/a7/7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c
# push file to the git lfs server
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
tee push.log
grep "Uploading LFS objects: 100% (1/1), 4 B" push.log
)
end_test
begin_test "pre-push with missing pointer not on server"
(
set -e
reponame="$(basename "$0" ".sh")-missing-pointer"
setup_remote_repo "$reponame"
clone_repo "$reponame" missing-pointer
oid="7aa7a5359173d05b63cfd682e3c38487f3cb4f7f1d60659fe59fab1505977d4c"
echo "$(pointer "$oid" 4)" > new.dat
git add new.dat
git commit -m "add new pointer"
# assert that push fails
set +e
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
tee push.log
set -e
grep " (missing) new.dat ($oid)" push.log
)
end_test
begin_test "pre-push with missing pointer which is on server"
(
# should permit push if files missing locally but are on server, shouldn't
# require client to have every file (prune)
set -e
reponame="$(basename "$0" ".sh")-missing-but-on-server"
setup_remote_repo "$reponame"
clone_repo "$reponame" missing-but-on-server
contents="common data"
contents_oid=$(calc_oid "$contents")
git lfs track "*.dat"
printf "%s" "$contents" > common1.dat
git add common1.dat
git add .gitattributes
git commit -m "add first file"
# push file to the git lfs server
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
tee push.log
grep "Uploading LFS objects: 100% (1/1), 11 B" push.log
# now the file exists
assert_server_object "$reponame" "$contents_oid"
# create another commit referencing same oid, then delete local data & push
printf "%s" "$contents" > common2.dat
git add common2.dat
git commit -m "add second file, same content"
rm -rf .git/lfs/objects
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
tee push.log
# make sure there were no errors reported
[ -z "$(grep -i 'Error' push.log)" ]
)
end_test
begin_test "pre-push with missing and present pointers (lfs.allowincompletepush true)"
(
set -e
reponame="pre-push-missing-and-present"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
git add .gitattributes
git commit -m "initial commit"
present="present"
present_oid="$(calc_oid "$present")"
printf "%s" "$present" > present.dat
missing="missing"
missing_oid="$(calc_oid "$missing")"
printf "%s" "$missing" > missing.dat
git add present.dat missing.dat
git commit -m "add present.dat and missing.dat"
git rm missing.dat
git commit -m "remove missing"
# :fire: the "missing" object
missing_oid_part_1="$(echo "$missing_oid" | cut -b 1-2)"
missing_oid_part_2="$(echo "$missing_oid" | cut -b 3-4)"
missing_oid_path=".git/lfs/objects/$missing_oid_part_1/$missing_oid_part_2/$missing_oid"
rm "$missing_oid_path"
git config lfs.allowincompletepush true
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
tee push.log
if [ "0" -ne "${PIPESTATUS[1]}" ]; then
echo >&2 "fatal: expected \`git lfs pre-push origin $GITSERVER/$reponame\` to succeed..."
exit 1
fi
grep "LFS upload missing objects" push.log
grep " (missing) missing.dat ($missing_oid)" push.log
assert_server_object "$reponame" "$present_oid"
refute_server_object "$reponame" "$missing_oid"
)
end_test
begin_test "pre-push reject missing pointers (lfs.allowincompletepush default)"
(
set -e
reponame="pre-push-reject-missing-and-present"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
git add .gitattributes
git commit -m "initial commit"
present="present"
present_oid="$(calc_oid "$present")"
printf "%s" "$present" > present.dat
missing="missing"
missing_oid="$(calc_oid "$missing")"
printf "%s" "$missing" > missing.dat
git add present.dat missing.dat
git commit -m "add present.dat and missing.dat"
git rm missing.dat
git commit -m "remove missing"
# :fire: the "missing" object
missing_oid_part_1="$(echo "$missing_oid" | cut -b 1-2)"
missing_oid_part_2="$(echo "$missing_oid" | cut -b 3-4)"
missing_oid_path=".git/lfs/objects/$missing_oid_part_1/$missing_oid_part_2/$missing_oid"
rm "$missing_oid_path"
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push origin "$GITSERVER/$reponame" 2>&1 |
tee push.log
if [ "2" -ne "${PIPESTATUS[1]}" ]; then
echo >&2 "fatal: expected \`git lfs pre-push origin $GITSERVER/$reponame\` to fail..."
exit 1
fi
grep 'Unable to find source' push.log
refute_server_object "$reponame" "$present_oid"
refute_server_object "$reponame" "$missing_oid"
)
end_test
begin_test "pre-push multiple branches"
(
set -e
reponame="$(basename "$0" ".sh")-multiple-branches"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
NUMFILES=6
# generate content we'll use
for ((a=0; a < NUMFILES ; a++))
do
content[$a]="filecontent$a"
oid[$a]=$(calc_oid "${content[$a]}")
done
echo "[
{
\"CommitDate\":\"$(get_date -10d)\",
\"Files\":[
{\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
{\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
},
{
\"NewBranch\":\"branch1\",
\"CommitDate\":\"$(get_date -5d)\",
\"Files\":[
{\"Filename\":\"file2.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
},
{
\"ParentBranches\":[\"main\"],
\"NewBranch\":\"branch2\",
\"CommitDate\":\"$(get_date -5d)\",
\"Files\":[
{\"Filename\":\"file3.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
},
{
\"ParentBranches\":[\"main\"],
\"NewBranch\":\"branch3\",
\"CommitDate\":\"$(get_date -2d)\",
\"Files\":[
{\"Filename\":\"file1.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}]
},
{
\"ParentBranches\":[\"main\"],
\"NewBranch\":\"branch4\",
\"CommitDate\":\"$(get_date -1d)\",
\"Files\":[
{\"Filename\":\"file4.dat\",\"Size\":${#content[5]}, \"Data\":\"${content[5]}\"}]
}
]" | lfstest-testutils addcommits
# make sure when called via git push all branches are updated
git push origin main branch1 branch2 branch3 branch4
for ((a=0; a < NUMFILES ; a++))
do
assert_server_object "$reponame" "${oid[$a]}"
done
)
end_test
begin_test "pre-push with bad remote"
(
set -e
cd repo
echo "refs/heads/main main refs/heads/main 0000000000000000000000000000000000000000" |
git lfs pre-push not-a-remote "$GITSERVER/$reponame" 2>&1 |
tee pre-push.log
grep "Invalid remote name" pre-push.log
)
end_test
begin_test "pre-push unfetched deleted remote branch & server GC"
(
# point of this is to simulate the case where the local cache of the remote
# branch state contains a branch which has actually been deleted on the remote,
# the client just doesn't know yet (hasn't done 'git fetch origin --prune')
# If the server GC'd the objects that deleted branch contained, but they were
# referenced by a branch being pushed (earlier commit), push might assume it
# doesn't have to push it, but it does. Tests that we check the real remote refs
# before making an assumption about the diff we need to push
set -e
reponame="$(basename "$0" ".sh")-server-deleted-branch-gc"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
NUMFILES=4
# generate content we'll use
for ((a=0; a < NUMFILES ; a++))
do
content[$a]="filecontent$a"
oid[$a]=$(calc_oid "${content[$a]}")
done
echo "[
{
\"CommitDate\":\"$(get_date -10d)\",
\"Files\":[
{\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
{\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
},
{
\"NewBranch\":\"branch-to-delete\",
\"CommitDate\":\"$(get_date -5d)\",
\"Files\":[
{\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
},
{
\"NewBranch\":\"branch-to-push-after\",
\"CommitDate\":\"$(get_date -2d)\",
\"Files\":[
{\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
}
]" | lfstest-testutils addcommits
# push only the first 2 branches
git push origin main branch-to-delete
for ((a=0; a < 3 ; a++))
do
assert_server_object "$reponame" "${oid[$a]}"
done
# confirm we haven't pushed the last one yet
refute_server_object "$reponame" "${oid[3]}"
# copy the cached remote ref for the branch we're going to delete remotely
cp .git/refs/remotes/origin/branch-to-delete branch-to-delete.ref
# now delete the branch on the server
git push origin --delete branch-to-delete
# remove the OID in it, as if GC'd
delete_server_object "$reponame" "${oid[2]}"
refute_server_object "$reponame" "${oid[2]}"
# Now put the cached remote ref back, as if someone else had deleted it but
# we hadn't done git fetch --prune yet
mv branch-to-delete.ref .git/refs/remotes/origin/branch-to-delete
# Confirm that local cache of remote branch is back
git branch -r 2>&1 | tee branch-r.log
grep "origin/branch-to-delete" branch-r.log
# Now push later branch which should now need to re-push previous commits LFS too
git push origin branch-to-push-after
# all objects should now be there even though cached remote branch claimed it already had file3.dat
for ((a=0; a < NUMFILES ; a++))
do
assert_server_object "$reponame" "${oid[$a]}"
done
)
end_test
begin_test "pre-push delete branch"
(
set -e
reponame="$(basename "$0" ".sh")-delete-branch"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
NUMFILES=4
# generate content we'll use
for ((a=0; a < NUMFILES ; a++))
do
content[$a]="filecontent$a"
oid[$a]=$(calc_oid "${content[$a]}")
done
echo "[
{
\"CommitDate\":\"$(get_date -2d)\",
\"Files\":[
{\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
{\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
},
{
\"NewBranch\":\"branch-to-delete\",
\"CommitDate\":\"$(get_date -1d)\",
\"Files\":[
{\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
},
{
\"ParentBranches\":[\"main\"],
\"CommitDate\":\"$(get_date -0d)\",
\"Files\":[
{\"Filename\":\"file4.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
}
]" | lfstest-testutils addcommits
# push all branches
git push origin main branch-to-delete
for ((a=0; a < NUMFILES ; a++))
do
assert_server_object "$reponame" "${oid[$a]}"
done
# deleting a branch with git push should not fail
# (requires correct special casing of "(delete) 0000000000.." in hook)
git push origin --delete branch-to-delete
)
end_test
begin_test "pre-push with our lock"
(
set -e
reponame="pre_push_owned_locks"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
git add .gitattributes
git commit -m "initial commit"
contents="locked contents"
printf "%s" "$contents" > locked.dat
git add locked.dat
git commit -m "add locked.dat"
git push origin main
git lfs lock --json "locked.dat" | tee lock.log
id=$(assert_lock lock.log locked.dat)
assert_server_lock $id
printf "authorized changes" >> locked.dat
git add locked.dat
git commit -m "add unauthorized changes"
GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log
grep "Consider unlocking your own locked files" push.log
grep "* locked.dat" push.log
assert_server_lock "$id"
)
end_test
begin_test "pre-push with their lock on lfs file"
(
set -e
reponame="pre_push_unowned_lock"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
git add .gitattributes
git commit -m "initial commit"
contents="locked contents"
# any lock path with "theirs" is returned as "their" lock by /locks/verify
printf "%s" "$contents" > locked_theirs.dat
git add locked_theirs.dat
git commit -m "add locked_theirs.dat"
git push origin main
git lfs lock --json "locked_theirs.dat" | tee lock.log
id=$(assert_lock lock.log locked_theirs.dat)
assert_server_lock $id
pushd "$TRASHDIR" >/dev/null
clone_repo "$reponame" "$reponame-assert"
git config lfs.locksverify true
printf "unauthorized changes" >> locked_theirs.dat
git add locked_theirs.dat
# --no-verify is used to avoid the pre-commit hook which is not under test
git commit --no-verify -m "add unauthorized changes"
git push origin main 2>&1 | tee push.log
res="${PIPESTATUS[0]}"
if [ "0" -eq "$res" ]; then
echo "push should fail"
exit 1
fi
grep "Unable to push locked files" push.log
grep "* locked_theirs.dat - Git LFS Tests" push.log
grep "Cannot update locked files." push.log
refute_server_object "$reponame" "$(calc_oid_file locked_theirs.dat)"
popd >/dev/null
)
end_test
begin_test "pre-push with their lock on non-lfs lockable file"
(
set -e
reponame="pre_push_unowned_lock_not_lfs"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
echo "*.dat lockable" > .gitattributes
git add .gitattributes
git commit -m "initial commit"
# any lock path with "theirs" is returned as "their" lock by /locks/verify
echo "hi" > readme.txt
echo "tiny" > tiny_locked_theirs.dat
git help > large_locked_theirs.dat
git add readme.txt tiny_locked_theirs.dat large_locked_theirs.dat
git commit -m "add initial files"
git push origin main
git lfs lock --json "tiny_locked_theirs.dat" | tee lock.log
id=$(assert_lock lock.log tiny_locked_theirs.dat)
assert_server_lock $id
git lfs lock --json "large_locked_theirs.dat" | tee lock.log
id=$(assert_lock lock.log large_locked_theirs.dat)
assert_server_lock $id
pushd "$TRASHDIR" >/dev/null
clone_repo "$reponame" "$reponame-assert"
git config lfs.locksverify true
git lfs update # manually add pre-push hook, since lfs clean hook is not used
echo "other changes" >> readme.txt
echo "unauthorized changes" >> large_locked_theirs.dat
echo "unauthorized changes" >> tiny_locked_theirs.dat
# --no-verify is used to avoid the pre-commit hook which is not under test
git commit --no-verify -am "add unauthorized changes"
git push origin main 2>&1 | tee push.log
res="${PIPESTATUS[0]}"
if [ "0" -eq "$res" ]; then
echo "push should fail"
exit 1
fi
grep "Unable to push locked files" push.log
grep "* large_locked_theirs.dat - Git LFS Tests" push.log
grep "* tiny_locked_theirs.dat - Git LFS Tests" push.log
grep "Cannot update locked files." push.log
refute_server_object "$reponame" "$(calc_oid_file large_locked_theirs.dat)"
refute_server_object "$reponame" "$(calc_oid_file tiny_locked_theirs.dat)"
popd >/dev/null
)
end_test
begin_test "pre-push locks verify 5xx with verification enabled"
(
set -e
reponame="lock-enabled-verify-5xx"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint="$(repo_endpoint $GITSERVER $reponame)"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git config "lfs.$endpoint.locksverify" true
git push origin main 2>&1 | tee push.log
grep "\"origin\" does not support the Git LFS locking API" push.log
grep "git config lfs.$endpoint.locksverify false" push.log
refute_server_object "$reponame" "$contents_oid"
)
end_test
begin_test "pre-push disable locks verify on exact url"
(
set -e
reponame="lock-disabled-verify-5xx"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint="$(repo_endpoint $GITSERVER $reponame)"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git config "lfs.$endpoint.locksverify" false
git push origin main 2>&1 | tee push.log
[ "0" -eq "$(grep -c "\"origin\" does not support the Git LFS locking API" push.log)" ]
assert_server_object "$reponame" "$contents_oid"
)
end_test
begin_test "pre-push disable locks verify on partial url"
(
set -e
reponame="lock-disabled-verify-5xx-partial"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint="$server/$repo"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git config "lfs.$endpoint.locksverify" false
git push origin main 2>&1 | tee push.log
[ "0" -eq "$(grep -c "\"origin\" does not support the Git LFS locking API" push.log)" ]
assert_server_object "$reponame" "$contents_oid"
)
end_test
begin_test "pre-push locks verify 403 with good ref"
(
set -e
reponame="lock-verify-main-branch-required"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git config "lfs.$GITSERVER/$reponame.git.locksverify" true
git push origin main 2>&1 | tee push.log
assert_server_object "$reponame" "$contents_oid" "refs/heads/main"
)
end_test
begin_test "pre-push locks verify 403 with good tracked ref"
(
set -e
reponame="lock-verify-tracked-branch-required"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git config push.default upstream
git config branch.main.merge refs/heads/tracked
git config branch.main.remote origin
git config "lfs.$GITSERVER/$reponame.git.locksverify" true
git push 2>&1 | tee push.log
assert_server_object "$reponame" "$contents_oid" "refs/heads/tracked"
)
end_test
begin_test "pre-push locks verify 403 with explicit ref"
(
set -e
reponame="lock-verify-explicit-branch-required"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git config "lfs.$GITSERVER/$reponame.git.locksverify" true
git push origin main:explicit 2>&1 | tee push.log
assert_server_object "$reponame" "$contents_oid" "refs/heads/explicit"
)
end_test
begin_test "pre-push locks verify 403 with bad ref"
(
set -e
reponame="lock-verify-other-branch-required"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git config "lfs.$GITSERVER/$reponame.git.locksverify" true
git push origin main 2>&1 | tee push.log
grep "failed to push some refs" push.log
refute_server_object "$reponame" "$contents_oid" "refs/heads/other"
)
end_test
begin_test "pre-push locks verify 5xx with verification unset"
(
set -e
reponame="lock-unset-verify-5xx"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint="$(repo_endpoint $GITSERVER $reponame)"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
[ -z "$(git config "lfs.$endpoint.locksverify")" ]
git push origin main 2>&1 | tee push.log
grep "\"origin\" does not support the Git LFS locking API" push.log
assert_server_object "$reponame" "$contents_oid"
)
end_test
begin_test "pre-push locks verify 501 with verification enabled"
(
set -e
reponame="lock-enabled-verify-501"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint="$(repo_endpoint $GITSERVER $reponame)"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git config "lfs.$endpoint.locksverify" true
git push origin main 2>&1 | tee push.log
assert_server_object "$reponame" "$contents_oid"
[ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
)
end_test
begin_test "pre-push locks verify 501 with verification disabled"
(
set -e
reponame="lock-disabled-verify-501"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint="$(repo_endpoint $GITSERVER $reponame)"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git config "lfs.$endpoint.locksverify" false
git push origin main 2>&1 | tee push.log
assert_server_object "$reponame" "$contents_oid"
[ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
)
end_test
begin_test "pre-push locks verify 501 with verification unset"
(
set -e
reponame="lock-unset-verify-501"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint="$(repo_endpoint $GITSERVER $reponame)"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
[ -z "$(git config "lfs.$endpoint.locksverify")" ]
git push origin main 2>&1 | tee push.log
assert_server_object "$reponame" "$contents_oid"
[ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
)
end_test
begin_test "pre-push locks verify 200"
(
set -e
reponame="lock-verify-200"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint="$(repo_endpoint $GITSERVER $reponame)"
[ -z "$(git config "lfs.$endpoint.locksverify")" ]
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git push origin main 2>&1 | tee push.log
grep "Locking support detected on remote \"origin\"." push.log
grep "git config lfs.$endpoint.locksverify true" push.log
assert_server_object "$reponame" "$contents_oid"
)
end_test
begin_test "pre-push locks verify 403 with verification enabled"
(
set -e
reponame="lock-enabled-verify-403"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint="$(repo_endpoint $GITSERVER $reponame)"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git config "lfs.$endpoint.locksverify" true
git push origin main 2>&1 | tee push.log
grep "error: Authentication error" push.log
refute_server_object "$reponame" "$contents_oid"
[ "true" = "$(git config "lfs.$endpoint.locksverify")" ]
)
end_test
begin_test "pre-push locks verify 403 with verification disabled"
(
set -e
reponame="lock-disabled-verify-403"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint="$(repo_endpoint $GITSERVER $reponame)"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
git config "lfs.$endpoint.locksverify" false
git push origin main 2>&1 | tee push.log
assert_server_object "$reponame" "$contents_oid"
[ "false" = "$(git config "lfs.$endpoint.locksverify")" ]
)
end_test
begin_test "pre-push locks verify 403 with verification unset"
(
set -e
reponame="lock-unset-verify-403"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint="$(repo_endpoint $GITSERVER $reponame)"
contents="example"
contents_oid="$(calc_oid "$contents")"
printf "%s" "$contents" > a.dat
git lfs track "*.dat"
git add .gitattributes a.dat
git commit --message "initial commit"
[ -z "$(git config "lfs.$endpoint.locksverify")" ]
git push origin main 2>&1 | tee push.log
grep "warning: Authentication error" push.log
assert_server_object "$reponame" "$contents_oid"
[ -z "$(git config "lfs.$endpoint.locksverify")" ]
)
end_test
begin_test "pre-push with pushDefault and explicit remote"
(
set -e
reponame="pre-push-pushdefault-explicit"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git remote add wrong "$(repo_endpoint "$GITSERVER" "wrong-url")"
git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
git config remote.pushDefault wrong
git lfs track "*.dat"
echo "hi" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin main 2>&1 | tee push.log
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
grep wrong-url push.log && exit 1
true
)
end_test
begin_test "pre-push uses optimization if remote URL matches"
(
set -e
reponame="pre-push-remote-url-optimization"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint=$(git config remote.origin.url)
contents_oid=$(calc_oid 'hi\n')
git config "lfs.$endpoint.locksverify" false
git lfs track "*.dat"
echo "hi" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
refute_server_object "$reponame" $contents_oid "refs/heads/main"
GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push "$endpoint" main 2>&1 | tee push.log
grep 'rev-list.*--not --remotes=origin' push.log
)
end_test
begin_test "pre-push does not traverse Git objects server has"
(
set -e
reponame="pre-push-traverse-server-objects"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
endpoint=$(git config remote.origin.url)
contents_oid=$(calc_oid 'hi\n')
git config "lfs.$endpoint.locksverify" false
git lfs track "*.dat"
echo "hi" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
refute_server_object "$reponame" $contents_oid "refs/heads/main"
# We use a different URL instead of a named remote or the remote URL so that
# we can't make use of the optimization that ignores objects we already have
# in remote tracking branches.
GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push "$endpoint.git" main 2>&1 | tee push.log
assert_server_object "$reponame" $contents_oid "refs/heads/main"
contents2_oid=$(calc_oid 'hello\n')
echo "hello" > b.dat
git add .gitattributes b.dat
git commit -m "add b.dat"
refute_server_object "$reponame" $contents2_oid "refs/heads/main"
GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push "$endpoint.git" main 2>&1 | tee push.log
assert_server_object "$reponame" $contents2_oid "refs/heads/main"
# Verify that we haven't tried to push or query for the object we already
# pushed before; i.e., we didn't see it because we ignored its Git object
# during traversal.
grep $contents_oid push.log && exit 1
true
)
end_test
begin_test "pre-push with force-pushed ref"
(
set -e
reponame="pre-push-force-pushed-ref"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
git config "lfs.$(repo_endpoint "$GITSERVER" "$reponame").locksverify" false
git lfs track "*.dat"
echo "hi" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
git tag -a -m tagname tagname
refute_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
git push origin main tagname
assert_server_object "$reponame" 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4 "refs/heads/main"
# We pick a different message so that we get different object IDs even if both
# commands run in the same second.
git tag -f -a -m tagname2 tagname
# Prune the old tag object.
git reflog expire --all --expire=now
git gc --prune=now
# Make sure we deal with us missing the object for the old value of the tag ref.
git push origin +tagname
)
end_test
begin_test "pre-push with local path"
(
set -e
reponame="pre-push-local-path"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame-2"
cd ..
clone_repo "$reponame" "$reponame"
git lfs track "*.dat"
echo "hi" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
# Push to the other repo.
git push "../$reponame-2" main:foo
# Push to . to make sure that works.
git push "." main:foo
git lfs fsck
cd "../$reponame-2"
git checkout foo
git lfs fsck
)
end_test
|