1#!/bin/sh
2#
3# Copyright (c) 2005 Johannes Schindelin
4#
5
6test_description='Testing multi_ack pack fetching'
7
8. ./test-lib.sh
9
10# Test fetch-pack/upload-pack pair.
11
12# Some convenience functions
13
14add () {
15 name=$1 &&
16 text="$@" &&
17 branch=`echo $name | sed -e 's/^\(.\).*$/\1/'` &&
18 parents="" &&
19
20 shift &&
21 while test $1; do
22 parents="$parents -p $1" &&
23 shift
24 done &&
25
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}
36
37pull_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 &&
45
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/"` &&
55
56 git fsck --full &&
57
58 mv .git/objects/pack/pack-* . &&
59 p=`ls -1 pack-*.pack` &&
60 git unpack-objects <$p &&
61 git fsck --full &&
62
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}
70
71# Here begins the actual testing
72
73# A1 - ... - A20 - A21
74# \
75# B1 - B2 - .. - B70
76
77# client pulls A20, B1. Then tracks only B. Then pulls A.
78
79test_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'
99
100pull_to_client 1st "B A" $((11*3))
101
102test_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
111'
112
113pull_to_client 2nd "B" $((64*3))
114
115pull_to_client 3rd "A" $((1*3))
116
117test_expect_success 'clone shallow' '
118 git clone --depth 2 "file://$(pwd)/." shallow
119'
120
121test_expect_success 'clone shallow object count' '
122 (
123 cd shallow &&
124 git count-objects -v
125 ) > count.shallow &&
126 grep "^in-pack: 18" count.shallow
127'
128
129test_expect_success 'clone shallow object count (part 2)' '
130 sed -e "/^in-pack:/d" -e "/^packs:/d" -e "/^size-pack:/d" \
131 -e "/: 0$/d" count.shallow > count_output &&
132 ! test -s count_output
133'
134
135test_expect_success 'fsck in shallow repo' '
136 (
137 cd shallow &&
138 git fsck --full
139 )
140'
141
142test_expect_success 'add two more' '
143 add B66 $B65 &&
144 add B67 $B66
145'
146
147test_expect_success 'pull in shallow repo' '
148 (
149 cd shallow &&
150 git pull .. B
151 )
152'
153
154test_expect_success 'clone shallow object count' '
155 (
156 cd shallow &&
157 git count-objects -v
158 ) > count.shallow &&
159 grep "^count: 6" count.shallow
160'
161
162test_expect_success 'add two more (part 2)' '
163 add B68 $B67 &&
164 add B69 $B68
165'
166
167test_expect_success 'deepening pull in shallow repo' '
168 (
169 cd shallow &&
170 git pull --depth 4 .. B
171 )
172'
173
174test_expect_success 'clone shallow object count' '
175 (
176 cd shallow &&
177 git count-objects -v
178 ) > count.shallow &&
179 grep "^count: 12" count.shallow
180'
181
182test_expect_success 'deepening fetch in shallow repo' '
183 (
184 cd shallow &&
185 git fetch --depth 4 .. A:A
186 )
187'
188
189test_expect_success 'clone shallow object count' '
190 (
191 cd shallow &&
192 git count-objects -v
193 ) > count.shallow &&
194 grep "^count: 18" count.shallow
195'
196
197test_expect_success 'pull in shallow repo with missing merge base' '
198 (
199 cd shallow &&
200 test_must_fail git pull --depth 4 .. A
201 )
202'
203
204test_done