Git 2.45
[git/gitster.git] / t / t5502-quickfetch.sh
blob7b3ff21b984ff4fcfbd4a64a3eecceabf694e27b
1 #!/bin/sh
3 test_description='test quickfetch from local'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success setup '
13 test_tick &&
14 echo ichi >file &&
15 git add file &&
16 git commit -m initial &&
18 cnt=$( (
19 git count-objects | sed -e "s/ *objects,.*//"
20 ) ) &&
21 test $cnt -eq 3
24 test_expect_success 'clone without alternate' '
27 mkdir cloned &&
28 cd cloned &&
29 git init-db &&
30 git remote add -f origin ..
31 ) &&
32 cnt=$( (
33 cd cloned &&
34 git count-objects | sed -e "s/ *objects,.*//"
35 ) ) &&
36 test $cnt -eq 3
39 test_expect_success 'further commits in the original' '
41 test_tick &&
42 echo ni >file &&
43 git commit -a -m second &&
45 cnt=$( (
46 git count-objects | sed -e "s/ *objects,.*//"
47 ) ) &&
48 test $cnt -eq 6
51 test_expect_success 'copy commit and tree but not blob by hand' '
53 git rev-list --objects HEAD |
54 git pack-objects --stdout |
56 cd cloned &&
57 git unpack-objects
58 ) &&
60 cnt=$( (
61 cd cloned &&
62 git count-objects | sed -e "s/ *objects,.*//"
63 ) ) &&
64 test $cnt -eq 6 &&
66 blob=$(git rev-parse HEAD:file | sed -e "s|..|&/|") &&
67 test -f "cloned/.git/objects/$blob" &&
68 rm -f "cloned/.git/objects/$blob" &&
70 cnt=$( (
71 cd cloned &&
72 git count-objects | sed -e "s/ *objects,.*//"
73 ) ) &&
74 test $cnt -eq 5
78 test_expect_success 'quickfetch should not leave a corrupted repository' '
81 cd cloned &&
82 git fetch
83 ) &&
85 cnt=$( (
86 cd cloned &&
87 git count-objects | sed -e "s/ *objects,.*//"
88 ) ) &&
89 test $cnt -eq 6
93 test_expect_success 'quickfetch should not copy from alternate' '
96 mkdir quickclone &&
97 cd quickclone &&
98 git init-db &&
99 (cd ../.git/objects && pwd) >.git/objects/info/alternates &&
100 git remote add origin .. &&
101 git fetch -k -k
102 ) &&
103 obj_cnt=$( (
104 cd quickclone &&
105 git count-objects | sed -e "s/ *objects,.*//"
106 ) ) &&
107 pck_cnt=$( (
108 cd quickclone &&
109 git count-objects -v | sed -n -e "/packs:/{
110 s/packs://
114 ) ) &&
115 origin_main=$( (
116 cd quickclone &&
117 git rev-parse origin/main
118 ) ) &&
119 echo "loose objects: $obj_cnt, packfiles: $pck_cnt" &&
120 test $obj_cnt -eq 0 &&
121 test $pck_cnt -eq 0 &&
122 test z$origin_main = z$(git rev-parse main)
126 test_expect_success 'quickfetch should handle ~1000 refs (on Windows)' '
128 git gc &&
129 head=$(git rev-parse HEAD) &&
130 branchprefix="$head refs/heads/branch" &&
131 for i in 0 1 2 3 4 5 6 7 8 9; do
132 for j in 0 1 2 3 4 5 6 7 8 9; do
133 for k in 0 1 2 3 4 5 6 7 8 9; do
134 echo "$branchprefix$i$j$k" >> .git/packed-refs || return 1
135 done
136 done
137 done &&
139 cd cloned &&
140 git fetch &&
141 git fetch
146 test_done