]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5502-quickfetch.sh
The third batch
[thirdparty/git.git] / t / t5502-quickfetch.sh
1 #!/bin/sh
2
3 test_description='test quickfetch from local'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 test_expect_success setup '
12
13 test_tick &&
14 echo ichi >file &&
15 git add file &&
16 git commit -m initial &&
17
18 cnt=$( (
19 git count-objects | sed -e "s/ *objects,.*//"
20 ) ) &&
21 test $cnt -eq 3
22 '
23
24 test_expect_success 'clone without alternate' '
25
26 (
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
37 '
38
39 test_expect_success 'further commits in the original' '
40
41 test_tick &&
42 echo ni >file &&
43 git commit -a -m second &&
44
45 cnt=$( (
46 git count-objects | sed -e "s/ *objects,.*//"
47 ) ) &&
48 test $cnt -eq 6
49 '
50
51 test_expect_success 'copy commit and tree but not blob by hand' '
52
53 git rev-list --objects HEAD |
54 git pack-objects --stdout |
55 (
56 cd cloned &&
57 git unpack-objects
58 ) &&
59
60 cnt=$( (
61 cd cloned &&
62 git count-objects | sed -e "s/ *objects,.*//"
63 ) ) &&
64 test $cnt -eq 6 &&
65
66 blob=$(git rev-parse HEAD:file | sed -e "s|..|&/|") &&
67 test -f "cloned/.git/objects/$blob" &&
68 rm -f "cloned/.git/objects/$blob" &&
69
70 cnt=$( (
71 cd cloned &&
72 git count-objects | sed -e "s/ *objects,.*//"
73 ) ) &&
74 test $cnt -eq 5
75
76 '
77
78 test_expect_success 'quickfetch should not leave a corrupted repository' '
79
80 (
81 cd cloned &&
82 git fetch
83 ) &&
84
85 cnt=$( (
86 cd cloned &&
87 git count-objects | sed -e "s/ *objects,.*//"
88 ) ) &&
89 test $cnt -eq 6
90
91 '
92
93 test_expect_success 'quickfetch should not copy from alternate' '
94
95 (
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://
111 p
112 q
113 }"
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)
123
124 '
125
126 test_expect_success 'quickfetch should handle ~1000 refs (on Windows)' '
127
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 &&
138 (
139 cd cloned &&
140 git fetch &&
141 git fetch
142 )
143
144 '
145
146 test_done