1#!/bin/sh
2# Copyright (c) 2006, Junio C Hamano.
3
4test_description='Per branch config variables affects "git fetch".
5
6'
7
8. ./test-lib.sh
9
10D=`pwd`
11
12test_expect_success setup '
13 echo >file original &&
14 git add file &&
15 git commit -a -m original'
16
17test_expect_success "clone and setup child repos" '
18 git clone . one &&
19 cd one &&
20 echo >file updated by one &&
21 git commit -a -m "updated by one" &&
22 cd .. &&
23 git clone . two &&
24 cd two &&
25 git config branch.master.remote one &&
26 git config remote.one.url ../one/.git/ &&
27 git config remote.one.fetch refs/heads/master:refs/heads/one &&
28 cd .. &&
29 git clone . three &&
30 cd three &&
31 git config branch.master.remote two &&
32 git config branch.master.merge refs/heads/one &&
33 mkdir -p .git/remotes &&
34 {
35 echo "URL: ../two/.git/"
36 echo "Pull: refs/heads/master:refs/heads/two"
37 echo "Pull: refs/heads/one:refs/heads/one"
38 } >.git/remotes/two &&
39 cd .. &&
40 git clone . bundle
41'
42
43test_expect_success "fetch test" '
44 cd "$D" &&
45 echo >file updated by origin &&
46 git commit -a -m "updated by origin" &&
47 cd two &&
48 git fetch &&
49 test -f .git/refs/heads/one &&
50 mine=`git rev-parse refs/heads/one` &&
51 his=`cd ../one && git rev-parse refs/heads/master` &&
52 test "z$mine" = "z$his"
53'
54
55test_expect_success "fetch test for-merge" '
56 cd "$D" &&
57 cd three &&
58 git fetch &&
59 test -f .git/refs/heads/two &&
60 test -f .git/refs/heads/one &&
61 master_in_two=`cd ../two && git rev-parse master` &&
62 one_in_two=`cd ../two && git rev-parse one` &&
63 {
64 echo "$master_in_two not-for-merge"
65 echo "$one_in_two "
66 } >expected &&
67 cut -f -2 .git/FETCH_HEAD >actual &&
68 diff expected actual'
69
70test_expect_success 'fetch tags when there is no tags' '
71
72 cd "$D" &&
73
74 mkdir notags &&
75 cd notags &&
76 git init &&
77
78 git fetch -t ..
79
80'
81
82test_expect_success 'fetch following tags' '
83
84 cd "$D" &&
85 git tag -a -m 'annotated' anno HEAD &&
86 git tag light HEAD &&
87
88 mkdir four &&
89 cd four &&
90 git init &&
91
92 git fetch .. :track &&
93 git show-ref --verify refs/tags/anno &&
94 git show-ref --verify refs/tags/light
95
96'
97
98test_expect_success 'fetch must not resolve short tag name' '
99
100 cd "$D" &&
101
102 mkdir five &&
103 cd five &&
104 git init &&
105
106 ! git fetch .. anno:five
107
108'
109
110test_expect_success 'fetch must not resolve short remote name' '
111
112 cd "$D" &&
113 git-update-ref refs/remotes/six/HEAD HEAD
114
115 mkdir six &&
116 cd six &&
117 git init &&
118
119 ! git fetch .. six:six
120
121'
122
123test_expect_success 'create bundle 1' '
124 cd "$D" &&
125 echo >file updated again by origin &&
126 git commit -a -m "tip" &&
127 git bundle create bundle1 master^..master
128'
129
130test_expect_success 'header of bundle looks right' '
131 head -n 1 "$D"/bundle1 | grep "^#" &&
132 head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
133 head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
134 head -n 4 "$D"/bundle1 | grep "^$"
135'
136
137test_expect_success 'create bundle 2' '
138 cd "$D" &&
139 git bundle create bundle2 master~2..master
140'
141
142test_expect_success 'unbundle 1' '
143 cd "$D/bundle" &&
144 git checkout -b some-branch &&
145 ! git fetch "$D/bundle1" master:master
146'
147
148test_expect_success 'bundle 1 has only 3 files ' '
149 cd "$D" &&
150 (
151 while read x && test -n "$x"
152 do
153 :;
154 done
155 cat
156 ) <bundle1 >bundle.pack &&
157 git index-pack bundle.pack &&
158 verify=$(git verify-pack -v bundle.pack) &&
159 test 4 = $(echo "$verify" | wc -l)
160'
161
162test_expect_success 'unbundle 2' '
163 cd "$D/bundle" &&
164 git fetch ../bundle2 master:master &&
165 test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
166'
167
168test_expect_success 'bundle does not prerequisite objects' '
169 cd "$D" &&
170 touch file2 &&
171 git add file2 &&
172 git commit -m add.file2 file2 &&
173 git bundle create bundle3 -1 HEAD &&
174 (
175 while read x && test -n "$x"
176 do
177 :;
178 done
179 cat
180 ) <bundle3 >bundle.pack &&
181 git index-pack bundle.pack &&
182 test 4 = $(git verify-pack -v bundle.pack | wc -l)
183'
184
185test_expect_success 'bundle should be able to create a full history' '
186
187 cd "$D" &&
188 git tag -a -m '1.0' v1.0 master &&
189 git bundle create bundle4 v1.0
190
191'
192
193test "$TEST_RSYNC" && {
194test_expect_success 'fetch via rsync' '
195 git pack-refs &&
196 mkdir rsynced &&
197 cd rsynced &&
198 git init &&
199 git fetch rsync://127.0.0.1$(pwd)/../.git master:refs/heads/master &&
200 git gc --prune &&
201 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
202 git fsck --full
203'
204
205test_expect_success 'push via rsync' '
206 mkdir ../rsynced2 &&
207 (cd ../rsynced2 &&
208 git init) &&
209 git push rsync://127.0.0.1$(pwd)/../rsynced2/.git master &&
210 cd ../rsynced2 &&
211 git gc --prune &&
212 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
213 git fsck --full
214'
215
216test_expect_success 'push via rsync' '
217 cd .. &&
218 mkdir rsynced3 &&
219 (cd rsynced3 &&
220 git init) &&
221 git push --all rsync://127.0.0.1$(pwd)/rsynced3/.git &&
222 cd rsynced3 &&
223 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
224 git fsck --full
225'
226}
227
228test_expect_success 'fetch with a non-applying branch.<name>.merge' '
229 git config branch.master.remote yeti &&
230 git config branch.master.merge refs/heads/bigfoot &&
231 git config remote.blub.url one &&
232 git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
233 git fetch blub
234'
235
236# the strange name is: a\!'b
237test_expect_success 'quoting of a strangely named repo' '
238 ! git fetch "a\\!'\''b" > result 2>&1 &&
239 cat result &&
240 grep "fatal: '\''a\\\\!'\''b'\''" result
241'
242
243test_expect_success 'bundle should record HEAD correctly' '
244
245 cd "$D" &&
246 git bundle create bundle5 HEAD master &&
247 git bundle list-heads bundle5 >actual &&
248 for h in HEAD refs/heads/master
249 do
250 echo "$(git rev-parse --verify $h) $h"
251 done >expect &&
252 diff -u expect actual
253
254'
255
256test_expect_success 'explicit fetch should not update tracking' '
257
258 cd "$D" &&
259 git branch -f side &&
260 (
261 cd three &&
262 o=$(git rev-parse --verify refs/remotes/origin/master) &&
263 git fetch origin master &&
264 n=$(git rev-parse --verify refs/remotes/origin/master) &&
265 test "$o" = "$n" &&
266 ! git rev-parse --verify refs/remotes/origin/side
267 )
268'
269
270test_expect_success 'explicit pull should not update tracking' '
271
272 cd "$D" &&
273 git branch -f side &&
274 (
275 cd three &&
276 o=$(git rev-parse --verify refs/remotes/origin/master) &&
277 git pull origin master &&
278 n=$(git rev-parse --verify refs/remotes/origin/master) &&
279 test "$o" = "$n" &&
280 ! git rev-parse --verify refs/remotes/origin/side
281 )
282'
283
284test_expect_success 'configured fetch updates tracking' '
285
286 cd "$D" &&
287 git branch -f side &&
288 (
289 cd three &&
290 o=$(git rev-parse --verify refs/remotes/origin/master) &&
291 git fetch origin &&
292 n=$(git rev-parse --verify refs/remotes/origin/master) &&
293 test "$o" != "$n" &&
294 git rev-parse --verify refs/remotes/origin/side
295 )
296'
297
298test_done