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