| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test fetching bundles with --bundle-uri' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | . "$TEST_DIRECTORY"/lib-bundle.sh |
| 7 | |
| 8 | test_expect_success 'fail to clone from non-existent file' ' |
| 9 | test_when_finished rm -rf test && |
| 10 | git clone --bundle-uri="$(pwd)/does-not-exist" . test 2>err && |
| 11 | grep "failed to download bundle from URI" err |
| 12 | ' |
| 13 | |
| 14 | test_expect_success 'fail to clone from non-bundle file' ' |
| 15 | test_when_finished rm -rf test && |
| 16 | echo bogus >bogus && |
| 17 | git clone --bundle-uri="$(pwd)/bogus" . test 2>err && |
| 18 | grep "is not a bundle" err |
| 19 | ' |
| 20 | |
| 21 | test_expect_success 'create bundle' ' |
| 22 | git init clone-from && |
| 23 | ( |
| 24 | cd clone-from && |
| 25 | git checkout -b topic && |
| 26 | |
| 27 | test_commit A && |
| 28 | git bundle create A.bundle topic && |
| 29 | |
| 30 | test_commit B && |
| 31 | git bundle create B.bundle topic && |
| 32 | |
| 33 | # Create a bundle with reference pointing to non-existent object. |
| 34 | commit_a=$(git rev-parse A) && |
| 35 | commit_b=$(git rev-parse B) && |
| 36 | sed -e "/^$/q" -e "s/$commit_a /$commit_b /" \ |
| 37 | <A.bundle >bad-header.bundle && |
| 38 | convert_bundle_to_pack \ |
| 39 | <A.bundle >>bad-header.bundle && |
| 40 | |
| 41 | tree_b=$(git rev-parse B^{tree}) && |
| 42 | cat >data <<-EOF && |
| 43 | tree $tree_b |
| 44 | parent $commit_b |
| 45 | author A U Thor |
| 46 | committer A U Thor |
| 47 | |
| 48 | commit: this is a commit with bad emails |
| 49 | |
| 50 | EOF |
| 51 | bad_commit=$(git hash-object --literally -t commit -w --stdin <data) && |
| 52 | git branch bad $bad_commit && |
| 53 | git bundle create bad-object.bundle bad && |
| 54 | git update-ref -d refs/heads/bad |
| 55 | ) |
| 56 | ' |
| 57 | |
| 58 | test_expect_success 'clone with path bundle' ' |
| 59 | git clone --bundle-uri="clone-from/B.bundle" \ |
| 60 | clone-from clone-path && |
| 61 | git -C clone-path rev-parse refs/bundles/heads/topic >actual && |
| 62 | git -C clone-from rev-parse topic >expect && |
| 63 | test_cmp expect actual |
| 64 | ' |
| 65 | |
| 66 | test_expect_success 'clone with bundle that has bad header' ' |
| 67 | # Write bundle ref fails, but clone can still proceed. |
| 68 | git clone --bundle-uri="clone-from/bad-header.bundle" \ |
| 69 | clone-from clone-bad-header 2>err && |
| 70 | commit_b=$(git -C clone-from rev-parse B) && |
| 71 | test_grep "trying to write ref '\''refs/bundles/heads/topic'\'' with nonexistent object $commit_b" err && |
| 72 | git -C clone-bad-header for-each-ref --format="%(refname)" >refs && |
| 73 | test_grep ! "refs/bundles/heads/" refs |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'clone with bundle that has bad object' ' |
| 77 | # Unbundle succeeds if no fsckObjects configured. |
| 78 | git clone --bundle-uri="clone-from/bad-object.bundle" \ |
| 79 | clone-from clone-bad-object-no-fsck && |
| 80 | git -C clone-bad-object-no-fsck for-each-ref --format="%(refname)" >refs && |
| 81 | grep "refs/bundles/heads/" refs >actual && |
| 82 | test_write_lines refs/bundles/heads/bad >expect && |
| 83 | test_cmp expect actual && |
| 84 | |
| 85 | # Unbundle fails with fsckObjects set true, but clone can still proceed. |
| 86 | git -c fetch.fsckObjects=true clone --bundle-uri="clone-from/bad-object.bundle" \ |
| 87 | clone-from clone-bad-object-fsck 2>err && |
| 88 | test_grep "missingEmail" err && |
| 89 | git -C clone-bad-object-fsck for-each-ref --format="%(refname)" >refs && |
| 90 | test_grep ! "refs/bundles/heads/" refs |
| 91 | ' |
| 92 | |
| 93 | test_expect_success 'clone with path bundle and non-default hash' ' |
| 94 | test_when_finished "rm -rf clone-path-non-default-hash" && |
| 95 | GIT_DEFAULT_HASH=sha256 git clone --bundle-uri="clone-from/B.bundle" \ |
| 96 | clone-from clone-path-non-default-hash && |
| 97 | git -C clone-path-non-default-hash rev-parse refs/bundles/heads/topic >actual && |
| 98 | git -C clone-from rev-parse topic >expect && |
| 99 | test_cmp expect actual |
| 100 | ' |
| 101 | |
| 102 | test_expect_success 'clone with file:// bundle' ' |
| 103 | git clone --bundle-uri="file://$(pwd)/clone-from/B.bundle" \ |
| 104 | clone-from clone-file && |
| 105 | git -C clone-file rev-parse refs/bundles/heads/topic >actual && |
| 106 | git -C clone-from rev-parse topic >expect && |
| 107 | test_cmp expect actual |
| 108 | ' |
| 109 | |
| 110 | test_expect_success 'create bundle with tags' ' |
| 111 | git init clone-from-tags && |
| 112 | ( |
| 113 | cd clone-from-tags && |
| 114 | git checkout -b base && |
| 115 | git checkout -b topic && |
| 116 | |
| 117 | test_commit A && |
| 118 | git tag tag-A && |
| 119 | git checkout -b base && |
| 120 | git branch -d topic && |
| 121 | test_commit B && |
| 122 | |
| 123 | git bundle create ALL.bundle --all && |
| 124 | git bundle verify ALL.bundle |
| 125 | ) |
| 126 | ' |
| 127 | |
| 128 | test_expect_success 'clone with tags bundle' ' |
| 129 | git clone --bundle-uri="clone-from-tags/ALL.bundle" \ |
| 130 | clone-from-tags clone-tags-path && |
| 131 | |
| 132 | git -C clone-from-tags for-each-ref --format="%(refname:lstrip=1)" \ |
| 133 | >expect && |
| 134 | git -C clone-tags-path for-each-ref --format="%(refname:lstrip=2)" \ |
| 135 | refs/bundles >actual && |
| 136 | |
| 137 | test_cmp expect actual |
| 138 | ' |
| 139 | |
| 140 | # To get interesting tests for bundle lists, we need to construct a |
| 141 | # somewhat-interesting commit history. |
| 142 | # |
| 143 | # ---------------- bundle-4 |
| 144 | # |
| 145 | # 4 |
| 146 | # / \ |
| 147 | # ----|---|------- bundle-3 |
| 148 | # | | |
| 149 | # | 3 |
| 150 | # | | |
| 151 | # ----|---|------- bundle-2 |
| 152 | # | | |
| 153 | # 2 | |
| 154 | # | | |
| 155 | # ----|---|------- bundle-1 |
| 156 | # \ / |
| 157 | # 1 |
| 158 | # | |
| 159 | # (previous commits) |
| 160 | test_expect_success 'construct incremental bundle list' ' |
| 161 | ( |
| 162 | cd clone-from && |
| 163 | git checkout -b base && |
| 164 | test_commit 1 && |
| 165 | git checkout -b left && |
| 166 | test_commit 2 && |
| 167 | git checkout -b right base && |
| 168 | test_commit 3 && |
| 169 | git checkout -b merge left && |
| 170 | git merge right -m "4" && |
| 171 | |
| 172 | git bundle create bundle-1.bundle base && |
| 173 | git bundle create bundle-2.bundle base..left && |
| 174 | git bundle create bundle-3.bundle base..right && |
| 175 | git bundle create bundle-4.bundle merge --not left right |
| 176 | ) |
| 177 | ' |
| 178 | |
| 179 | test_expect_success 'clone bundle list (file, no heuristic)' ' |
| 180 | cat >bundle-list <<-EOF && |
| 181 | [bundle] |
| 182 | version = 1 |
| 183 | mode = all |
| 184 | |
| 185 | [bundle "bundle-1"] |
| 186 | uri = file://$(pwd)/clone-from/bundle-1.bundle |
| 187 | |
| 188 | [bundle "bundle-2"] |
| 189 | uri = file://$(pwd)/clone-from/bundle-2.bundle |
| 190 | |
| 191 | [bundle "bundle-3"] |
| 192 | uri = file://$(pwd)/clone-from/bundle-3.bundle |
| 193 | |
| 194 | [bundle "bundle-4"] |
| 195 | uri = file://$(pwd)/clone-from/bundle-4.bundle |
| 196 | EOF |
| 197 | |
| 198 | git clone --bundle-uri="file://$(pwd)/bundle-list" \ |
| 199 | clone-from clone-list-file 2>err && |
| 200 | ! grep "Repository lacks these prerequisite commits" err && |
| 201 | |
| 202 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
| 203 | git -C clone-list-file cat-file --batch-check <oids && |
| 204 | |
| 205 | git -C clone-list-file for-each-ref --format="%(refname)" >refs && |
| 206 | grep "refs/bundles/heads/" refs >actual && |
| 207 | cat >expect <<-\EOF && |
| 208 | refs/bundles/heads/base |
| 209 | refs/bundles/heads/left |
| 210 | refs/bundles/heads/merge |
| 211 | refs/bundles/heads/right |
| 212 | EOF |
| 213 | test_cmp expect actual |
| 214 | ' |
| 215 | |
| 216 | test_expect_success 'clone bundle list (file, all mode, some failures)' ' |
| 217 | cat >bundle-list <<-EOF && |
| 218 | [bundle] |
| 219 | version = 1 |
| 220 | mode = all |
| 221 | |
| 222 | # Does not exist. Should be skipped. |
| 223 | [bundle "bundle-0"] |
| 224 | uri = file://$(pwd)/clone-from/bundle-0.bundle |
| 225 | |
| 226 | [bundle "bundle-1"] |
| 227 | uri = file://$(pwd)/clone-from/bundle-1.bundle |
| 228 | |
| 229 | [bundle "bundle-2"] |
| 230 | uri = file://$(pwd)/clone-from/bundle-2.bundle |
| 231 | |
| 232 | # No bundle-3 means bundle-4 will not apply. |
| 233 | |
| 234 | [bundle "bundle-4"] |
| 235 | uri = file://$(pwd)/clone-from/bundle-4.bundle |
| 236 | |
| 237 | # Does not exist. Should be skipped. |
| 238 | [bundle "bundle-5"] |
| 239 | uri = file://$(pwd)/clone-from/bundle-5.bundle |
| 240 | EOF |
| 241 | |
| 242 | GIT_TRACE2_PERF=1 \ |
| 243 | git clone --bundle-uri="file://$(pwd)/bundle-list" \ |
| 244 | clone-from clone-all-some 2>err && |
| 245 | ! grep "Repository lacks these prerequisite commits" err && |
| 246 | ! grep "fatal" err && |
| 247 | grep "warning: failed to download bundle from URI" err && |
| 248 | |
| 249 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
| 250 | git -C clone-all-some cat-file --batch-check <oids && |
| 251 | |
| 252 | git -C clone-all-some for-each-ref --format="%(refname)" >refs && |
| 253 | grep "refs/bundles/heads/" refs >actual && |
| 254 | cat >expect <<-\EOF && |
| 255 | refs/bundles/heads/base |
| 256 | refs/bundles/heads/left |
| 257 | EOF |
| 258 | test_cmp expect actual |
| 259 | ' |
| 260 | |
| 261 | test_expect_success 'clone bundle list (file, all mode, all failures)' ' |
| 262 | cat >bundle-list <<-EOF && |
| 263 | [bundle] |
| 264 | version = 1 |
| 265 | mode = all |
| 266 | |
| 267 | # Does not exist. Should be skipped. |
| 268 | [bundle "bundle-0"] |
| 269 | uri = file://$(pwd)/clone-from/bundle-0.bundle |
| 270 | |
| 271 | # Does not exist. Should be skipped. |
| 272 | [bundle "bundle-5"] |
| 273 | uri = file://$(pwd)/clone-from/bundle-5.bundle |
| 274 | EOF |
| 275 | |
| 276 | git clone --bundle-uri="file://$(pwd)/bundle-list" \ |
| 277 | clone-from clone-all-fail 2>err && |
| 278 | ! grep "Repository lacks these prerequisite commits" err && |
| 279 | ! grep "fatal" err && |
| 280 | grep "warning: failed to download bundle from URI" err && |
| 281 | |
| 282 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
| 283 | git -C clone-all-fail cat-file --batch-check <oids && |
| 284 | |
| 285 | git -C clone-all-fail for-each-ref --format="%(refname)" >refs && |
| 286 | ! grep "refs/bundles/heads/" refs |
| 287 | ' |
| 288 | |
| 289 | test_expect_success 'clone bundle list (file, any mode)' ' |
| 290 | cat >bundle-list <<-EOF && |
| 291 | [bundle] |
| 292 | version = 1 |
| 293 | mode = any |
| 294 | |
| 295 | # Does not exist. Should be skipped. |
| 296 | [bundle "bundle-0"] |
| 297 | uri = file://$(pwd)/clone-from/bundle-0.bundle |
| 298 | |
| 299 | [bundle "bundle-1"] |
| 300 | uri = file://$(pwd)/clone-from/bundle-1.bundle |
| 301 | |
| 302 | # Does not exist. Should be skipped. |
| 303 | [bundle "bundle-5"] |
| 304 | uri = file://$(pwd)/clone-from/bundle-5.bundle |
| 305 | EOF |
| 306 | |
| 307 | git clone --bundle-uri="file://$(pwd)/bundle-list" \ |
| 308 | clone-from clone-any-file 2>err && |
| 309 | ! grep "Repository lacks these prerequisite commits" err && |
| 310 | |
| 311 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
| 312 | git -C clone-any-file cat-file --batch-check <oids && |
| 313 | |
| 314 | git -C clone-any-file for-each-ref --format="%(refname)" >refs && |
| 315 | grep "refs/bundles/heads/" refs >actual && |
| 316 | cat >expect <<-\EOF && |
| 317 | refs/bundles/heads/base |
| 318 | EOF |
| 319 | test_cmp expect actual |
| 320 | ' |
| 321 | |
| 322 | test_expect_success 'clone bundle list (file, any mode, all failures)' ' |
| 323 | cat >bundle-list <<-EOF && |
| 324 | [bundle] |
| 325 | version = 1 |
| 326 | mode = any |
| 327 | |
| 328 | # Does not exist. Should be skipped. |
| 329 | [bundle "bundle-0"] |
| 330 | uri = $HTTPD_URL/bundle-0.bundle |
| 331 | |
| 332 | # Does not exist. Should be skipped. |
| 333 | [bundle "bundle-5"] |
| 334 | uri = $HTTPD_URL/bundle-5.bundle |
| 335 | EOF |
| 336 | |
| 337 | git clone --bundle-uri="file://$(pwd)/bundle-list" \ |
| 338 | clone-from clone-any-fail 2>err && |
| 339 | ! grep "fatal" err && |
| 340 | grep "warning: failed to download bundle from URI" err && |
| 341 | |
| 342 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
| 343 | git -C clone-any-fail cat-file --batch-check <oids && |
| 344 | |
| 345 | git -C clone-any-fail for-each-ref --format="%(refname)" >refs && |
| 346 | ! grep "refs/bundles/heads/" refs |
| 347 | ' |
| 348 | |
| 349 | test_expect_success 'negotiation: bundle with part of wanted commits' ' |
| 350 | test_when_finished "rm -f trace*.txt" && |
| 351 | GIT_TRACE_PACKET="$(pwd)/trace-packet.txt" \ |
| 352 | git clone --no-local --bundle-uri="clone-from/A.bundle" \ |
| 353 | clone-from nego-bundle-part && |
| 354 | git -C nego-bundle-part for-each-ref --format="%(refname)" >refs && |
| 355 | grep "refs/bundles/heads/" refs >actual && |
| 356 | test_write_lines refs/bundles/heads/topic >expect && |
| 357 | test_cmp expect actual && |
| 358 | # Ensure that refs/bundles/heads/topic are sent as "have". |
| 359 | tip=$(git -C clone-from rev-parse A) && |
| 360 | test_grep "clone> have $tip" trace-packet.txt |
| 361 | ' |
| 362 | |
| 363 | test_expect_success 'negotiation: bundle with all wanted commits' ' |
| 364 | test_when_finished "rm -f trace*.txt" && |
| 365 | GIT_TRACE_PACKET="$(pwd)/trace-packet.txt" \ |
| 366 | git clone --no-local --single-branch --branch=topic --no-tags \ |
| 367 | --bundle-uri="clone-from/B.bundle" \ |
| 368 | clone-from nego-bundle-all && |
| 369 | git -C nego-bundle-all for-each-ref --format="%(refname)" >refs && |
| 370 | grep "refs/bundles/heads/" refs >actual && |
| 371 | test_write_lines refs/bundles/heads/topic >expect && |
| 372 | test_cmp expect actual && |
| 373 | # We already have all needed commits so no "want" needed. |
| 374 | test_grep ! "clone> want " trace-packet.txt |
| 375 | ' |
| 376 | |
| 377 | test_expect_success 'negotiation: bundle list (no heuristic)' ' |
| 378 | test_when_finished "rm -f trace*.txt" && |
| 379 | cat >bundle-list <<-EOF && |
| 380 | [bundle] |
| 381 | version = 1 |
| 382 | mode = all |
| 383 | |
| 384 | [bundle "bundle-1"] |
| 385 | uri = file://$(pwd)/clone-from/bundle-1.bundle |
| 386 | |
| 387 | [bundle "bundle-2"] |
| 388 | uri = file://$(pwd)/clone-from/bundle-2.bundle |
| 389 | EOF |
| 390 | |
| 391 | GIT_TRACE_PACKET="$(pwd)/trace-packet.txt" \ |
| 392 | git clone --no-local --bundle-uri="file://$(pwd)/bundle-list" \ |
| 393 | clone-from nego-bundle-list-no-heuristic && |
| 394 | |
| 395 | git -C nego-bundle-list-no-heuristic for-each-ref --format="%(refname)" >refs && |
| 396 | grep "refs/bundles/heads/" refs >actual && |
| 397 | cat >expect <<-\EOF && |
| 398 | refs/bundles/heads/base |
| 399 | refs/bundles/heads/left |
| 400 | EOF |
| 401 | test_cmp expect actual && |
| 402 | tip=$(git -C nego-bundle-list-no-heuristic rev-parse refs/bundles/heads/left) && |
| 403 | test_grep "clone> have $tip" trace-packet.txt |
| 404 | ' |
| 405 | |
| 406 | test_expect_success 'negotiation: bundle list (creationToken)' ' |
| 407 | test_when_finished "rm -f trace*.txt" && |
| 408 | cat >bundle-list <<-EOF && |
| 409 | [bundle] |
| 410 | version = 1 |
| 411 | mode = all |
| 412 | heuristic = creationToken |
| 413 | |
| 414 | [bundle "bundle-1"] |
| 415 | uri = file://$(pwd)/clone-from/bundle-1.bundle |
| 416 | creationToken = 1 |
| 417 | |
| 418 | [bundle "bundle-2"] |
| 419 | uri = file://$(pwd)/clone-from/bundle-2.bundle |
| 420 | creationToken = 2 |
| 421 | EOF |
| 422 | |
| 423 | GIT_TRACE_PACKET="$(pwd)/trace-packet.txt" \ |
| 424 | git clone --no-local --bundle-uri="file://$(pwd)/bundle-list" \ |
| 425 | clone-from nego-bundle-list-heuristic && |
| 426 | |
| 427 | git -C nego-bundle-list-heuristic for-each-ref --format="%(refname)" >refs && |
| 428 | grep "refs/bundles/heads/" refs >actual && |
| 429 | cat >expect <<-\EOF && |
| 430 | refs/bundles/heads/base |
| 431 | refs/bundles/heads/left |
| 432 | EOF |
| 433 | test_cmp expect actual && |
| 434 | tip=$(git -C nego-bundle-list-heuristic rev-parse refs/bundles/heads/left) && |
| 435 | test_grep "clone> have $tip" trace-packet.txt |
| 436 | ' |
| 437 | |
| 438 | test_expect_success 'negotiation: bundle list with all wanted commits' ' |
| 439 | test_when_finished "rm -f trace*.txt" && |
| 440 | cat >bundle-list <<-EOF && |
| 441 | [bundle] |
| 442 | version = 1 |
| 443 | mode = all |
| 444 | heuristic = creationToken |
| 445 | |
| 446 | [bundle "bundle-1"] |
| 447 | uri = file://$(pwd)/clone-from/bundle-1.bundle |
| 448 | creationToken = 1 |
| 449 | |
| 450 | [bundle "bundle-2"] |
| 451 | uri = file://$(pwd)/clone-from/bundle-2.bundle |
| 452 | creationToken = 2 |
| 453 | EOF |
| 454 | |
| 455 | GIT_TRACE_PACKET="$(pwd)/trace-packet.txt" \ |
| 456 | git clone --no-local --single-branch --branch=left --no-tags \ |
| 457 | --bundle-uri="file://$(pwd)/bundle-list" \ |
| 458 | clone-from nego-bundle-list-all && |
| 459 | |
| 460 | git -C nego-bundle-list-all for-each-ref --format="%(refname)" >refs && |
| 461 | grep "refs/bundles/heads/" refs >actual && |
| 462 | cat >expect <<-\EOF && |
| 463 | refs/bundles/heads/base |
| 464 | refs/bundles/heads/left |
| 465 | EOF |
| 466 | test_cmp expect actual && |
| 467 | # We already have all needed commits so no "want" needed. |
| 468 | test_grep ! "clone> want " trace-packet.txt |
| 469 | ' |
| 470 | |
| 471 | ######################################################################### |
| 472 | # HTTP tests begin here |
| 473 | |
| 474 | . "$TEST_DIRECTORY"/lib-httpd.sh |
| 475 | start_httpd |
| 476 | |
| 477 | test_expect_success 'fail to fetch from non-existent HTTP URL' ' |
| 478 | test_when_finished rm -rf test && |
| 479 | git clone --bundle-uri="$HTTPD_URL/does-not-exist" . test 2>err && |
| 480 | grep "failed to download bundle from URI" err |
| 481 | ' |
| 482 | |
| 483 | test_expect_success 'fail to fetch from non-bundle HTTP URL' ' |
| 484 | test_when_finished rm -rf test && |
| 485 | echo bogus >"$HTTPD_DOCUMENT_ROOT_PATH/bogus" && |
| 486 | git clone --bundle-uri="$HTTPD_URL/bogus" . test 2>err && |
| 487 | grep "is not a bundle" err |
| 488 | ' |
| 489 | |
| 490 | test_expect_success 'clone HTTP bundle' ' |
| 491 | cp clone-from/B.bundle "$HTTPD_DOCUMENT_ROOT_PATH/B.bundle" && |
| 492 | |
| 493 | git clone --no-local --mirror clone-from \ |
| 494 | "$HTTPD_DOCUMENT_ROOT_PATH/fetch.git" && |
| 495 | |
| 496 | git clone --bundle-uri="$HTTPD_URL/B.bundle" \ |
| 497 | "$HTTPD_URL/smart/fetch.git" clone-http && |
| 498 | git -C clone-http rev-parse refs/bundles/heads/topic >actual && |
| 499 | git -C clone-from rev-parse topic >expect && |
| 500 | test_cmp expect actual && |
| 501 | |
| 502 | test_config -C clone-http log.excludedecoration refs/bundle/ |
| 503 | ' |
| 504 | |
| 505 | test_expect_success 'clone HTTP bundle with non-default hash' ' |
| 506 | test_when_finished "rm -rf clone-http-non-default-hash" && |
| 507 | GIT_DEFAULT_HASH=sha256 git clone --bundle-uri="$HTTPD_URL/B.bundle" \ |
| 508 | "$HTTPD_URL/smart/fetch.git" clone-http-non-default-hash && |
| 509 | git -C clone-http-non-default-hash rev-parse refs/bundles/heads/topic >actual && |
| 510 | git -C clone-from rev-parse topic >expect && |
| 511 | test_cmp expect actual |
| 512 | ' |
| 513 | |
| 514 | test_expect_success 'clone bundle list (HTTP, no heuristic)' ' |
| 515 | test_when_finished rm -f trace*.txt && |
| 516 | |
| 517 | cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" && |
| 518 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 519 | [bundle] |
| 520 | version = 1 |
| 521 | mode = all |
| 522 | |
| 523 | [bundle "bundle-1"] |
| 524 | uri = $HTTPD_URL/bundle-1.bundle |
| 525 | |
| 526 | [bundle "bundle-2"] |
| 527 | uri = $HTTPD_URL/bundle-2.bundle |
| 528 | |
| 529 | [bundle "bundle-3"] |
| 530 | uri = $HTTPD_URL/bundle-3.bundle |
| 531 | |
| 532 | [bundle "bundle-4"] |
| 533 | uri = $HTTPD_URL/bundle-4.bundle |
| 534 | EOF |
| 535 | |
| 536 | GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \ |
| 537 | git clone --bundle-uri="$HTTPD_URL/bundle-list" \ |
| 538 | clone-from clone-list-http 2>err && |
| 539 | ! grep "Repository lacks these prerequisite commits" err && |
| 540 | |
| 541 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
| 542 | git -C clone-list-http cat-file --batch-check <oids && |
| 543 | |
| 544 | cat >expect <<-EOF && |
| 545 | $HTTPD_URL/bundle-1.bundle |
| 546 | $HTTPD_URL/bundle-2.bundle |
| 547 | $HTTPD_URL/bundle-3.bundle |
| 548 | $HTTPD_URL/bundle-4.bundle |
| 549 | $HTTPD_URL/bundle-list |
| 550 | EOF |
| 551 | |
| 552 | # Sort the list, since the order is not well-defined |
| 553 | # without a heuristic. |
| 554 | test_remote_https_urls <trace-clone.txt | sort >actual && |
| 555 | test_cmp expect actual |
| 556 | ' |
| 557 | |
| 558 | test_expect_success 'clone bundle list (HTTP, any mode)' ' |
| 559 | cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" && |
| 560 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 561 | [bundle] |
| 562 | version = 1 |
| 563 | mode = any |
| 564 | |
| 565 | # Does not exist. Should be skipped. |
| 566 | [bundle "bundle-0"] |
| 567 | uri = $HTTPD_URL/bundle-0.bundle |
| 568 | |
| 569 | [bundle "bundle-1"] |
| 570 | uri = $HTTPD_URL/bundle-1.bundle |
| 571 | |
| 572 | # Does not exist. Should be skipped. |
| 573 | [bundle "bundle-5"] |
| 574 | uri = $HTTPD_URL/bundle-5.bundle |
| 575 | EOF |
| 576 | |
| 577 | git clone --bundle-uri="$HTTPD_URL/bundle-list" \ |
| 578 | clone-from clone-any-http 2>err && |
| 579 | ! grep "fatal" err && |
| 580 | grep "warning: failed to download bundle from URI" err && |
| 581 | |
| 582 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
| 583 | git -C clone-any-http cat-file --batch-check <oids && |
| 584 | |
| 585 | git -C clone-list-file for-each-ref --format="%(refname)" >refs && |
| 586 | grep "refs/bundles/heads/" refs >actual && |
| 587 | cat >expect <<-\EOF && |
| 588 | refs/bundles/heads/base |
| 589 | refs/bundles/heads/left |
| 590 | refs/bundles/heads/merge |
| 591 | refs/bundles/heads/right |
| 592 | EOF |
| 593 | test_cmp expect actual |
| 594 | ' |
| 595 | |
| 596 | test_expect_success 'clone bundle list (http, creationToken)' ' |
| 597 | test_when_finished rm -f trace*.txt && |
| 598 | |
| 599 | cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" && |
| 600 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 601 | [bundle] |
| 602 | version = 1 |
| 603 | mode = all |
| 604 | heuristic = creationToken |
| 605 | |
| 606 | [bundle "bundle-1"] |
| 607 | uri = bundle-1.bundle |
| 608 | creationToken = 1 |
| 609 | |
| 610 | [bundle "bundle-2"] |
| 611 | uri = bundle-2.bundle |
| 612 | creationToken = 2 |
| 613 | |
| 614 | [bundle "bundle-3"] |
| 615 | uri = bundle-3.bundle |
| 616 | creationToken = 3 |
| 617 | |
| 618 | [bundle "bundle-4"] |
| 619 | uri = bundle-4.bundle |
| 620 | creationToken = 4 |
| 621 | EOF |
| 622 | |
| 623 | GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" git \ |
| 624 | clone --bundle-uri="$HTTPD_URL/bundle-list" \ |
| 625 | "$HTTPD_URL/smart/fetch.git" clone-list-http-2 && |
| 626 | |
| 627 | git -C clone-from for-each-ref --format="%(objectname)" >oids && |
| 628 | git -C clone-list-http-2 cat-file --batch-check <oids && |
| 629 | |
| 630 | cat >expect <<-EOF && |
| 631 | $HTTPD_URL/bundle-list |
| 632 | $HTTPD_URL/bundle-4.bundle |
| 633 | $HTTPD_URL/bundle-3.bundle |
| 634 | $HTTPD_URL/bundle-2.bundle |
| 635 | $HTTPD_URL/bundle-1.bundle |
| 636 | EOF |
| 637 | |
| 638 | test_remote_https_urls <trace-clone.txt >actual && |
| 639 | test_cmp expect actual |
| 640 | ' |
| 641 | |
| 642 | test_expect_success 'clone incomplete bundle list (http, creationToken)' ' |
| 643 | test_when_finished rm -f trace*.txt && |
| 644 | |
| 645 | cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" && |
| 646 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 647 | [bundle] |
| 648 | version = 1 |
| 649 | mode = all |
| 650 | heuristic = creationToken |
| 651 | |
| 652 | [bundle "bundle-1"] |
| 653 | uri = bundle-1.bundle |
| 654 | creationToken = 1 |
| 655 | EOF |
| 656 | |
| 657 | GIT_TRACE2_EVENT=$(pwd)/trace-clone.txt \ |
| 658 | git clone --bundle-uri="$HTTPD_URL/bundle-list" \ |
| 659 | --single-branch --branch=base --no-tags \ |
| 660 | "$HTTPD_URL/smart/fetch.git" clone-token-http && |
| 661 | |
| 662 | test_cmp_config -C clone-token-http "$HTTPD_URL/bundle-list" fetch.bundleuri && |
| 663 | test_cmp_config -C clone-token-http 1 fetch.bundlecreationtoken && |
| 664 | |
| 665 | cat >expect <<-EOF && |
| 666 | $HTTPD_URL/bundle-list |
| 667 | $HTTPD_URL/bundle-1.bundle |
| 668 | EOF |
| 669 | |
| 670 | test_remote_https_urls <trace-clone.txt >actual && |
| 671 | test_cmp expect actual && |
| 672 | |
| 673 | # We now have only one bundle ref. |
| 674 | git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs && |
| 675 | cat >expect <<-\EOF && |
| 676 | refs/bundles/heads/base |
| 677 | EOF |
| 678 | test_cmp expect refs && |
| 679 | |
| 680 | # Add remaining bundles, exercising the "deepening" strategy |
| 681 | # for downloading via the creationToken heurisitc. |
| 682 | cat >>"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 683 | [bundle "bundle-2"] |
| 684 | uri = bundle-2.bundle |
| 685 | creationToken = 2 |
| 686 | |
| 687 | [bundle "bundle-3"] |
| 688 | uri = bundle-3.bundle |
| 689 | creationToken = 3 |
| 690 | |
| 691 | [bundle "bundle-4"] |
| 692 | uri = bundle-4.bundle |
| 693 | creationToken = 4 |
| 694 | EOF |
| 695 | |
| 696 | GIT_TRACE2_EVENT="$(pwd)/trace1.txt" \ |
| 697 | git -C clone-token-http fetch origin --no-tags \ |
| 698 | refs/heads/merge:refs/heads/merge && |
| 699 | test_cmp_config -C clone-token-http 4 fetch.bundlecreationtoken && |
| 700 | |
| 701 | cat >expect <<-EOF && |
| 702 | $HTTPD_URL/bundle-list |
| 703 | $HTTPD_URL/bundle-4.bundle |
| 704 | $HTTPD_URL/bundle-3.bundle |
| 705 | $HTTPD_URL/bundle-2.bundle |
| 706 | EOF |
| 707 | |
| 708 | test_remote_https_urls <trace1.txt >actual && |
| 709 | test_cmp expect actual && |
| 710 | |
| 711 | # We now have all bundle refs. |
| 712 | git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs && |
| 713 | |
| 714 | cat >expect <<-\EOF && |
| 715 | refs/bundles/heads/base |
| 716 | refs/bundles/heads/left |
| 717 | refs/bundles/heads/merge |
| 718 | refs/bundles/heads/right |
| 719 | EOF |
| 720 | test_cmp expect refs |
| 721 | ' |
| 722 | |
| 723 | test_expect_success 'http clone with bundle.heuristic creates fetch.bundleURI' ' |
| 724 | test_when_finished rm -rf fetch-http-4 trace*.txt && |
| 725 | |
| 726 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 727 | [bundle] |
| 728 | version = 1 |
| 729 | mode = all |
| 730 | heuristic = creationToken |
| 731 | |
| 732 | [bundle "bundle-1"] |
| 733 | uri = bundle-1.bundle |
| 734 | creationToken = 1 |
| 735 | EOF |
| 736 | |
| 737 | GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \ |
| 738 | git clone --single-branch --branch=base \ |
| 739 | --bundle-uri="$HTTPD_URL/bundle-list" \ |
| 740 | "$HTTPD_URL/smart/fetch.git" fetch-http-4 && |
| 741 | |
| 742 | test_cmp_config -C fetch-http-4 "$HTTPD_URL/bundle-list" fetch.bundleuri && |
| 743 | test_cmp_config -C fetch-http-4 1 fetch.bundlecreationtoken && |
| 744 | |
| 745 | cat >expect <<-EOF && |
| 746 | $HTTPD_URL/bundle-list |
| 747 | $HTTPD_URL/bundle-1.bundle |
| 748 | EOF |
| 749 | |
| 750 | test_remote_https_urls <trace-clone.txt >actual && |
| 751 | test_cmp expect actual && |
| 752 | |
| 753 | # only received base ref from bundle-1 |
| 754 | git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs && |
| 755 | cat >expect <<-\EOF && |
| 756 | refs/bundles/heads/base |
| 757 | EOF |
| 758 | test_cmp expect refs && |
| 759 | |
| 760 | cat >>"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 761 | [bundle "bundle-2"] |
| 762 | uri = bundle-2.bundle |
| 763 | creationToken = 2 |
| 764 | EOF |
| 765 | |
| 766 | # Fetch the objects for bundle-2 _and_ bundle-3. |
| 767 | GIT_TRACE2_EVENT="$(pwd)/trace1.txt" \ |
| 768 | git -C fetch-http-4 fetch origin --no-tags \ |
| 769 | refs/heads/left:refs/heads/left \ |
| 770 | refs/heads/right:refs/heads/right && |
| 771 | test_cmp_config -C fetch-http-4 2 fetch.bundlecreationtoken && |
| 772 | |
| 773 | cat >expect <<-EOF && |
| 774 | $HTTPD_URL/bundle-list |
| 775 | $HTTPD_URL/bundle-2.bundle |
| 776 | EOF |
| 777 | |
| 778 | test_remote_https_urls <trace1.txt >actual && |
| 779 | test_cmp expect actual && |
| 780 | |
| 781 | # received left from bundle-2 |
| 782 | git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs && |
| 783 | cat >expect <<-\EOF && |
| 784 | refs/bundles/heads/base |
| 785 | refs/bundles/heads/left |
| 786 | EOF |
| 787 | test_cmp expect refs && |
| 788 | |
| 789 | # No-op fetch |
| 790 | GIT_TRACE2_EVENT="$(pwd)/trace1b.txt" \ |
| 791 | git -C fetch-http-4 fetch origin --no-tags \ |
| 792 | refs/heads/left:refs/heads/left \ |
| 793 | refs/heads/right:refs/heads/right && |
| 794 | |
| 795 | cat >expect <<-EOF && |
| 796 | $HTTPD_URL/bundle-list |
| 797 | EOF |
| 798 | test_remote_https_urls <trace1b.txt >actual && |
| 799 | test_cmp expect actual && |
| 800 | |
| 801 | cat >>"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 802 | [bundle "bundle-3"] |
| 803 | uri = bundle-3.bundle |
| 804 | creationToken = 3 |
| 805 | |
| 806 | [bundle "bundle-4"] |
| 807 | uri = bundle-4.bundle |
| 808 | creationToken = 4 |
| 809 | EOF |
| 810 | |
| 811 | # This fetch should skip bundle-3.bundle, since its objects are |
| 812 | # already local (we have the requisite commits for bundle-4.bundle). |
| 813 | GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \ |
| 814 | git -C fetch-http-4 fetch origin --no-tags \ |
| 815 | refs/heads/merge:refs/heads/merge && |
| 816 | test_cmp_config -C fetch-http-4 4 fetch.bundlecreationtoken && |
| 817 | |
| 818 | cat >expect <<-EOF && |
| 819 | $HTTPD_URL/bundle-list |
| 820 | $HTTPD_URL/bundle-4.bundle |
| 821 | EOF |
| 822 | |
| 823 | test_remote_https_urls <trace2.txt >actual && |
| 824 | test_cmp expect actual && |
| 825 | |
| 826 | # received merge ref from bundle-4, but right is missing |
| 827 | # because we did not download bundle-3. |
| 828 | git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs && |
| 829 | |
| 830 | cat >expect <<-\EOF && |
| 831 | refs/bundles/heads/base |
| 832 | refs/bundles/heads/left |
| 833 | refs/bundles/heads/merge |
| 834 | EOF |
| 835 | test_cmp expect refs && |
| 836 | |
| 837 | # No-op fetch |
| 838 | GIT_TRACE2_EVENT="$(pwd)/trace2b.txt" \ |
| 839 | git -C fetch-http-4 fetch origin && |
| 840 | |
| 841 | cat >expect <<-EOF && |
| 842 | $HTTPD_URL/bundle-list |
| 843 | EOF |
| 844 | test_remote_https_urls <trace2b.txt >actual && |
| 845 | test_cmp expect actual |
| 846 | ' |
| 847 | |
| 848 | test_expect_success 'creationToken heuristic with failed downloads (clone)' ' |
| 849 | test_when_finished rm -rf download-* trace*.txt && |
| 850 | |
| 851 | # Case 1: base bundle does not exist, nothing can unbundle |
| 852 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 853 | [bundle] |
| 854 | version = 1 |
| 855 | mode = all |
| 856 | heuristic = creationToken |
| 857 | |
| 858 | [bundle "bundle-1"] |
| 859 | uri = fake.bundle |
| 860 | creationToken = 1 |
| 861 | |
| 862 | [bundle "bundle-2"] |
| 863 | uri = bundle-2.bundle |
| 864 | creationToken = 2 |
| 865 | |
| 866 | [bundle "bundle-3"] |
| 867 | uri = bundle-3.bundle |
| 868 | creationToken = 3 |
| 869 | |
| 870 | [bundle "bundle-4"] |
| 871 | uri = bundle-4.bundle |
| 872 | creationToken = 4 |
| 873 | EOF |
| 874 | |
| 875 | GIT_TRACE2_EVENT="$(pwd)/trace-clone-1.txt" \ |
| 876 | git clone --single-branch --branch=base \ |
| 877 | --bundle-uri="$HTTPD_URL/bundle-list" \ |
| 878 | "$HTTPD_URL/smart/fetch.git" download-1 && |
| 879 | |
| 880 | # Bundle failure does not set these configs. |
| 881 | test_must_fail git -C download-1 config fetch.bundleuri && |
| 882 | test_must_fail git -C download-1 config fetch.bundlecreationtoken && |
| 883 | |
| 884 | cat >expect <<-EOF && |
| 885 | $HTTPD_URL/bundle-list |
| 886 | $HTTPD_URL/bundle-4.bundle |
| 887 | $HTTPD_URL/bundle-3.bundle |
| 888 | $HTTPD_URL/bundle-2.bundle |
| 889 | $HTTPD_URL/fake.bundle |
| 890 | EOF |
| 891 | test_remote_https_urls <trace-clone-1.txt >actual && |
| 892 | test_cmp expect actual && |
| 893 | |
| 894 | # All bundles failed to unbundle |
| 895 | git -C download-1 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs && |
| 896 | test_must_be_empty refs && |
| 897 | |
| 898 | # Case 2: middle bundle does not exist, only two bundles can unbundle |
| 899 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 900 | [bundle] |
| 901 | version = 1 |
| 902 | mode = all |
| 903 | heuristic = creationToken |
| 904 | |
| 905 | [bundle "bundle-1"] |
| 906 | uri = bundle-1.bundle |
| 907 | creationToken = 1 |
| 908 | |
| 909 | [bundle "bundle-2"] |
| 910 | uri = fake.bundle |
| 911 | creationToken = 2 |
| 912 | |
| 913 | [bundle "bundle-3"] |
| 914 | uri = bundle-3.bundle |
| 915 | creationToken = 3 |
| 916 | |
| 917 | [bundle "bundle-4"] |
| 918 | uri = bundle-4.bundle |
| 919 | creationToken = 4 |
| 920 | EOF |
| 921 | |
| 922 | GIT_TRACE2_EVENT="$(pwd)/trace-clone-2.txt" \ |
| 923 | git clone --single-branch --branch=base \ |
| 924 | --bundle-uri="$HTTPD_URL/bundle-list" \ |
| 925 | "$HTTPD_URL/smart/fetch.git" download-2 && |
| 926 | |
| 927 | # Bundle failure does not set these configs. |
| 928 | test_must_fail git -C download-2 config fetch.bundleuri && |
| 929 | test_must_fail git -C download-2 config fetch.bundlecreationtoken && |
| 930 | |
| 931 | cat >expect <<-EOF && |
| 932 | $HTTPD_URL/bundle-list |
| 933 | $HTTPD_URL/bundle-4.bundle |
| 934 | $HTTPD_URL/bundle-3.bundle |
| 935 | $HTTPD_URL/fake.bundle |
| 936 | $HTTPD_URL/bundle-1.bundle |
| 937 | EOF |
| 938 | test_remote_https_urls <trace-clone-2.txt >actual && |
| 939 | test_cmp expect actual && |
| 940 | |
| 941 | # bundle-1 and bundle-3 could unbundle, but bundle-4 could not |
| 942 | git -C download-2 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs && |
| 943 | cat >expect <<-EOF && |
| 944 | refs/bundles/heads/base |
| 945 | refs/bundles/heads/right |
| 946 | EOF |
| 947 | test_cmp expect refs && |
| 948 | |
| 949 | # Case 3: top bundle does not exist, rest unbundle fine. |
| 950 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 951 | [bundle] |
| 952 | version = 1 |
| 953 | mode = all |
| 954 | heuristic = creationToken |
| 955 | |
| 956 | [bundle "bundle-1"] |
| 957 | uri = bundle-1.bundle |
| 958 | creationToken = 1 |
| 959 | |
| 960 | [bundle "bundle-2"] |
| 961 | uri = bundle-2.bundle |
| 962 | creationToken = 2 |
| 963 | |
| 964 | [bundle "bundle-3"] |
| 965 | uri = bundle-3.bundle |
| 966 | creationToken = 3 |
| 967 | |
| 968 | [bundle "bundle-4"] |
| 969 | uri = fake.bundle |
| 970 | creationToken = 4 |
| 971 | EOF |
| 972 | |
| 973 | GIT_TRACE2_EVENT="$(pwd)/trace-clone-3.txt" \ |
| 974 | git clone --single-branch --branch=base \ |
| 975 | --bundle-uri="$HTTPD_URL/bundle-list" \ |
| 976 | "$HTTPD_URL/smart/fetch.git" download-3 && |
| 977 | |
| 978 | # As long as we have contiguous successful downloads, |
| 979 | # we _do_ set these configs. |
| 980 | test_cmp_config -C download-3 "$HTTPD_URL/bundle-list" fetch.bundleuri && |
| 981 | test_cmp_config -C download-3 3 fetch.bundlecreationtoken && |
| 982 | |
| 983 | cat >expect <<-EOF && |
| 984 | $HTTPD_URL/bundle-list |
| 985 | $HTTPD_URL/fake.bundle |
| 986 | $HTTPD_URL/bundle-3.bundle |
| 987 | $HTTPD_URL/bundle-2.bundle |
| 988 | $HTTPD_URL/bundle-1.bundle |
| 989 | EOF |
| 990 | test_remote_https_urls <trace-clone-3.txt >actual && |
| 991 | test_cmp expect actual && |
| 992 | |
| 993 | # fake.bundle did not unbundle, but the others did. |
| 994 | git -C download-3 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs && |
| 995 | cat >expect <<-EOF && |
| 996 | refs/bundles/heads/base |
| 997 | refs/bundles/heads/left |
| 998 | refs/bundles/heads/right |
| 999 | EOF |
| 1000 | test_cmp expect refs |
| 1001 | ' |
| 1002 | |
| 1003 | # Expand the bundle list to include other interesting shapes, specifically |
| 1004 | # interesting for use when fetching from a previous state. |
| 1005 | # |
| 1006 | # ---------------- bundle-7 |
| 1007 | # 7 |
| 1008 | # _/|\_ |
| 1009 | # ---/--|--\------ bundle-6 |
| 1010 | # 5 | 6 |
| 1011 | # --|---|---|----- bundle-4 |
| 1012 | # | 4 | |
| 1013 | # | / \ / |
| 1014 | # --|-|---|/------ bundle-3 (the client will be caught up to this point.) |
| 1015 | # \ | 3 |
| 1016 | # ---\|---|------- bundle-2 |
| 1017 | # 2 | |
| 1018 | # ----|---|------- bundle-1 |
| 1019 | # \ / |
| 1020 | # 1 |
| 1021 | # | |
| 1022 | # (previous commits) |
| 1023 | test_expect_success 'expand incremental bundle list' ' |
| 1024 | ( |
| 1025 | cd clone-from && |
| 1026 | git checkout -b lefter left && |
| 1027 | test_commit 5 && |
| 1028 | git checkout -b righter right && |
| 1029 | test_commit 6 && |
| 1030 | git checkout -b top lefter && |
| 1031 | git merge -m "7" merge righter && |
| 1032 | |
| 1033 | git bundle create bundle-6.bundle lefter righter --not left right && |
| 1034 | git bundle create bundle-7.bundle top --not lefter merge righter && |
| 1035 | |
| 1036 | cp bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" |
| 1037 | ) && |
| 1038 | git -C "$HTTPD_DOCUMENT_ROOT_PATH/fetch.git" fetch origin +refs/heads/*:refs/heads/* |
| 1039 | ' |
| 1040 | |
| 1041 | test_expect_success 'creationToken heuristic with failed downloads (fetch)' ' |
| 1042 | test_when_finished rm -rf download-* trace*.txt && |
| 1043 | |
| 1044 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 1045 | [bundle] |
| 1046 | version = 1 |
| 1047 | mode = all |
| 1048 | heuristic = creationToken |
| 1049 | |
| 1050 | [bundle "bundle-1"] |
| 1051 | uri = bundle-1.bundle |
| 1052 | creationToken = 1 |
| 1053 | |
| 1054 | [bundle "bundle-2"] |
| 1055 | uri = bundle-2.bundle |
| 1056 | creationToken = 2 |
| 1057 | |
| 1058 | [bundle "bundle-3"] |
| 1059 | uri = bundle-3.bundle |
| 1060 | creationToken = 3 |
| 1061 | EOF |
| 1062 | |
| 1063 | git clone --single-branch --branch=left \ |
| 1064 | --bundle-uri="$HTTPD_URL/bundle-list" \ |
| 1065 | "$HTTPD_URL/smart/fetch.git" fetch-base && |
| 1066 | test_cmp_config -C fetch-base "$HTTPD_URL/bundle-list" fetch.bundleURI && |
| 1067 | test_cmp_config -C fetch-base 3 fetch.bundleCreationToken && |
| 1068 | |
| 1069 | # Case 1: all bundles exist: successful unbundling of all bundles |
| 1070 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 1071 | [bundle] |
| 1072 | version = 1 |
| 1073 | mode = all |
| 1074 | heuristic = creationToken |
| 1075 | |
| 1076 | [bundle "bundle-1"] |
| 1077 | uri = bundle-1.bundle |
| 1078 | creationToken = 1 |
| 1079 | |
| 1080 | [bundle "bundle-2"] |
| 1081 | uri = bundle-2.bundle |
| 1082 | creationToken = 2 |
| 1083 | |
| 1084 | [bundle "bundle-3"] |
| 1085 | uri = bundle-3.bundle |
| 1086 | creationToken = 3 |
| 1087 | |
| 1088 | [bundle "bundle-4"] |
| 1089 | uri = bundle-4.bundle |
| 1090 | creationToken = 4 |
| 1091 | |
| 1092 | [bundle "bundle-6"] |
| 1093 | uri = bundle-6.bundle |
| 1094 | creationToken = 6 |
| 1095 | |
| 1096 | [bundle "bundle-7"] |
| 1097 | uri = bundle-7.bundle |
| 1098 | creationToken = 7 |
| 1099 | EOF |
| 1100 | |
| 1101 | cp -r fetch-base fetch-1 && |
| 1102 | GIT_TRACE2_EVENT="$(pwd)/trace-fetch-1.txt" \ |
| 1103 | git -C fetch-1 fetch origin && |
| 1104 | test_cmp_config -C fetch-1 7 fetch.bundlecreationtoken && |
| 1105 | |
| 1106 | cat >expect <<-EOF && |
| 1107 | $HTTPD_URL/bundle-list |
| 1108 | $HTTPD_URL/bundle-7.bundle |
| 1109 | $HTTPD_URL/bundle-6.bundle |
| 1110 | $HTTPD_URL/bundle-4.bundle |
| 1111 | EOF |
| 1112 | test_remote_https_urls <trace-fetch-1.txt >actual && |
| 1113 | test_cmp expect actual && |
| 1114 | |
| 1115 | # Check which bundles have unbundled by refs |
| 1116 | git -C fetch-1 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs && |
| 1117 | cat >expect <<-EOF && |
| 1118 | refs/bundles/heads/base |
| 1119 | refs/bundles/heads/left |
| 1120 | refs/bundles/heads/lefter |
| 1121 | refs/bundles/heads/merge |
| 1122 | refs/bundles/heads/right |
| 1123 | refs/bundles/heads/righter |
| 1124 | refs/bundles/heads/top |
| 1125 | EOF |
| 1126 | test_cmp expect refs && |
| 1127 | |
| 1128 | # Case 2: middle bundle does not exist, only bundle-4 can unbundle |
| 1129 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 1130 | [bundle] |
| 1131 | version = 1 |
| 1132 | mode = all |
| 1133 | heuristic = creationToken |
| 1134 | |
| 1135 | [bundle "bundle-1"] |
| 1136 | uri = bundle-1.bundle |
| 1137 | creationToken = 1 |
| 1138 | |
| 1139 | [bundle "bundle-2"] |
| 1140 | uri = bundle-2.bundle |
| 1141 | creationToken = 2 |
| 1142 | |
| 1143 | [bundle "bundle-3"] |
| 1144 | uri = bundle-3.bundle |
| 1145 | creationToken = 3 |
| 1146 | |
| 1147 | [bundle "bundle-4"] |
| 1148 | uri = bundle-4.bundle |
| 1149 | creationToken = 4 |
| 1150 | |
| 1151 | [bundle "bundle-6"] |
| 1152 | uri = fake.bundle |
| 1153 | creationToken = 6 |
| 1154 | |
| 1155 | [bundle "bundle-7"] |
| 1156 | uri = bundle-7.bundle |
| 1157 | creationToken = 7 |
| 1158 | EOF |
| 1159 | |
| 1160 | cp -r fetch-base fetch-2 && |
| 1161 | GIT_TRACE2_EVENT="$(pwd)/trace-fetch-2.txt" \ |
| 1162 | git -C fetch-2 fetch origin && |
| 1163 | |
| 1164 | # Since bundle-7 fails to unbundle, do not update creation token. |
| 1165 | test_cmp_config -C fetch-2 3 fetch.bundlecreationtoken && |
| 1166 | |
| 1167 | cat >expect <<-EOF && |
| 1168 | $HTTPD_URL/bundle-list |
| 1169 | $HTTPD_URL/bundle-7.bundle |
| 1170 | $HTTPD_URL/fake.bundle |
| 1171 | $HTTPD_URL/bundle-4.bundle |
| 1172 | EOF |
| 1173 | test_remote_https_urls <trace-fetch-2.txt >actual && |
| 1174 | test_cmp expect actual && |
| 1175 | |
| 1176 | # Check which bundles have unbundled by refs |
| 1177 | git -C fetch-2 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs && |
| 1178 | cat >expect <<-EOF && |
| 1179 | refs/bundles/heads/base |
| 1180 | refs/bundles/heads/left |
| 1181 | refs/bundles/heads/merge |
| 1182 | refs/bundles/heads/right |
| 1183 | EOF |
| 1184 | test_cmp expect refs && |
| 1185 | |
| 1186 | # Case 3: top bundle does not exist, rest unbundle fine. |
| 1187 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 1188 | [bundle] |
| 1189 | version = 1 |
| 1190 | mode = all |
| 1191 | heuristic = creationToken |
| 1192 | |
| 1193 | [bundle "bundle-1"] |
| 1194 | uri = bundle-1.bundle |
| 1195 | creationToken = 1 |
| 1196 | |
| 1197 | [bundle "bundle-2"] |
| 1198 | uri = bundle-2.bundle |
| 1199 | creationToken = 2 |
| 1200 | |
| 1201 | [bundle "bundle-3"] |
| 1202 | uri = bundle-3.bundle |
| 1203 | creationToken = 3 |
| 1204 | |
| 1205 | [bundle "bundle-4"] |
| 1206 | uri = bundle-4.bundle |
| 1207 | creationToken = 4 |
| 1208 | |
| 1209 | [bundle "bundle-6"] |
| 1210 | uri = bundle-6.bundle |
| 1211 | creationToken = 6 |
| 1212 | |
| 1213 | [bundle "bundle-7"] |
| 1214 | uri = fake.bundle |
| 1215 | creationToken = 7 |
| 1216 | EOF |
| 1217 | |
| 1218 | cp -r fetch-base fetch-3 && |
| 1219 | GIT_TRACE2_EVENT="$(pwd)/trace-fetch-3.txt" \ |
| 1220 | git -C fetch-3 fetch origin && |
| 1221 | |
| 1222 | # As long as we have contiguous successful downloads, |
| 1223 | # we _do_ set the maximum creation token. |
| 1224 | test_cmp_config -C fetch-3 6 fetch.bundlecreationtoken && |
| 1225 | |
| 1226 | # NOTE: the fetch skips bundle-4 since bundle-6 successfully |
| 1227 | # unbundles itself and bundle-7 failed to download. |
| 1228 | cat >expect <<-EOF && |
| 1229 | $HTTPD_URL/bundle-list |
| 1230 | $HTTPD_URL/fake.bundle |
| 1231 | $HTTPD_URL/bundle-6.bundle |
| 1232 | EOF |
| 1233 | test_remote_https_urls <trace-fetch-3.txt >actual && |
| 1234 | test_cmp expect actual && |
| 1235 | |
| 1236 | # Check which bundles have unbundled by refs |
| 1237 | git -C fetch-3 for-each-ref --format="%(refname)" "refs/bundles/heads/*" >refs && |
| 1238 | cat >expect <<-EOF && |
| 1239 | refs/bundles/heads/base |
| 1240 | refs/bundles/heads/left |
| 1241 | refs/bundles/heads/lefter |
| 1242 | refs/bundles/heads/right |
| 1243 | refs/bundles/heads/righter |
| 1244 | EOF |
| 1245 | test_cmp expect refs |
| 1246 | ' |
| 1247 | |
| 1248 | test_expect_success 'bundles are downloaded once during fetch --all' ' |
| 1249 | test_when_finished rm -rf download-* trace*.txt fetch-mult && |
| 1250 | |
| 1251 | cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF && |
| 1252 | [bundle] |
| 1253 | version = 1 |
| 1254 | mode = all |
| 1255 | heuristic = creationToken |
| 1256 | |
| 1257 | [bundle "bundle-1"] |
| 1258 | uri = bundle-1.bundle |
| 1259 | creationToken = 1 |
| 1260 | |
| 1261 | [bundle "bundle-2"] |
| 1262 | uri = bundle-2.bundle |
| 1263 | creationToken = 2 |
| 1264 | |
| 1265 | [bundle "bundle-3"] |
| 1266 | uri = bundle-3.bundle |
| 1267 | creationToken = 3 |
| 1268 | EOF |
| 1269 | |
| 1270 | git clone --single-branch --branch=left \ |
| 1271 | --bundle-uri="$HTTPD_URL/bundle-list" \ |
| 1272 | "$HTTPD_URL/smart/fetch.git" fetch-mult && |
| 1273 | git -C fetch-mult remote add dup1 "$HTTPD_URL/smart/fetch.git" && |
| 1274 | git -C fetch-mult remote add dup2 "$HTTPD_URL/smart/fetch.git" && |
| 1275 | |
| 1276 | GIT_TRACE2_EVENT="$(pwd)/trace-mult.txt" \ |
| 1277 | git -C fetch-mult fetch --all && |
| 1278 | grep "\"child_start\".*\"git-remote-https\",\"$HTTPD_URL/bundle-list\"" \ |
| 1279 | trace-mult.txt >bundle-fetches && |
| 1280 | test_line_count = 1 bundle-fetches |
| 1281 | ' |
| 1282 | |
| 1283 | test_expect_success 'bundles with space in URI are rejected' ' |
| 1284 | test_when_finished "rm -rf busted repo" && |
| 1285 | mkdir -p "$HOME/busted/ /$HOME/repo/.git/objects/bundles" && |
| 1286 | git clone --bundle-uri="$HTTPD_URL/bogus $HOME/busted/" "$HTTPD_URL/smart/fetch.git" repo 2>err && |
| 1287 | test_grep "error: bundle-uri: URI is malformed: " err && |
| 1288 | find busted -type f >files && |
| 1289 | test_must_be_empty files |
| 1290 | ' |
| 1291 | |
| 1292 | test_expect_success 'bundles with newline in URI are rejected' ' |
| 1293 | test_when_finished "rm -rf busted repo" && |
| 1294 | git clone --bundle-uri="$HTTPD_URL/bogus\nget $HTTPD_URL/bogus $HOME/busted" "$HTTPD_URL/smart/fetch.git" repo 2>err && |
| 1295 | test_grep "error: bundle-uri: URI is malformed: " err && |
| 1296 | test_path_is_missing "$HOME/busted" |
| 1297 | ' |
| 1298 | |
| 1299 | test_expect_success 'bundles with newline in target path are rejected' ' |
| 1300 | git clone --bundle-uri="$HTTPD_URL/bogus" "$HTTPD_URL/smart/fetch.git" "$(printf "escape\nget $HTTPD_URL/bogus .")" 2>err && |
| 1301 | test_grep "error: bundle-uri: filename is malformed: " err && |
| 1302 | test_path_is_missing escape |
| 1303 | ' |
| 1304 | |
| 1305 | # Do not add tests here unless they use the HTTP server, as they will |
| 1306 | # not run unless the HTTP dependencies exist. |
| 1307 | |
| 1308 | test_done |