Code

Merge branch 'maint-1.6.0' into maint-1.6.1
[git.git] / t / t5510-fetch.sh
1 #!/bin/sh
2 # Copyright (c) 2006, Junio C Hamano.
4 test_description='Per branch config variables affects "git fetch".
6 '
8 . ./test-lib.sh
10 D=`pwd`
12 test_bundle_object_count () {
13         git verify-pack -v "$1" >verify.out &&
14         test "$2" = $(grep '^[0-9a-f]\{40\} ' verify.out | wc -l)
15 }
17 test_expect_success setup '
18         echo >file original &&
19         git add file &&
20         git commit -a -m original'
22 test_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 &&
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 &&
33         cd .. &&
34         git clone . three &&
35         cd three &&
36         git config branch.master.remote two &&
37         git config branch.master.merge refs/heads/one &&
38         mkdir -p .git/remotes &&
39         {
40                 echo "URL: ../two/.git/"
41                 echo "Pull: refs/heads/master:refs/heads/two"
42                 echo "Pull: refs/heads/one:refs/heads/one"
43         } >.git/remotes/two &&
44         cd .. &&
45         git clone . bundle &&
46         git clone . seven
47 '
49 test_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 '
61 test_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 &&
74         diff expected actual'
76 test_expect_success 'fetch tags when there is no tags' '
78     cd "$D" &&
80     mkdir notags &&
81     cd notags &&
82     git init &&
84     git fetch -t ..
86 '
88 test_expect_success 'fetch following tags' '
90         cd "$D" &&
91         git tag -a -m 'annotated' anno HEAD &&
92         git tag light HEAD &&
94         mkdir four &&
95         cd four &&
96         git init &&
98         git fetch .. :track &&
99         git show-ref --verify refs/tags/anno &&
100         git show-ref --verify refs/tags/light
104 test_expect_success 'fetch must not resolve short tag name' '
106         cd "$D" &&
108         mkdir five &&
109         cd five &&
110         git init &&
112         test_must_fail git fetch .. anno:five
116 test_expect_success 'fetch must not resolve short remote name' '
118         cd "$D" &&
119         git update-ref refs/remotes/six/HEAD HEAD
121         mkdir six &&
122         cd six &&
123         git init &&
125         test_must_fail git fetch .. six:six
129 test_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
136 test_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 "^$"
143 test_expect_success 'create bundle 2' '
144         cd "$D" &&
145         git bundle create bundle2 master~2..master
148 test_expect_success 'unbundle 1' '
149         cd "$D/bundle" &&
150         git checkout -b some-branch &&
151         test_must_fail git fetch "$D/bundle1" master:master
155 test_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 &&
165         test_bundle_object_count bundle.pack 3
168 test_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-)"
174 test_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 &&
180         (
181                 while read x && test -n "$x"
182                 do
183                         :;
184                 done
185                 cat
186         ) <bundle3 >bundle.pack &&
187         git index-pack bundle.pack &&
188         test_bundle_object_count bundle.pack 3
191 test_expect_success 'bundle should be able to create a full history' '
193         cd "$D" &&
194         git tag -a -m '1.0' v1.0 master &&
195         git bundle create bundle4 v1.0
199 test "$TEST_RSYNC" && {
200 test_expect_success 'fetch via rsync' '
201         git pack-refs &&
202         mkdir rsynced &&
203         cd rsynced &&
204         git init &&
205         git fetch rsync://127.0.0.1$(pwd)/../.git master:refs/heads/master &&
206         git gc --prune &&
207         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
208         git fsck --full
211 test_expect_success 'push via rsync' '
212         mkdir ../rsynced2 &&
213         (cd ../rsynced2 &&
214          git init) &&
215         git push rsync://127.0.0.1$(pwd)/../rsynced2/.git master &&
216         cd ../rsynced2 &&
217         git gc --prune &&
218         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
219         git fsck --full
222 test_expect_success 'push via rsync' '
223         cd .. &&
224         mkdir rsynced3 &&
225         (cd rsynced3 &&
226          git init) &&
227         git push --all rsync://127.0.0.1$(pwd)/rsynced3/.git &&
228         cd rsynced3 &&
229         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
230         git fsck --full
234 test_expect_success 'fetch with a non-applying branch.<name>.merge' '
235         git config branch.master.remote yeti &&
236         git config branch.master.merge refs/heads/bigfoot &&
237         git config remote.blub.url one &&
238         git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
239         git fetch blub
242 # the strange name is: a\!'b
243 test_expect_success 'quoting of a strangely named repo' '
244         test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
245         cat result &&
246         grep "fatal: '\''a\\\\!'\''b'\''" result
249 test_expect_success 'bundle should record HEAD correctly' '
251         cd "$D" &&
252         git bundle create bundle5 HEAD master &&
253         git bundle list-heads bundle5 >actual &&
254         for h in HEAD refs/heads/master
255         do
256                 echo "$(git rev-parse --verify $h) $h"
257         done >expect &&
258         test_cmp expect actual
262 test_expect_success 'explicit fetch should not update tracking' '
264         cd "$D" &&
265         git branch -f side &&
266         (
267                 cd three &&
268                 o=$(git rev-parse --verify refs/remotes/origin/master) &&
269                 git fetch origin master &&
270                 n=$(git rev-parse --verify refs/remotes/origin/master) &&
271                 test "$o" = "$n" &&
272                 test_must_fail git rev-parse --verify refs/remotes/origin/side
273         )
276 test_expect_success 'explicit pull should not update tracking' '
278         cd "$D" &&
279         git branch -f side &&
280         (
281                 cd three &&
282                 o=$(git rev-parse --verify refs/remotes/origin/master) &&
283                 git pull origin master &&
284                 n=$(git rev-parse --verify refs/remotes/origin/master) &&
285                 test "$o" = "$n" &&
286                 test_must_fail git rev-parse --verify refs/remotes/origin/side
287         )
290 test_expect_success 'configured fetch updates tracking' '
292         cd "$D" &&
293         git branch -f side &&
294         (
295                 cd three &&
296                 o=$(git rev-parse --verify refs/remotes/origin/master) &&
297                 git fetch origin &&
298                 n=$(git rev-parse --verify refs/remotes/origin/master) &&
299                 test "$o" != "$n" &&
300                 git rev-parse --verify refs/remotes/origin/side
301         )
304 test_expect_success 'pushing nonexistent branch by mistake should not segv' '
306         cd "$D" &&
307         test_must_fail git push seven no:no
311 test_expect_success 'auto tag following fetches minimum' '
313         cd "$D" &&
314         git clone .git follow &&
315         git checkout HEAD^0 &&
316         (
317                 for i in 1 2 3 4 5 6 7
318                 do
319                         echo $i >>file &&
320                         git commit -m $i -a &&
321                         git tag -a -m $i excess-$i || exit 1
322                 done
323         ) &&
324         git checkout master &&
325         (
326                 cd follow &&
327                 git fetch
328         )
331 test_expect_success 'refuse to fetch into the current branch' '
333         test_must_fail git fetch . side:master
337 test_expect_success 'fetch into the current branch with --update-head-ok' '
339         git fetch --update-head-ok . side:master
343 test_done