Code

Merge branch 'jc/maint-commit-ignore-i-t-a'
[git.git] / t / t5500-fetch-pack.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Johannes Schindelin
4 #
6 test_description='Testing multi_ack pack fetching'
8 . ./test-lib.sh
10 # Test fetch-pack/upload-pack pair.
12 # Some convenience functions
14 add () {
15         name=$1 &&
16         text="$@" &&
17         branch=`echo $name | sed -e 's/^\(.\).*$/\1/'` &&
18         parents="" &&
20         shift &&
21         while test $1; do
22                 parents="$parents -p $1" &&
23                 shift
24         done &&
26         echo "$text" > test.txt &&
27         git update-index --add test.txt &&
28         tree=$(git write-tree) &&
29         # make sure timestamps are in correct order
30         test_tick &&
31         commit=$(echo "$text" | git commit-tree $tree $parents) &&
32         eval "$name=$commit; export $name" &&
33         echo $commit > .git/refs/heads/$branch &&
34         eval ${branch}TIP=$commit
35 }
37 pull_to_client () {
38         number=$1 &&
39         heads=$2 &&
40         count=$3 &&
41         test_expect_success "$number pull" '
42                 (
43                         cd client &&
44                         git fetch-pack -k -v .. $heads &&
46                         case "$heads" in
47                             *A*)
48                                     echo $ATIP > .git/refs/heads/A;;
49                         esac &&
50                         case "$heads" in *B*)
51                             echo $BTIP > .git/refs/heads/B;;
52                         esac &&
53                         git symbolic-ref HEAD refs/heads/`echo $heads \
54                                 | sed -e "s/^\(.\).*$/\1/"` &&
56                         git fsck --full &&
58                         mv .git/objects/pack/pack-* . &&
59                         p=`ls -1 pack-*.pack` &&
60                         git unpack-objects <$p &&
61                         git fsck --full &&
63                         idx=`echo pack-*.idx` &&
64                         pack_count=`git show-index <$idx | wc -l` &&
65                         test $pack_count = $count &&
66                         rm -f pack-*
67                 )
68         '
69 }
71 # Here begins the actual testing
73 # A1 - ... - A20 - A21
74 #    \
75 #      B1  -   B2 - .. - B70
77 # client pulls A20, B1. Then tracks only B. Then pulls A.
79 test_expect_success 'setup' '
80         mkdir client &&
81         (
82                 cd client &&
83                 git init &&
84                 git config transfer.unpacklimit 0
85         ) &&
86         add A1 &&
87         prev=1 &&
88         cur=2 &&
89         while [ $cur -le 10 ]; do
90                 add A$cur $(eval echo \$A$prev) &&
91                 prev=$cur &&
92                 cur=$(($cur+1))
93         done &&
94         add B1 $A1 &&
95         echo $ATIP > .git/refs/heads/A &&
96         echo $BTIP > .git/refs/heads/B &&
97         git symbolic-ref HEAD refs/heads/B
98 '
100 pull_to_client 1st "refs/heads/B refs/heads/A" $((11*3))
102 test_expect_success 'post 1st pull setup' '
103         add A11 $A10 &&
104         prev=1 &&
105         cur=2 &&
106         while [ $cur -le 65 ]; do
107                 add B$cur $(eval echo \$B$prev) &&
108                 prev=$cur &&
109                 cur=$(($cur+1))
110         done
113 pull_to_client 2nd "refs/heads/B" $((64*3))
115 pull_to_client 3rd "refs/heads/A" $((1*3))
117 test_expect_success 'single branch clone' '
118         git clone --single-branch "file://$(pwd)/." singlebranch
121 test_expect_success 'single branch object count' '
122         GIT_DIR=singlebranch/.git git count-objects -v |
123                 grep "^in-pack:" > count.singlebranch &&
124         echo "in-pack: 198" >expected &&
125         test_cmp expected count.singlebranch
128 test_expect_success 'clone shallow' '
129         git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow
132 test_expect_success 'clone shallow object count' '
133         (
134                 cd shallow &&
135                 git count-objects -v
136         ) > count.shallow &&
137         grep "^in-pack: 18" count.shallow
140 test_expect_success 'clone shallow object count (part 2)' '
141         sed -e "/^in-pack:/d" -e "/^packs:/d" -e "/^size-pack:/d" \
142             -e "/: 0$/d" count.shallow > count_output &&
143         ! test -s count_output
146 test_expect_success 'fsck in shallow repo' '
147         (
148                 cd shallow &&
149                 git fsck --full
150         )
153 test_expect_success 'simple fetch in shallow repo' '
154         (
155                 cd shallow &&
156                 git fetch
157         )
160 test_expect_success 'no changes expected' '
161         (
162                 cd shallow &&
163                 git count-objects -v
164         ) > count.shallow.2 &&
165         cmp count.shallow count.shallow.2
168 test_expect_success 'fetch same depth in shallow repo' '
169         (
170                 cd shallow &&
171                 git fetch --depth=2
172         )
175 test_expect_success 'no changes expected' '
176         (
177                 cd shallow &&
178                 git count-objects -v
179         ) > count.shallow.3 &&
180         cmp count.shallow count.shallow.3
183 test_expect_success 'add two more' '
184         add B66 $B65 &&
185         add B67 $B66
188 test_expect_success 'pull in shallow repo' '
189         (
190                 cd shallow &&
191                 git pull .. B
192         )
195 test_expect_success 'clone shallow object count' '
196         (
197                 cd shallow &&
198                 git count-objects -v
199         ) > count.shallow &&
200         grep "^count: 6" count.shallow
203 test_expect_success 'add two more (part 2)' '
204         add B68 $B67 &&
205         add B69 $B68
208 test_expect_success 'deepening pull in shallow repo' '
209         (
210                 cd shallow &&
211                 git pull --depth 4 .. B
212         )
215 test_expect_success 'clone shallow object count' '
216         (
217                 cd shallow &&
218                 git count-objects -v
219         ) > count.shallow &&
220         grep "^count: 12" count.shallow
223 test_expect_success 'deepening fetch in shallow repo' '
224         (
225                 cd shallow &&
226                 git fetch --depth 4 .. A:A
227         )
230 test_expect_success 'clone shallow object count' '
231         (
232                 cd shallow &&
233                 git count-objects -v
234         ) > count.shallow &&
235         grep "^count: 18" count.shallow
238 test_expect_success 'pull in shallow repo with missing merge base' '
239         (
240                 cd shallow &&
241                 test_must_fail git pull --depth 4 .. A
242         )
245 test_expect_success 'additional simple shallow deepenings' '
246         (
247                 cd shallow &&
248                 git fetch --depth=8 &&
249                 git fetch --depth=10 &&
250                 git fetch --depth=11
251         )
254 test_expect_success 'clone shallow object count' '
255         (
256                 cd shallow &&
257                 git count-objects -v
258         ) > count.shallow &&
259         grep "^count: 52" count.shallow
262 test_expect_success 'clone shallow without --no-single-branch' '
263         git clone --depth 1 "file://$(pwd)/." shallow2
266 test_expect_success 'clone shallow object count' '
267         (
268                 cd shallow2 &&
269                 git count-objects -v
270         ) > count.shallow2 &&
271         grep "^in-pack: 6" count.shallow2
274 test_expect_success 'clone shallow with --branch' '
275         git clone --depth 1 --branch A "file://$(pwd)/." shallow3
278 test_expect_success 'clone shallow object count' '
279         echo "in-pack: 12" > count3.expected &&
280         GIT_DIR=shallow3/.git git count-objects -v |
281                 grep "^in-pack" > count3.actual &&
282         test_cmp count3.expected count3.actual
285 test_expect_success 'clone shallow with detached HEAD' '
286         git checkout HEAD^ &&
287         git clone --depth 1 "file://$(pwd)/." shallow5 &&
288         git checkout - &&
289         GIT_DIR=shallow5/.git git rev-parse HEAD >actual &&
290         git rev-parse HEAD^ >expected &&
291         test_cmp expected actual
294 test_expect_success 'shallow clone pulling tags' '
295         git tag -a -m A TAGA1 A &&
296         git tag -a -m B TAGB1 B &&
297         git tag TAGA2 A &&
298         git tag TAGB2 B &&
299         git clone --depth 1 "file://$(pwd)/." shallow6 &&
301         cat >taglist.expected <<\EOF &&
302 TAGB1
303 TAGB2
304 EOF
305         GIT_DIR=shallow6/.git git tag -l >taglist.actual &&
306         test_cmp taglist.expected taglist.actual &&
308         echo "in-pack: 7" > count6.expected &&
309         GIT_DIR=shallow6/.git git count-objects -v |
310                 grep "^in-pack" > count6.actual &&
311         test_cmp count6.expected count6.actual
314 test_expect_success 'shallow cloning single tag' '
315         git clone --depth 1 --branch=TAGB1 "file://$(pwd)/." shallow7 &&
316         cat >taglist.expected <<\EOF &&
317 TAGB1
318 TAGB2
319 EOF
320         GIT_DIR=shallow7/.git git tag -l >taglist.actual &&
321         test_cmp taglist.expected taglist.actual &&
323         echo "in-pack: 7" > count7.expected &&
324         GIT_DIR=shallow7/.git git count-objects -v |
325                 grep "^in-pack" > count7.actual &&
326         test_cmp count7.expected count7.actual
329 test_done