| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test cloning a repository larger than 2 gigabyte' |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | if ! test_bool_env GIT_TEST_CLONE_2GB false |
| 7 | then |
| 8 | skip_all='expensive 2GB clone test; enable with GIT_TEST_CLONE_2GB=true' |
| 9 | test_done |
| 10 | fi |
| 11 | |
| 12 | test_expect_success 'setup' ' |
| 13 | git init 2gb-repo && |
| 14 | ( |
| 15 | cd 2gb-repo && |
| 16 | git config pack.compression 0 && |
| 17 | git config pack.depth 0 && |
| 18 | blobsize=$((100*1024*1024)) && |
| 19 | blobcount=$((2*1024*1024*1024/$blobsize+1)) && |
| 20 | i=1 && |
| 21 | (while test $i -le $blobcount |
| 22 | do |
| 23 | printf "Generating blob $i/$blobcount\r" >&2 && |
| 24 | printf "blob\nmark :$i\ndata $blobsize\n" && |
| 25 | #test-tool genrandom $i $blobsize && |
| 26 | printf "%-${blobsize}s" $i && |
| 27 | echo "M 100644 :$i $i" >> commit && |
| 28 | i=$(($i+1)) || |
| 29 | echo $? > exit-status |
| 30 | done && |
| 31 | echo "commit refs/heads/main" && |
| 32 | echo "author A U Thor <author@email.com> 123456789 +0000" && |
| 33 | echo "committer C O Mitter <committer@email.com> 123456789 +0000" && |
| 34 | echo "data 5" && |
| 35 | echo ">2gb" && |
| 36 | cat commit) | |
| 37 | git fast-import --big-file-threshold=2 && |
| 38 | test ! -f exit-status |
| 39 | ) |
| 40 | ' |
| 41 | |
| 42 | test_expect_success 'clone - bare' ' |
| 43 | test_when_finished rm -rf clone-bare && |
| 44 | git clone --bare --no-hardlinks 2gb-repo clone-bare |
| 45 | ' |
| 46 | |
| 47 | test_expect_success 'clone - with worktree, file:// protocol' ' |
| 48 | test_when_finished rm -rf clone-wt && |
| 49 | git clone "file://$(pwd)/2gb-repo" clone-wt |
| 50 | ' |
| 51 | |
| 52 | rm -rf 2gb-repo 2>/dev/null |
| 53 | |
| 54 | test_expect_success SIZE_T_IS_64BIT,EXPENSIVE 'set up repo with >4GB object' ' |
| 55 | large_blob_size=$((4*1024*1024*1024+1)) && |
| 56 | git init --bare 4gb-repo && |
| 57 | head_oid=$(test-tool synthesize pack \ |
| 58 | --reachable-large "$large_blob_size" \ |
| 59 | 4gb-repo/objects/pack/test.pack) && |
| 60 | git -C 4gb-repo index-pack objects/pack/test.pack && |
| 61 | git -C 4gb-repo update-ref refs/heads/main $head_oid && |
| 62 | git -C 4gb-repo symbolic-ref HEAD refs/heads/main |
| 63 | ' |
| 64 | |
| 65 | test_expect_success SIZE_T_IS_64BIT,EXPENSIVE 'clone >4GB object via unpack-objects' ' |
| 66 | test_when_finished rm -rf 4gb-clone-unpack && |
| 67 | # The synthesized pack has five objects, so a large unpack limit keeps |
| 68 | # fetch-pack on the unpack-objects path. |
| 69 | git -c fetch.unpackLimit=100 clone --bare \ |
| 70 | "file://$(pwd)/4gb-repo" 4gb-clone-unpack && |
| 71 | |
| 72 | # Verify the large blob survived the clone by comparing its OID |
| 73 | # between source and clone. We cannot use "cat-file -s" because |
| 74 | # object_info.sizep is still unsigned long, which truncates >4GB |
| 75 | # sizes on Windows. OID equality proves content integrity since |
| 76 | # the clone already verified checksums via index-pack/unpack-objects. |
| 77 | source_blob=$(git -C 4gb-repo rev-parse main^:file) && |
| 78 | clone_blob=$(git -C 4gb-clone-unpack rev-parse main^:file) && |
| 79 | test "$source_blob" = "$clone_blob" |
| 80 | ' |
| 81 | |
| 82 | test_expect_success SIZE_T_IS_64BIT,EXPENSIVE 'clone with >4GB object via index-pack' ' |
| 83 | test_when_finished rm -rf 4gb-clone-index && |
| 84 | # Force fetch-pack to hand the pack to index-pack instead. |
| 85 | git -c fetch.unpackLimit=1 clone --bare \ |
| 86 | "file://$(pwd)/4gb-repo" 4gb-clone-index && |
| 87 | |
| 88 | source_blob=$(git -C 4gb-repo rev-parse main^:file) && |
| 89 | clone_blob=$(git -C 4gb-clone-index rev-parse main^:file) && |
| 90 | test "$source_blob" = "$clone_blob" |
| 91 | ' |
| 92 | |
| 93 | test_done |