builtin/fetch.c: comment that branch->remote_name is usable when has_merge
[git/git.git] / t / t5510-fetch.sh
CommitLineData
7be1d62c
JH
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
2e674a9d
JH
12test_bundle_object_count () {
13 git verify-pack -v "$1" >verify.out &&
14 test "$2" = $(grep '^[0-9a-f]\{40\} ' verify.out | wc -l)
15}
16
7be1d62c
JH
17test_expect_success setup '
18 echo >file original &&
19 git add file &&
20 git commit -a -m original'
21
22test_expect_success "clone and setup child repos" '
23 git clone . one &&
24 cd one &&
25 echo >file updated by one &&
26 git commit -a -m "updated by one" &&
27 cd .. &&
28 git clone . two &&
29 cd two &&
e0d10e1c
TP
30 git config branch.master.remote one &&
31 git config remote.one.url ../one/.git/ &&
32 git config remote.one.fetch refs/heads/master:refs/heads/one &&
6cc7c36d
SB
33 cd .. &&
34 git clone . three &&
35 cd three &&
e0d10e1c
TP
36 git config branch.master.remote two &&
37 git config branch.master.merge refs/heads/one &&
75c384ef 38 mkdir -p .git/remotes &&
6cc7c36d
SB
39 {
40 echo "URL: ../two/.git/"
41 echo "Pull: refs/heads/master:refs/heads/two"
42 echo "Pull: refs/heads/one:refs/heads/one"
2e0afafe
JS
43 } >.git/remotes/two &&
44 cd .. &&
9a7bbd1d
JK
45 git clone . bundle &&
46 git clone . seven
7be1d62c
JH
47'
48
49test_expect_success "fetch test" '
50 cd "$D" &&
51 echo >file updated by origin &&
52 git commit -a -m "updated by origin" &&
53 cd two &&
54 git fetch &&
55 test -f .git/refs/heads/one &&
56 mine=`git rev-parse refs/heads/one` &&
57 his=`cd ../one && git rev-parse refs/heads/master` &&
58 test "z$mine" = "z$his"
59'
60
6cc7c36d
SB
61test_expect_success "fetch test for-merge" '
62 cd "$D" &&
63 cd three &&
64 git fetch &&
65 test -f .git/refs/heads/two &&
66 test -f .git/refs/heads/one &&
67 master_in_two=`cd ../two && git rev-parse master` &&
68 one_in_two=`cd ../two && git rev-parse one` &&
69 {
70 echo "$master_in_two not-for-merge"
71 echo "$one_in_two "
72 } >expected &&
73 cut -f -2 .git/FETCH_HEAD >actual &&
4fdf71be 74 test_cmp expected actual'
6cc7c36d 75
f539d0d6
VJ
76test_expect_success 'fetch tags when there is no tags' '
77
78 cd "$D" &&
79
80 mkdir notags &&
81 cd notags &&
82 git init &&
83
84 git fetch -t ..
85
86'
87
6c96c0f1
JH
88test_expect_success 'fetch following tags' '
89
90 cd "$D" &&
91 git tag -a -m 'annotated' anno HEAD &&
92 git tag light HEAD &&
93
94 mkdir four &&
95 cd four &&
5c94f87e 96 git init &&
6c96c0f1
JH
97
98 git fetch .. :track &&
99 git show-ref --verify refs/tags/anno &&
100 git show-ref --verify refs/tags/light
101
102'
103
41ac414e 104test_expect_success 'fetch must not resolve short tag name' '
605b4978
SP
105
106 cd "$D" &&
107
108 mkdir five &&
109 cd five &&
110 git init &&
111
d492b31c 112 test_must_fail git fetch .. anno:five
605b4978
SP
113
114'
115
41ac414e 116test_expect_success 'fetch must not resolve short remote name' '
605b4978
SP
117
118 cd "$D" &&
3604e7c5 119 git update-ref refs/remotes/six/HEAD HEAD
605b4978
SP
120
121 mkdir six &&
122 cd six &&
123 git init &&
124
d492b31c 125 test_must_fail git fetch .. six:six
605b4978
SP
126
127'
128
2e0afafe
JS
129test_expect_success 'create bundle 1' '
130 cd "$D" &&
131 echo >file updated again by origin &&
132 git commit -a -m "tip" &&
133 git bundle create bundle1 master^..master
134'
135
8315588b
JS
136test_expect_success 'header of bundle looks right' '
137 head -n 1 "$D"/bundle1 | grep "^#" &&
138 head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
139 head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
140 head -n 4 "$D"/bundle1 | grep "^$"
141'
142
2e0afafe
JS
143test_expect_success 'create bundle 2' '
144 cd "$D" &&
145 git bundle create bundle2 master~2..master
146'
147
41ac414e 148test_expect_success 'unbundle 1' '
2e0afafe
JS
149 cd "$D/bundle" &&
150 git checkout -b some-branch &&
d492b31c 151 test_must_fail git fetch "$D/bundle1" master:master
2e0afafe
JS
152'
153
2e674a9d 154
8315588b
JS
155test_expect_success 'bundle 1 has only 3 files ' '
156 cd "$D" &&
157 (
158 while read x && test -n "$x"
159 do
160 :;
161 done
162 cat
163 ) <bundle1 >bundle.pack &&
164 git index-pack bundle.pack &&
2e674a9d 165 test_bundle_object_count bundle.pack 3
8315588b
JS
166'
167
2e0afafe
JS
168test_expect_success 'unbundle 2' '
169 cd "$D/bundle" &&
170 git fetch ../bundle2 master:master &&
171 test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
172'
173
18449ab0
JS
174test_expect_success 'bundle does not prerequisite objects' '
175 cd "$D" &&
176 touch file2 &&
177 git add file2 &&
178 git commit -m add.file2 file2 &&
179 git bundle create bundle3 -1 HEAD &&
6016e35b
SP
180 (
181 while read x && test -n "$x"
182 do
183 :;
184 done
185 cat
186 ) <bundle3 >bundle.pack &&
18449ab0 187 git index-pack bundle.pack &&
2e674a9d 188 test_bundle_object_count bundle.pack 3
18449ab0
JS
189'
190
7fa8254f
JH
191test_expect_success 'bundle should be able to create a full history' '
192
193 cd "$D" &&
194 git tag -a -m '1.0' v1.0 master &&
195 git bundle create bundle4 v1.0
196
197'
198
7efaeba2
JS
199! rsync --help > /dev/null 2> /dev/null &&
200say 'Skipping rsync tests because rsync was not found' || {
cd547b48
JS
201test_expect_success 'fetch via rsync' '
202 git pack-refs &&
203 mkdir rsynced &&
7efaeba2
JS
204 (cd rsynced &&
205 git init --bare &&
206 git fetch "rsync:$(pwd)/../.git" master:refs/heads/master &&
207 git gc --prune &&
208 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
209 git fsck --full)
cd547b48
JS
210'
211
212test_expect_success 'push via rsync' '
7efaeba2
JS
213 mkdir rsynced2 &&
214 (cd rsynced2 &&
cd547b48 215 git init) &&
7efaeba2
JS
216 (cd rsynced &&
217 git push "rsync:$(pwd)/../rsynced2/.git" master) &&
218 (cd rsynced2 &&
219 git gc --prune &&
220 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
221 git fsck --full)
cd547b48
JS
222'
223
224test_expect_success 'push via rsync' '
cd547b48
JS
225 mkdir rsynced3 &&
226 (cd rsynced3 &&
227 git init) &&
7efaeba2
JS
228 git push --all "rsync:$(pwd)/rsynced3/.git" &&
229 (cd rsynced3 &&
230 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
231 git fsck --full)
cd547b48
JS
232'
233}
234
da0204df
JS
235test_expect_success 'fetch with a non-applying branch.<name>.merge' '
236 git config branch.master.remote yeti &&
237 git config branch.master.merge refs/heads/bigfoot &&
238 git config remote.blub.url one &&
239 git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
240 git fetch blub
241'
242
3ee1757b 243test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge' '
6106ce46
BC
244 git update-ref -d FETCH_HEAD &&
245 git fetch one &&
246 git rev-parse --verify FETCH_HEAD
247'
248
c2015b3a
JS
249# the strange name is: a\!'b
250test_expect_success 'quoting of a strangely named repo' '
d492b31c 251 test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
c2015b3a
JS
252 cat result &&
253 grep "fatal: '\''a\\\\!'\''b'\''" result
254'
255
c5546e88
JS
256test_expect_success 'bundle should record HEAD correctly' '
257
258 cd "$D" &&
259 git bundle create bundle5 HEAD master &&
260 git bundle list-heads bundle5 >actual &&
261 for h in HEAD refs/heads/master
262 do
263 echo "$(git rev-parse --verify $h) $h"
264 done >expect &&
82ebb0b6 265 test_cmp expect actual
c5546e88
JS
266
267'
268
c7015961
JH
269test_expect_success 'explicit fetch should not update tracking' '
270
271 cd "$D" &&
272 git branch -f side &&
273 (
274 cd three &&
275 o=$(git rev-parse --verify refs/remotes/origin/master) &&
276 git fetch origin master &&
277 n=$(git rev-parse --verify refs/remotes/origin/master) &&
278 test "$o" = "$n" &&
d492b31c 279 test_must_fail git rev-parse --verify refs/remotes/origin/side
c7015961
JH
280 )
281'
282
283test_expect_success 'explicit pull should not update tracking' '
284
285 cd "$D" &&
286 git branch -f side &&
287 (
288 cd three &&
289 o=$(git rev-parse --verify refs/remotes/origin/master) &&
290 git pull origin master &&
291 n=$(git rev-parse --verify refs/remotes/origin/master) &&
292 test "$o" = "$n" &&
d492b31c 293 test_must_fail git rev-parse --verify refs/remotes/origin/side
c7015961
JH
294 )
295'
296
297test_expect_success 'configured fetch updates tracking' '
298
299 cd "$D" &&
300 git branch -f side &&
301 (
302 cd three &&
303 o=$(git rev-parse --verify refs/remotes/origin/master) &&
304 git fetch origin &&
305 n=$(git rev-parse --verify refs/remotes/origin/master) &&
306 test "$o" != "$n" &&
307 git rev-parse --verify refs/remotes/origin/side
308 )
309'
310
9a7bbd1d
JK
311test_expect_success 'pushing nonexistent branch by mistake should not segv' '
312
313 cd "$D" &&
314 test_must_fail git push seven no:no
315
316'
317
49420252
JH
318test_expect_success 'auto tag following fetches minimum' '
319
320 cd "$D" &&
321 git clone .git follow &&
322 git checkout HEAD^0 &&
323 (
324 for i in 1 2 3 4 5 6 7
325 do
326 echo $i >>file &&
327 git commit -m $i -a &&
328 git tag -a -m $i excess-$i || exit 1
329 done
330 ) &&
331 git checkout master &&
332 (
333 cd follow &&
334 git fetch
335 )
336'
337
8ee5d731
JS
338test_expect_success 'refuse to fetch into the current branch' '
339
340 test_must_fail git fetch . side:master
341
342'
343
344test_expect_success 'fetch into the current branch with --update-head-ok' '
345
346 git fetch --update-head-ok . side:master
347
348'
349
3fdcdbdf
JS
350test_expect_success 'fetch --dry-run' '
351
352 rm -f .git/FETCH_HEAD &&
353 git fetch --dry-run . &&
354 ! test -f .git/FETCH_HEAD
355'
356
95c96d48
JP
357test_expect_success "should be able to fetch with duplicate refspecs" '
358 mkdir dups &&
359 cd dups &&
360 git init &&
361 git config branch.master.remote three &&
362 git config remote.three.url ../three/.git &&
363 git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
364 git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
365 git fetch three
366'
367
7be1d62c 368test_done