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 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544
|
#!/bin/sh
# Copyright (c) 2006, Junio C Hamano.
test_description='Per branch config variables affects "git fetch".
'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-bundle.sh
if ! test_have_prereq PERL_TEST_HELPERS
then
skip_all='skipping fetch tests; Perl not available'
test_done
fi
D=$(pwd)
test_expect_success setup '
echo >file original &&
git add file &&
git commit -a -m original &&
git branch -M main
'
test_expect_success "clone and setup child repos" '
git clone . one &&
(
cd one &&
echo >file updated by one &&
git commit -a -m "updated by one"
) &&
git clone . two &&
(
cd two &&
git config branch.main.remote one &&
git config remote.one.url ../one/.git/ &&
git config remote.one.fetch refs/heads/main:refs/heads/one
) &&
git clone . three &&
(
cd three &&
git config set remote.two.url ../two/.git/ &&
git config set remote.two.fetch refs/heads/main:refs/heads/two &&
git config set --append remote.two.fetch refs/heads/one:refs/heads/one &&
git config set branch.main.remote two &&
git config set branch.main.merge refs/heads/one
) &&
git clone . bundle &&
git clone . seven
'
test_expect_success "fetch test" '
cd "$D" &&
echo >file updated by origin &&
git commit -a -m "updated by origin" &&
cd two &&
git fetch &&
git rev-parse --verify refs/heads/one &&
mine=$(git rev-parse refs/heads/one) &&
his=$(cd ../one && git rev-parse refs/heads/main) &&
test "z$mine" = "z$his"
'
test_expect_success "fetch test for-merge" '
cd "$D" &&
cd three &&
git fetch &&
git rev-parse --verify refs/heads/two &&
git rev-parse --verify refs/heads/one &&
main_in_two=$(cd ../two && git rev-parse main) &&
one_in_two=$(cd ../two && git rev-parse one) &&
{
echo "$one_in_two " &&
echo "$main_in_two not-for-merge"
} >expected &&
cut -f -2 .git/FETCH_HEAD >actual &&
test_cmp expected actual'
test_expect_success "fetch test remote HEAD" '
cd "$D" &&
cd two &&
git fetch &&
git rev-parse --verify refs/remotes/origin/HEAD &&
git rev-parse --verify refs/remotes/origin/main &&
head=$(git rev-parse refs/remotes/origin/HEAD) &&
branch=$(git rev-parse refs/remotes/origin/main) &&
test "z$head" = "z$branch"'
test_expect_success "fetch test remote HEAD in bare repository" '
test_when_finished rm -rf barerepo &&
(
cd "$D" &&
git init --bare barerepo &&
cd barerepo &&
git remote add upstream ../two &&
git fetch upstream &&
git rev-parse --verify refs/remotes/upstream/HEAD &&
git rev-parse --verify refs/remotes/upstream/main &&
head=$(git rev-parse refs/remotes/upstream/HEAD) &&
branch=$(git rev-parse refs/remotes/upstream/main) &&
test "z$head" = "z$branch"
)
'
test_expect_success "fetch test remote HEAD change" '
cd "$D" &&
cd two &&
git switch -c other &&
git push -u origin other &&
git rev-parse --verify refs/remotes/origin/HEAD &&
git rev-parse --verify refs/remotes/origin/main &&
git rev-parse --verify refs/remotes/origin/other &&
git remote set-head origin other &&
git fetch &&
head=$(git rev-parse refs/remotes/origin/HEAD) &&
branch=$(git rev-parse refs/remotes/origin/other) &&
test "z$head" = "z$branch"'
test_expect_success "fetch test followRemoteHEAD never" '
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
(
cd "$D" &&
cd two &&
git update-ref --no-deref -d refs/remotes/origin/HEAD &&
git config set remote.origin.followRemoteHEAD "never" &&
GIT_TRACE_PACKET=$PWD/trace.out git fetch &&
# Confirm that we do not even ask for HEAD when we are
# not going to act on it.
test_grep ! "ref-prefix HEAD" trace.out &&
test_must_fail git rev-parse --verify refs/remotes/origin/HEAD
)
'
test_expect_success "fetch test followRemoteHEAD warn no change" '
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
(
cd "$D" &&
cd two &&
git rev-parse --verify refs/remotes/origin/other &&
git remote set-head origin other &&
git rev-parse --verify refs/remotes/origin/HEAD &&
git rev-parse --verify refs/remotes/origin/main &&
git config set remote.origin.followRemoteHEAD "warn" &&
git fetch >output &&
echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \
"but we have ${SQ}other${SQ} locally." >expect &&
test_cmp expect output &&
head=$(git rev-parse refs/remotes/origin/HEAD) &&
branch=$(git rev-parse refs/remotes/origin/other) &&
test "z$head" = "z$branch"
)
'
test_expect_success "fetch test followRemoteHEAD warn create" '
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
(
cd "$D" &&
cd two &&
git update-ref --no-deref -d refs/remotes/origin/HEAD &&
git config set remote.origin.followRemoteHEAD "warn" &&
git rev-parse --verify refs/remotes/origin/main &&
output=$(git fetch) &&
test "z" = "z$output" &&
head=$(git rev-parse refs/remotes/origin/HEAD) &&
branch=$(git rev-parse refs/remotes/origin/main) &&
test "z$head" = "z$branch"
)
'
test_expect_success "fetch test followRemoteHEAD warn detached" '
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
(
cd "$D" &&
cd two &&
git update-ref --no-deref -d refs/remotes/origin/HEAD &&
git update-ref refs/remotes/origin/HEAD HEAD &&
HEAD=$(git log --pretty="%H") &&
git config set remote.origin.followRemoteHEAD "warn" &&
git fetch >output &&
echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \
"but we have a detached HEAD pointing to" \
"${SQ}${HEAD}${SQ} locally." >expect &&
test_cmp expect output
)
'
test_expect_success "fetch test followRemoteHEAD warn quiet" '
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
(
cd "$D" &&
cd two &&
git rev-parse --verify refs/remotes/origin/other &&
git remote set-head origin other &&
git rev-parse --verify refs/remotes/origin/HEAD &&
git rev-parse --verify refs/remotes/origin/main &&
git config set remote.origin.followRemoteHEAD "warn" &&
output=$(git fetch --quiet) &&
test "z" = "z$output" &&
head=$(git rev-parse refs/remotes/origin/HEAD) &&
branch=$(git rev-parse refs/remotes/origin/other) &&
test "z$head" = "z$branch"
)
'
test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is same" '
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
(
cd "$D" &&
cd two &&
git rev-parse --verify refs/remotes/origin/other &&
git remote set-head origin other &&
git rev-parse --verify refs/remotes/origin/HEAD &&
git rev-parse --verify refs/remotes/origin/main &&
git config set remote.origin.followRemoteHEAD "warn-if-not-main" &&
actual=$(git fetch) &&
test "z" = "z$actual" &&
head=$(git rev-parse refs/remotes/origin/HEAD) &&
branch=$(git rev-parse refs/remotes/origin/other) &&
test "z$head" = "z$branch"
)
'
test_expect_success "fetch test followRemoteHEAD warn-if-not-branch branch is different" '
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
(
cd "$D" &&
cd two &&
git rev-parse --verify refs/remotes/origin/other &&
git remote set-head origin other &&
git rev-parse --verify refs/remotes/origin/HEAD &&
git rev-parse --verify refs/remotes/origin/main &&
git config set remote.origin.followRemoteHEAD "warn-if-not-some/different-branch" &&
git fetch >actual &&
echo "${SQ}HEAD${SQ} at ${SQ}origin${SQ} is ${SQ}main${SQ}," \
"but we have ${SQ}other${SQ} locally." >expect &&
test_cmp expect actual &&
head=$(git rev-parse refs/remotes/origin/HEAD) &&
branch=$(git rev-parse refs/remotes/origin/other) &&
test "z$head" = "z$branch"
)
'
test_expect_success "fetch test followRemoteHEAD always" '
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
(
cd "$D" &&
cd two &&
git rev-parse --verify refs/remotes/origin/other &&
git remote set-head origin other &&
git rev-parse --verify refs/remotes/origin/HEAD &&
git rev-parse --verify refs/remotes/origin/main &&
git config set remote.origin.followRemoteHEAD "always" &&
git fetch &&
head=$(git rev-parse refs/remotes/origin/HEAD) &&
branch=$(git rev-parse refs/remotes/origin/main) &&
test "z$head" = "z$branch"
)
'
test_expect_success 'followRemoteHEAD does not kick in with refspecs' '
test_when_finished "git config unset remote.origin.followRemoteHEAD" &&
(
cd "$D" &&
cd two &&
git remote set-head origin other &&
git config set remote.origin.followRemoteHEAD always &&
git fetch origin refs/heads/main:refs/remotes/origin/main &&
echo refs/remotes/origin/other >expect &&
git symbolic-ref refs/remotes/origin/HEAD >actual &&
test_cmp expect actual
)
'
test_expect_success 'fetch --prune on its own works as expected' '
cd "$D" &&
git clone . prune &&
cd prune &&
git update-ref refs/remotes/origin/extrabranch main &&
git fetch --prune origin &&
test_must_fail git rev-parse origin/extrabranch
'
test_expect_success 'fetch --prune with a branch name keeps branches' '
cd "$D" &&
git clone . prune-branch &&
cd prune-branch &&
git update-ref refs/remotes/origin/extrabranch main &&
git fetch --prune origin main &&
git rev-parse origin/extrabranch
'
test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
cd "$D" &&
git clone . prune-namespace &&
cd prune-namespace &&
git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
git rev-parse origin/main
'
test_expect_success 'fetch --prune handles overlapping refspecs' '
cd "$D" &&
git update-ref refs/pull/42/head main &&
git clone . prune-overlapping &&
cd prune-overlapping &&
git config --add remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
git fetch --prune origin &&
git rev-parse origin/main &&
git rev-parse origin/pr/42 &&
git config --unset-all remote.origin.fetch &&
git config remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
git config --add remote.origin.fetch refs/heads/*:refs/remotes/origin/* &&
git fetch --prune origin &&
git rev-parse origin/main &&
git rev-parse origin/pr/42
'
test_expect_success 'fetch --prune --tags prunes branches but not tags' '
cd "$D" &&
git clone . prune-tags &&
cd prune-tags &&
git tag sometag main &&
# Create what looks like a remote-tracking branch from an earlier
# fetch that has since been deleted from the remote:
git update-ref refs/remotes/origin/fake-remote main &&
git fetch --prune --tags origin &&
git rev-parse origin/main &&
test_must_fail git rev-parse origin/fake-remote &&
git rev-parse sometag
'
test_expect_success 'fetch --prune --tags with branch does not prune other things' '
cd "$D" &&
git clone . prune-tags-branch &&
cd prune-tags-branch &&
git tag sometag main &&
git update-ref refs/remotes/origin/extrabranch main &&
git fetch --prune --tags origin main &&
git rev-parse origin/extrabranch &&
git rev-parse sometag
'
test_expect_success 'fetch --prune --tags with refspec prunes based on refspec' '
cd "$D" &&
git clone . prune-tags-refspec &&
cd prune-tags-refspec &&
git tag sometag main &&
git update-ref refs/remotes/origin/foo/otherbranch main &&
git update-ref refs/remotes/origin/extrabranch main &&
git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
git rev-parse origin/extrabranch &&
git rev-parse sometag
'
test_expect_success 'fetch --tags gets tags even without a configured remote' '
REMOTE="$(pwd)/test_tag_1" &&
git init test_tag_1 &&
(
cd test_tag_1 &&
test_commit foo
) &&
git init test_tag_2 &&
(
cd test_tag_2 &&
git fetch --tags "file://$REMOTE" &&
echo "foo" >expect &&
git tag >actual &&
test_cmp expect actual
)
'
test_expect_success REFFILES 'fetch --prune fails to delete branches' '
cd "$D" &&
git clone . prune-fail &&
cd prune-fail &&
git update-ref refs/remotes/origin/extrabranch main &&
git pack-refs --all &&
: this will prevent --prune from locking packed-refs for deleting refs, but adding loose refs still succeeds &&
>.git/packed-refs.new &&
test_must_fail git fetch --prune origin
'
test_expect_success 'fetch --atomic works with a single branch' '
test_when_finished "rm -rf \"$D\"/atomic" &&
cd "$D" &&
git clone . atomic &&
git branch atomic-branch &&
oid=$(git rev-parse atomic-branch) &&
echo "$oid" >expected &&
git -C atomic fetch --atomic origin &&
git -C atomic rev-parse origin/atomic-branch >actual &&
test_cmp expected actual &&
test $oid = "$(git -C atomic rev-parse --verify FETCH_HEAD)"
'
test_expect_success 'fetch --atomic works with multiple branches' '
test_when_finished "rm -rf \"$D\"/atomic" &&
cd "$D" &&
git clone . atomic &&
git branch atomic-branch-1 &&
git branch atomic-branch-2 &&
git branch atomic-branch-3 &&
git rev-parse refs/heads/atomic-branch-1 refs/heads/atomic-branch-2 refs/heads/atomic-branch-3 >actual &&
git -C atomic fetch --atomic origin &&
git -C atomic rev-parse refs/remotes/origin/atomic-branch-1 refs/remotes/origin/atomic-branch-2 refs/remotes/origin/atomic-branch-3 >expected &&
test_cmp expected actual
'
test_expect_success 'fetch --atomic works with mixed branches and tags' '
test_when_finished "rm -rf \"$D\"/atomic" &&
cd "$D" &&
git clone . atomic &&
git branch atomic-mixed-branch &&
git tag atomic-mixed-tag &&
git rev-parse refs/heads/atomic-mixed-branch refs/tags/atomic-mixed-tag >actual &&
git -C atomic fetch --tags --atomic origin &&
git -C atomic rev-parse refs/remotes/origin/atomic-mixed-branch refs/tags/atomic-mixed-tag >expected &&
test_cmp expected actual
'
test_expect_success 'fetch --atomic prunes references' '
test_when_finished "rm -rf \"$D\"/atomic" &&
cd "$D" &&
git branch atomic-prune-delete &&
git clone . atomic &&
git branch --delete atomic-prune-delete &&
git branch atomic-prune-create &&
git rev-parse refs/heads/atomic-prune-create >actual &&
git -C atomic fetch --prune --atomic origin &&
test_must_fail git -C atomic rev-parse refs/remotes/origin/atomic-prune-delete &&
git -C atomic rev-parse refs/remotes/origin/atomic-prune-create >expected &&
test_cmp expected actual
'
test_expect_success 'fetch --atomic aborts with non-fast-forward update' '
test_when_finished "rm -rf \"$D\"/atomic" &&
cd "$D" &&
git branch atomic-non-ff &&
git clone . atomic &&
git rev-parse HEAD >actual &&
git branch atomic-new-branch &&
parent_commit=$(git rev-parse atomic-non-ff~) &&
git update-ref refs/heads/atomic-non-ff $parent_commit &&
test_must_fail git -C atomic fetch --atomic origin refs/heads/*:refs/remotes/origin/* &&
test_must_fail git -C atomic rev-parse refs/remotes/origin/atomic-new-branch &&
git -C atomic rev-parse refs/remotes/origin/atomic-non-ff >expected &&
test_cmp expected actual &&
test_must_be_empty atomic/.git/FETCH_HEAD
'
test_expect_success 'fetch --atomic executes a single reference transaction only' '
test_when_finished "rm -rf \"$D\"/atomic" &&
cd "$D" &&
git clone . atomic &&
git branch atomic-hooks-1 &&
git branch atomic-hooks-2 &&
head_oid=$(git rev-parse HEAD) &&
cat >expected <<-EOF &&
prepared
$ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1
$ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2
committed
$ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1
$ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2
EOF
rm -f atomic/actual &&
test_hook -C atomic reference-transaction <<-\EOF &&
( echo "$*" && cat ) >>actual
EOF
git -C atomic fetch --atomic origin &&
test_cmp expected atomic/actual
'
test_expect_success 'fetch --atomic aborts all reference updates if hook aborts' '
test_when_finished "rm -rf \"$D\"/atomic" &&
cd "$D" &&
git clone . atomic &&
git branch atomic-hooks-abort-1 &&
git branch atomic-hooks-abort-2 &&
git branch atomic-hooks-abort-3 &&
git tag atomic-hooks-abort &&
head_oid=$(git rev-parse HEAD) &&
cat >expected <<-EOF &&
prepared
$ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-1
$ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-2
$ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-3
$ZERO_OID $head_oid refs/tags/atomic-hooks-abort
aborted
$ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-1
$ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-2
$ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-3
$ZERO_OID $head_oid refs/tags/atomic-hooks-abort
EOF
rm -f atomic/actual &&
test_hook -C atomic/.git reference-transaction <<-\EOF &&
( echo "$*" && cat ) >>actual
exit 1
EOF
git -C atomic for-each-ref >expected-refs &&
test_must_fail git -C atomic fetch --tags --atomic origin &&
git -C atomic for-each-ref >actual-refs &&
test_cmp expected-refs actual-refs &&
test_must_be_empty atomic/.git/FETCH_HEAD
'
test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' '
test_when_finished "rm -rf \"$D\"/atomic" &&
cd "$D" &&
git clone . atomic &&
oid=$(git rev-parse HEAD) &&
git branch atomic-fetch-head-1 &&
git -C atomic fetch --atomic origin atomic-fetch-head-1 &&
test_line_count = 1 atomic/.git/FETCH_HEAD &&
git branch atomic-fetch-head-2 &&
git -C atomic fetch --atomic --append origin atomic-fetch-head-2 &&
test_line_count = 2 atomic/.git/FETCH_HEAD &&
cp atomic/.git/FETCH_HEAD expected &&
test_hook -C atomic reference-transaction <<-\EOF &&
exit 1
EOF
git branch atomic-fetch-head-3 &&
test_must_fail git -C atomic fetch --atomic --append origin atomic-fetch-head-3 &&
test_cmp expected atomic/.git/FETCH_HEAD
'
test_expect_success REFFILES 'fetch --atomic fails transaction if reference locked' '
test_when_finished "rm -rf upstream repo" &&
git init upstream &&
git -C upstream commit --allow-empty -m 1 &&
git -C upstream switch -c foobar &&
git clone --mirror upstream repo &&
git -C upstream commit --allow-empty -m 2 &&
touch repo/refs/heads/foobar.lock &&
test_must_fail git -C repo fetch --atomic origin
'
test_expect_success '--refmap="" ignores configured refspec' '
cd "$TRASH_DIRECTORY" &&
git clone "$D" remote-refs &&
git -C remote-refs rev-parse remotes/origin/main >old &&
git -C remote-refs update-ref refs/remotes/origin/main main~1 &&
git -C remote-refs rev-parse remotes/origin/main >new &&
git -C remote-refs fetch --refmap= origin "+refs/heads/*:refs/hidden/origin/*" &&
git -C remote-refs rev-parse remotes/origin/main >actual &&
test_cmp new actual &&
git -C remote-refs fetch origin &&
git -C remote-refs rev-parse remotes/origin/main >actual &&
test_cmp old actual
'
test_expect_success '--refmap="" and --prune' '
git -C remote-refs update-ref refs/remotes/origin/foo/otherbranch main &&
git -C remote-refs update-ref refs/hidden/foo/otherbranch main &&
git -C remote-refs fetch --prune --refmap="" origin +refs/heads/*:refs/hidden/* &&
git -C remote-refs rev-parse remotes/origin/foo/otherbranch &&
test_must_fail git -C remote-refs rev-parse refs/hidden/foo/otherbranch &&
git -C remote-refs fetch --prune origin &&
test_must_fail git -C remote-refs rev-parse remotes/origin/foo/otherbranch
'
test_expect_success 'fetch tags when there is no tags' '
cd "$D" &&
mkdir notags &&
cd notags &&
git init &&
git fetch -t ..
'
test_expect_success 'fetch following tags' '
cd "$D" &&
git tag -a -m "annotated" anno HEAD &&
git tag light HEAD &&
mkdir four &&
cd four &&
git init &&
git fetch .. :track &&
git show-ref --verify refs/tags/anno &&
git show-ref --verify refs/tags/light
'
test_expect_success 'fetch uses remote ref names to describe new refs' '
cd "$D" &&
git init descriptive &&
(
cd descriptive &&
git config remote.o.url .. &&
git config remote.o.fetch "refs/heads/*:refs/crazyheads/*" &&
git config --add remote.o.fetch "refs/others/*:refs/heads/*" &&
git fetch o
) &&
git tag -a -m "Descriptive tag" descriptive-tag &&
git branch descriptive-branch &&
git checkout descriptive-branch &&
echo "Nuts" >crazy &&
git add crazy &&
git commit -a -m "descriptive commit" &&
git update-ref refs/others/crazy HEAD &&
(
cd descriptive &&
git fetch o 2>actual &&
test_grep "new branch.* -> refs/crazyheads/descriptive-branch$" actual &&
test_grep "new tag.* -> descriptive-tag$" actual &&
test_grep "new ref.* -> crazy$" actual
) &&
git checkout main
'
test_expect_success 'fetch must not resolve short tag name' '
cd "$D" &&
mkdir five &&
cd five &&
git init &&
test_must_fail git fetch .. anno:five
'
test_expect_success 'fetch can now resolve short remote name' '
cd "$D" &&
git update-ref refs/remotes/six/HEAD HEAD &&
mkdir six &&
cd six &&
git init &&
git fetch .. six:six
'
test_expect_success 'create bundle 1' '
cd "$D" &&
echo >file updated again by origin &&
git commit -a -m "tip" &&
git bundle create --version=3 bundle1 main^..main
'
test_expect_success 'header of bundle looks right' '
cat >expect <<-EOF &&
# v3 git bundle
@object-format=$(test_oid algo)
-OID updated by origin
OID refs/heads/main
EOF
sed -e "s/$OID_REGEX/OID/g" -e "5q" "$D"/bundle1 >actual &&
test_cmp expect actual
'
test_expect_success 'create bundle 2' '
cd "$D" &&
git bundle create bundle2 main~2..main
'
test_expect_success 'unbundle 1' '
cd "$D/bundle" &&
git checkout -b some-branch &&
test_must_fail git fetch "$D/bundle1" main:main
'
test_expect_success 'bundle 1 has only 3 files ' '
cd "$D" &&
test_bundle_object_count bundle1 3
'
test_expect_success 'unbundle 2' '
cd "$D/bundle" &&
git fetch ../bundle2 main:main &&
test "tip" = "$(git log -1 --pretty=oneline main | cut -d" " -f2)"
'
test_expect_success 'bundle does not prerequisite objects' '
cd "$D" &&
touch file2 &&
git add file2 &&
git commit -m add.file2 file2 &&
git bundle create bundle3 -1 HEAD &&
test_bundle_object_count bundle3 3
'
test_expect_success 'bundle should be able to create a full history' '
cd "$D" &&
git tag -a -m "1.0" v1.0 main &&
git bundle create bundle4 v1.0
'
test_expect_success 'fetch with a non-applying branch.<name>.merge' '
git config branch.main.remote yeti &&
git config branch.main.merge refs/heads/bigfoot &&
git config remote.blub.url one &&
git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
git fetch blub
'
# URL supplied to fetch does not match the url of the configured branch's remote
test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
one_head=$(cd one && git rev-parse HEAD) &&
this_head=$(git rev-parse HEAD) &&
rm .git/FETCH_HEAD &&
git fetch one &&
test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
test $this_head = "$(git rev-parse --verify HEAD)"
'
# URL supplied to fetch matches the url of the configured branch's remote and
# the merge spec matches the branch the remote HEAD points to
test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [2]' '
one_ref=$(cd one && git symbolic-ref HEAD) &&
git config branch.main.remote blub &&
git config branch.main.merge "$one_ref" &&
rm .git/FETCH_HEAD &&
git fetch one &&
test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
test $this_head = "$(git rev-parse --verify HEAD)"
'
# URL supplied to fetch matches the url of the configured branch's remote, but
# the merge spec does not match the branch the remote HEAD points to
test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
git config branch.main.merge "${one_ref}_not" &&
rm .git/FETCH_HEAD &&
git fetch one &&
test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
test $this_head = "$(git rev-parse --verify HEAD)"
'
# the strange name is: a\!'b
test_expect_success 'quoting of a strangely named repo' '
test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
grep "fatal: '\''a\\\\!'\''b'\''" result
'
test_expect_success 'bundle should record HEAD correctly' '
cd "$D" &&
git bundle create bundle5 HEAD main &&
git bundle list-heads bundle5 >actual &&
for h in HEAD refs/heads/main
do
echo "$(git rev-parse --verify $h) $h" || return 1
done >expect &&
test_cmp expect actual
'
test_expect_success 'mark initial state of origin/main' '
(
cd three &&
git tag base-origin-main refs/remotes/origin/main
)
'
test_expect_success 'explicit fetch should update tracking' '
cd "$D" &&
git branch -f side &&
(
cd three &&
git update-ref refs/remotes/origin/main base-origin-main &&
o=$(git rev-parse --verify refs/remotes/origin/main) &&
git fetch origin main &&
n=$(git rev-parse --verify refs/remotes/origin/main) &&
test "$o" != "$n" &&
test_must_fail git rev-parse --verify refs/remotes/origin/side
)
'
test_expect_success 'explicit pull should update tracking' '
cd "$D" &&
git branch -f side &&
(
cd three &&
git update-ref refs/remotes/origin/main base-origin-main &&
o=$(git rev-parse --verify refs/remotes/origin/main) &&
git pull origin main &&
n=$(git rev-parse --verify refs/remotes/origin/main) &&
test "$o" != "$n" &&
test_must_fail git rev-parse --verify refs/remotes/origin/side
)
'
test_expect_success 'explicit --refmap is allowed only with command-line refspec' '
cd "$D" &&
(
cd three &&
test_must_fail git fetch --refmap="*:refs/remotes/none/*"
)
'
test_expect_success 'explicit --refmap option overrides remote.*.fetch' '
cd "$D" &&
git branch -f side &&
(
cd three &&
git update-ref refs/remotes/origin/main base-origin-main &&
o=$(git rev-parse --verify refs/remotes/origin/main) &&
git fetch --refmap="refs/heads/*:refs/remotes/other/*" origin main &&
n=$(git rev-parse --verify refs/remotes/origin/main) &&
test "$o" = "$n" &&
test_must_fail git rev-parse --verify refs/remotes/origin/side &&
git rev-parse --verify refs/remotes/other/main
)
'
test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' '
cd "$D" &&
git branch -f side &&
(
cd three &&
git update-ref refs/remotes/origin/main base-origin-main &&
o=$(git rev-parse --verify refs/remotes/origin/main) &&
git fetch --refmap="" origin main &&
n=$(git rev-parse --verify refs/remotes/origin/main) &&
test "$o" = "$n" &&
test_must_fail git rev-parse --verify refs/remotes/origin/side
)
'
test_expect_success 'configured fetch updates tracking' '
cd "$D" &&
git branch -f side &&
(
cd three &&
git update-ref refs/remotes/origin/main base-origin-main &&
o=$(git rev-parse --verify refs/remotes/origin/main) &&
git fetch origin &&
n=$(git rev-parse --verify refs/remotes/origin/main) &&
test "$o" != "$n" &&
git rev-parse --verify refs/remotes/origin/side
)
'
test_expect_success 'non-matching refspecs do not confuse tracking update' '
cd "$D" &&
git update-ref refs/odd/location HEAD &&
(
cd three &&
git update-ref refs/remotes/origin/main base-origin-main &&
git config --add remote.origin.fetch \
refs/odd/location:refs/remotes/origin/odd &&
o=$(git rev-parse --verify refs/remotes/origin/main) &&
git fetch origin main &&
n=$(git rev-parse --verify refs/remotes/origin/main) &&
test "$o" != "$n" &&
test_must_fail git rev-parse --verify refs/remotes/origin/odd
)
'
test_expect_success 'pushing nonexistent branch by mistake should not segv' '
cd "$D" &&
test_must_fail git push seven no:no
'
test_expect_success 'auto tag following fetches minimum' '
cd "$D" &&
git clone .git follow &&
git checkout HEAD^0 &&
(
for i in 1 2 3 4 5 6 7
do
echo $i >>file &&
git commit -m $i -a &&
git tag -a -m $i excess-$i || exit 1
done
) &&
git checkout main &&
(
cd follow &&
git fetch
)
'
test_expect_success 'refuse to fetch into the current branch' '
test_must_fail git fetch . side:main
'
test_expect_success 'fetch into the current branch with --update-head-ok' '
git fetch --update-head-ok . side:main
'
test_expect_success 'fetch --dry-run does not touch FETCH_HEAD, but still prints what would be written' '
rm -f .git/FETCH_HEAD err &&
git fetch --dry-run . 2>err &&
! test -f .git/FETCH_HEAD &&
grep FETCH_HEAD err
'
test_expect_success '--no-write-fetch-head does not touch FETCH_HEAD, and does not print what would be written' '
rm -f .git/FETCH_HEAD err &&
git fetch --no-write-fetch-head . 2>err &&
! test -f .git/FETCH_HEAD &&
! grep FETCH_HEAD err
'
test_expect_success '--write-fetch-head gets defeated by --dry-run' '
rm -f .git/FETCH_HEAD &&
git fetch --dry-run --write-fetch-head . &&
! test -f .git/FETCH_HEAD
'
test_expect_success "should be able to fetch with duplicate refspecs" '
mkdir dups &&
(
cd dups &&
git init &&
git config branch.main.remote three &&
git config remote.three.url ../three/.git &&
git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
git fetch three
)
'
test_expect_success 'LHS of refspec follows ref disambiguation rules' '
mkdir lhs-ambiguous &&
(
cd lhs-ambiguous &&
git init server &&
test_commit -C server unwanted &&
test_commit -C server wanted &&
git init client &&
# Check a name coming after "refs" alphabetically ...
git -C server update-ref refs/heads/s wanted &&
git -C server update-ref refs/heads/refs/heads/s unwanted &&
git -C client fetch ../server +refs/heads/s:refs/heads/checkthis &&
git -C server rev-parse wanted >expect &&
git -C client rev-parse checkthis >actual &&
test_cmp expect actual &&
# ... and one before.
git -C server update-ref refs/heads/q wanted &&
git -C server update-ref refs/heads/refs/heads/q unwanted &&
git -C client fetch ../server +refs/heads/q:refs/heads/checkthis &&
git -C server rev-parse wanted >expect &&
git -C client rev-parse checkthis >actual &&
test_cmp expect actual &&
# Tags are preferred over branches like refs/{heads,tags}/*
git -C server update-ref refs/tags/t wanted &&
git -C server update-ref refs/heads/t unwanted &&
git -C client fetch ../server +t:refs/heads/checkthis &&
git -C server rev-parse wanted >expect &&
git -C client rev-parse checkthis >actual
)
'
test_expect_success 'fetch.writeCommitGraph' '
git clone three write &&
(
cd three &&
test_commit new
) &&
(
cd write &&
git -c fetch.writeCommitGraph fetch origin &&
test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
)
'
test_expect_success 'fetch.writeCommitGraph with submodules' '
test_config_global protocol.file.allow always &&
git clone dups super &&
(
cd super &&
git submodule add "file://$TRASH_DIRECTORY/three" &&
git commit -m "add submodule"
) &&
git clone "super" super-clone &&
(
cd super-clone &&
rm -rf .git/objects/info &&
git -c fetch.writeCommitGraph=true fetch origin &&
test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain &&
git -c fetch.writeCommitGraph=true fetch --recurse-submodules origin
)
'
# fetches from first configured url
test_expect_success 'fetch from multiple configured URLs in single remote' '
git init url1 &&
git remote add multipleurls url1 &&
git remote set-url --add multipleurls url2 &&
git fetch multipleurls
'
# configured prune tests
set_config_tristate () {
# var=$1 val=$2
case "$2" in
unset)
test_unconfig "$1"
;;
*)
git config "$1" "$2"
key=$(echo $1 | sed -e 's/^remote\.origin/fetch/')
git_fetch_c="$git_fetch_c -c $key=$2"
;;
esac
}
test_configured_prune () {
test_configured_prune_type "$@" "name"
test_configured_prune_type "$@" "link"
}
test_configured_prune_type () {
fetch_prune=$1
remote_origin_prune=$2
fetch_prune_tags=$3
remote_origin_prune_tags=$4
expected_branch=$5
expected_tag=$6
cmdline=$7
mode=$8
if test -z "$cmdline_setup"
then
test_expect_success 'setup cmdline_setup variable for subsequent test' '
remote_url="file://$(git -C one config remote.origin.url)" &&
remote_fetch="$(git -C one config remote.origin.fetch)" &&
cmdline_setup="\"$remote_url\" \"$remote_fetch\""
'
fi
if test "$mode" = 'link'
then
new_cmdline=""
if test "$cmdline" = ""
then
new_cmdline=$cmdline_setup
else
new_cmdline=$(perl -e '
my ($cmdline, $url) = @ARGV;
$cmdline =~ s[origin(?!/)][quotemeta($url)]ge;
print $cmdline;
' -- "$cmdline" "$remote_url")
fi
if test "$fetch_prune_tags" = 'true' ||
test "$remote_origin_prune_tags" = 'true'
then
if ! printf '%s' "$cmdline\n" | grep -q refs/remotes/origin/
then
new_cmdline="$new_cmdline refs/tags/*:refs/tags/*"
fi
fi
cmdline="$new_cmdline"
fi
test_expect_success "$mode prune fetch.prune=$1 remote.origin.prune=$2 fetch.pruneTags=$3 remote.origin.pruneTags=$4${7:+ $7}; branch:$5 tag:$6" '
# make sure a newbranch is there in . and also in one
git branch -f newbranch &&
git tag -f newtag &&
(
cd one &&
test_unconfig fetch.prune &&
test_unconfig fetch.pruneTags &&
test_unconfig remote.origin.prune &&
test_unconfig remote.origin.pruneTags &&
git fetch '"$cmdline_setup"' &&
git rev-parse --verify refs/remotes/origin/newbranch &&
git rev-parse --verify refs/tags/newtag
) &&
# now remove them
git branch -d newbranch &&
git tag -d newtag &&
# then test
(
cd one &&
git_fetch_c="" &&
set_config_tristate fetch.prune $fetch_prune &&
set_config_tristate fetch.pruneTags $fetch_prune_tags &&
set_config_tristate remote.origin.prune $remote_origin_prune &&
set_config_tristate remote.origin.pruneTags $remote_origin_prune_tags &&
if test "$mode" != "link"
then
git_fetch_c=""
fi &&
git$git_fetch_c fetch '"$cmdline"' &&
case "$expected_branch" in
pruned)
test_must_fail git rev-parse --verify refs/remotes/origin/newbranch
;;
kept)
git rev-parse --verify refs/remotes/origin/newbranch
;;
esac &&
case "$expected_tag" in
pruned)
test_must_fail git rev-parse --verify refs/tags/newtag
;;
kept)
git rev-parse --verify refs/tags/newtag
;;
esac
)
'
}
# $1 config: fetch.prune
# $2 config: remote.<name>.prune
# $3 config: fetch.pruneTags
# $4 config: remote.<name>.pruneTags
# $5 expect: branch to be pruned?
# $6 expect: tag to be pruned?
# $7 git-fetch $cmdline:
#
# $1 $2 $3 $4 $5 $6 $7
test_configured_prune unset unset unset unset kept kept ""
test_configured_prune unset unset unset unset kept kept "--no-prune"
test_configured_prune unset unset unset unset pruned kept "--prune"
test_configured_prune unset unset unset unset kept pruned \
"--prune origin refs/tags/*:refs/tags/*"
test_configured_prune unset unset unset unset pruned pruned \
"--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
test_configured_prune false unset unset unset kept kept ""
test_configured_prune false unset unset unset kept kept "--no-prune"
test_configured_prune false unset unset unset pruned kept "--prune"
test_configured_prune true unset unset unset pruned kept ""
test_configured_prune true unset unset unset pruned kept "--prune"
test_configured_prune true unset unset unset kept kept "--no-prune"
test_configured_prune unset false unset unset kept kept ""
test_configured_prune unset false unset unset kept kept "--no-prune"
test_configured_prune unset false unset unset pruned kept "--prune"
test_configured_prune false false unset unset kept kept ""
test_configured_prune false false unset unset kept kept "--no-prune"
test_configured_prune false false unset unset pruned kept "--prune"
test_configured_prune false false unset unset kept pruned \
"--prune origin refs/tags/*:refs/tags/*"
test_configured_prune false false unset unset pruned pruned \
"--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
test_configured_prune true false unset unset kept kept ""
test_configured_prune true false unset unset pruned kept "--prune"
test_configured_prune true false unset unset kept kept "--no-prune"
test_configured_prune unset true unset unset pruned kept ""
test_configured_prune unset true unset unset kept kept "--no-prune"
test_configured_prune unset true unset unset pruned kept "--prune"
test_configured_prune false true unset unset pruned kept ""
test_configured_prune false true unset unset kept kept "--no-prune"
test_configured_prune false true unset unset pruned kept "--prune"
test_configured_prune true true unset unset pruned kept ""
test_configured_prune true true unset unset pruned kept "--prune"
test_configured_prune true true unset unset kept kept "--no-prune"
test_configured_prune true true unset unset kept pruned \
"--prune origin refs/tags/*:refs/tags/*"
test_configured_prune true true unset unset pruned pruned \
"--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
# --prune-tags on its own does nothing, needs --prune as well, same
# for fetch.pruneTags without fetch.prune
test_configured_prune unset unset unset unset kept kept "--prune-tags"
test_configured_prune unset unset true unset kept kept ""
test_configured_prune unset unset unset true kept kept ""
# These will prune the tags
test_configured_prune unset unset unset unset pruned pruned "--prune --prune-tags"
test_configured_prune true unset true unset pruned pruned ""
test_configured_prune unset true unset true pruned pruned ""
# remote.<name>.pruneTags overrides fetch.pruneTags, just like
# remote.<name>.prune overrides fetch.prune if set.
test_configured_prune true unset true unset pruned pruned ""
test_configured_prune false true false true pruned pruned ""
test_configured_prune true false true false kept kept ""
# When --prune-tags is supplied it's ignored if an explicit refspec is
# given, same for the configuration options.
test_configured_prune unset unset unset unset pruned kept \
"--prune --prune-tags origin +refs/heads/*:refs/remotes/origin/*"
test_configured_prune unset unset true unset pruned kept \
"--prune origin +refs/heads/*:refs/remotes/origin/*"
test_configured_prune unset unset unset true pruned kept \
"--prune origin +refs/heads/*:refs/remotes/origin/*"
# Pruning that also takes place if a file:// url replaces a named
# remote. However, because there's no implicit
# +refs/heads/*:refs/remotes/origin/* refspec and supplying it on the
# command-line negates --prune-tags, the branches will not be pruned.
test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "name"
test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "link"
test_configured_prune_type unset unset unset unset pruned pruned "origin --prune --prune-tags" "name"
test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "link"
test_configured_prune_type unset unset unset unset pruned pruned "--prune --prune-tags origin" "name"
test_configured_prune_type unset unset unset unset kept pruned "--prune --prune-tags origin" "link"
test_configured_prune_type unset unset true unset pruned pruned "--prune origin" "name"
test_configured_prune_type unset unset true unset kept pruned "--prune origin" "link"
test_configured_prune_type unset unset unset true pruned pruned "--prune origin" "name"
test_configured_prune_type unset unset unset true kept pruned "--prune origin" "link"
test_configured_prune_type true unset true unset pruned pruned "origin" "name"
test_configured_prune_type true unset true unset kept pruned "origin" "link"
test_configured_prune_type unset true true unset pruned pruned "origin" "name"
test_configured_prune_type unset true true unset kept pruned "origin" "link"
test_configured_prune_type unset true unset true pruned pruned "origin" "name"
test_configured_prune_type unset true unset true kept pruned "origin" "link"
# When all remote.origin.fetch settings are deleted a --prune
# --prune-tags still implicitly supplies refs/tags/*:refs/tags/* so
# tags, but not tracking branches, will be deleted.
test_expect_success 'remove remote.origin.fetch "one"' '
(
cd one &&
git config --unset-all remote.origin.fetch
)
'
test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "name"
test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "link"
test_expect_success 'all boundary commits are excluded' '
test_commit base &&
test_commit oneside &&
git checkout HEAD^ &&
test_commit otherside &&
git checkout main &&
test_tick &&
git merge otherside &&
ad=$(git log --no-walk --format=%ad HEAD) &&
# If the a different name hash function is used here, then no delta
# pair is found and the bundle does not expand to three objects
# when fixing the thin object.
GIT_TEST_NAME_HASH_VERSION=1 \
git bundle create twoside-boundary.bdl main --since="$ad" &&
test_bundle_object_count --thin twoside-boundary.bdl 3
'
test_expect_success 'fetch --prune prints the remotes url' '
git branch goodbye &&
git clone . only-prunes &&
git branch -D goodbye &&
(
cd only-prunes &&
git fetch --prune origin 2>&1 | head -n1 >../actual
) &&
echo "From ${D}/." >expect &&
test_cmp expect actual
'
test_expect_success 'branchname D/F conflict resolved by --prune' '
git branch dir/file &&
git clone . prune-df-conflict &&
git branch -D dir/file &&
git branch dir &&
(
cd prune-df-conflict &&
git fetch --prune &&
git rev-parse origin/dir >../actual
) &&
git rev-parse dir >expect &&
test_cmp expect actual
'
test_expect_success 'branchname D/F conflict rejected with targeted error message' '
git clone . df-conflict-error &&
git branch dir_conflict &&
(
cd df-conflict-error &&
git update-ref refs/remotes/origin/dir_conflict/file HEAD &&
test_must_fail git fetch 2>err &&
test_grep "error: some local refs could not be updated; try running" err &&
test_grep " ${SQ}git remote prune origin${SQ} to remove any old, conflicting branches" err &&
git pack-refs --all &&
test_must_fail git fetch 2>err-packed &&
test_grep "error: some local refs could not be updated; try running" err-packed &&
test_grep " ${SQ}git remote prune origin${SQ} to remove any old, conflicting branches" err-packed
)
'
test_expect_success 'fetching a one-level ref works' '
test_commit extra &&
git reset --hard HEAD^ &&
git update-ref refs/foo extra &&
git init one-level &&
(
cd one-level &&
git fetch .. HEAD refs/foo
)
'
test_expect_success 'fetching with auto-gc does not lock up' '
write_script askyesno <<-\EOF &&
echo "$*" &&
false
EOF
git clone "file://$D" auto-gc &&
test_commit test2 &&
(
cd auto-gc &&
git config fetch.unpackLimit 1 &&
git config gc.autoPackLimit 1 &&
git config gc.autoDetach false &&
GIT_ASK_YESNO="$D/askyesno" git fetch --verbose >fetch.out 2>&1 &&
test_grep "Auto packing the repository" fetch.out &&
! grep "Should I try again" fetch.out
)
'
for section in fetch transfer
do
test_expect_success "$section.hideRefs affects connectivity check" '
GIT_TRACE="$PWD"/trace git -c $section.hideRefs=refs -c \
$section.hideRefs="!refs/tags/" fetch &&
grep "git rev-list .*--exclude-hidden=fetch" trace
'
done
test_expect_success 'prepare source branch' '
echo one >onebranch &&
git checkout --orphan onebranch &&
git rm --cached -r . &&
git add onebranch &&
git commit -m onebranch &&
git rev-list --objects onebranch -- >actual &&
# 3 objects should be created, at least ...
test 3 -le $(wc -l <actual)
'
validate_store_type () {
git -C dest count-objects -v >actual &&
case "$store_type" in
packed)
grep "^count: 0$" actual ;;
loose)
grep "^packs: 0$" actual ;;
esac || {
echo "store_type is $store_type"
cat actual
false
}
}
test_unpack_limit () {
store_type=$1
case "$store_type" in
packed) fetch_limit=1 transfer_limit=10000 ;;
loose) fetch_limit=10000 transfer_limit=1 ;;
esac
test_expect_success "fetch trumps transfer limit" '
rm -fr dest &&
git --bare init dest &&
git -C dest config fetch.unpacklimit $fetch_limit &&
git -C dest config transfer.unpacklimit $transfer_limit &&
git -C dest fetch .. onebranch &&
validate_store_type
'
}
test_unpack_limit packed
test_unpack_limit loose
setup_negotiation_tip () {
SERVER="$1"
URL="$2"
USE_PROTOCOL_V2="$3"
rm -rf "$SERVER" client trace &&
git init -b main "$SERVER" &&
test_commit -C "$SERVER" alpha_1 &&
test_commit -C "$SERVER" alpha_2 &&
git -C "$SERVER" checkout --orphan beta &&
test_commit -C "$SERVER" beta_1 &&
test_commit -C "$SERVER" beta_2 &&
git clone "$URL" client &&
if test "$USE_PROTOCOL_V2" -eq 1
then
git -C "$SERVER" config protocol.version 2 &&
git -C client config protocol.version 2
fi &&
test_commit -C "$SERVER" beta_s &&
git -C "$SERVER" checkout main &&
test_commit -C "$SERVER" alpha_s &&
git -C "$SERVER" tag -d alpha_1 alpha_2 beta_1 beta_2
}
check_negotiation_tip () {
# Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2
ALPHA_1=$(git -C client rev-parse alpha_1) &&
grep "fetch> have $ALPHA_1" trace &&
BETA_1=$(git -C client rev-parse beta_1) &&
grep "fetch> have $BETA_1" trace &&
ALPHA_2=$(git -C client rev-parse alpha_2) &&
! grep "fetch> have $ALPHA_2" trace &&
BETA_2=$(git -C client rev-parse beta_2) &&
! grep "fetch> have $BETA_2" trace
}
test_expect_success '--negotiation-tip limits "have" lines sent' '
setup_negotiation_tip server server 0 &&
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
--negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
origin alpha_s beta_s &&
check_negotiation_tip
'
test_expect_success '--negotiation-tip understands globs' '
setup_negotiation_tip server server 0 &&
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
--negotiation-tip=*_1 \
origin alpha_s beta_s &&
check_negotiation_tip
'
test_expect_success '--negotiation-tip understands abbreviated SHA-1' '
setup_negotiation_tip server server 0 &&
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
--negotiation-tip=$(git -C client rev-parse --short alpha_1) \
--negotiation-tip=$(git -C client rev-parse --short beta_1) \
origin alpha_s beta_s &&
check_negotiation_tip
'
test_expect_success '--negotiation-tip rejects missing OIDs' '
setup_negotiation_tip server server 0 &&
test_must_fail git -C client fetch \
--negotiation-tip=alpha_1 \
--negotiation-tip=$(test_oid zero) \
origin alpha_s beta_s 2>err &&
cat >fatal-expect <<-EOF &&
fatal: the object $(test_oid zero) does not exist
EOF
grep fatal: err >fatal-actual &&
test_cmp fatal-expect fatal-actual
'
test_expect_success SYMLINKS 'clone does not get confused by a D/F conflict' '
git init df-conflict &&
(
cd df-conflict &&
ln -s .git a &&
git add a &&
test_tick &&
git commit -m symlink &&
test_commit a- &&
rm a &&
mkdir -p a/hooks &&
write_script a/hooks/post-checkout <<-EOF &&
echo WHOOPSIE >&2
echo whoopsie >"$TRASH_DIRECTORY"/whoops
EOF
git add a/hooks/post-checkout &&
test_tick &&
git commit -m post-checkout
) &&
git clone df-conflict clone 2>err &&
test_grep ! WHOOPS err &&
test_path_is_missing whoops
'
. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd
test_expect_success '--negotiation-tip limits "have" lines sent with HTTP protocol v2' '
setup_negotiation_tip "$HTTPD_DOCUMENT_ROOT_PATH/server" \
"$HTTPD_URL/smart/server" 1 &&
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
--negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
origin alpha_s beta_s &&
check_negotiation_tip
'
# DO NOT add non-httpd-specific tests here, because the last part of this
# test script is only executed when httpd is available and enabled.
test_done
|