2 # Copyright (c) 2006, Junio C Hamano.
4 test_description
='Per branch config variables affects "git fetch".
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)
17 test_expect_success setup
'
18 echo >file original &&
20 git commit -a -m original'
22 test_expect_success
"clone and setup child repos" '
26 echo >file updated by one &&
27 git commit -a -m "updated by one"
32 git config branch.master.remote one &&
33 git config remote.one.url ../one/.git/ &&
34 git config remote.one.fetch refs/heads/master:refs/heads/one
39 git config branch.master.remote two &&
40 git config branch.master.merge refs/heads/one &&
41 mkdir -p .git/remotes &&
43 echo "URL: ../two/.git/"
44 echo "Pull: refs/heads/master:refs/heads/two"
45 echo "Pull: refs/heads/one:refs/heads/one"
52 test_expect_success
"fetch test" '
54 echo >file updated by origin &&
55 git commit -a -m "updated by origin" &&
58 test -f .git/refs/heads/one &&
59 mine=`git rev-parse refs/heads/one` &&
60 his=`cd ../one && git rev-parse refs/heads/master` &&
61 test "z$mine" = "z$his"
64 test_expect_success
"fetch test for-merge" '
68 test -f .git/refs/heads/two &&
69 test -f .git/refs/heads/one &&
70 master_in_two=`cd ../two && git rev-parse master` &&
71 one_in_two=`cd ../two && git rev-parse one` &&
73 echo "$master_in_two not-for-merge"
76 cut -f -2 .git/FETCH_HEAD >actual &&
77 test_cmp expected actual'
79 test_expect_success
'fetch --prune on its own works as expected' '
83 git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
85 git fetch --prune origin &&
86 test_must_fail git rev-parse origin/extrabranch
89 test_expect_success
'fetch --prune with a branch name keeps branches' '
91 git clone . prune-branch &&
93 git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
95 git fetch --prune origin master &&
96 git rev-parse origin/extrabranch
99 test_expect_success
'fetch --prune with a namespace keeps other namespaces' '
101 git clone . prune-namespace &&
102 cd prune-namespace &&
104 git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
105 git rev-parse origin/master
108 test_expect_success
'fetch --prune --tags does not delete the remote-tracking branches' '
110 git clone . prune-tags &&
112 git fetch origin refs/heads/master:refs/tags/sometag &&
114 git fetch --prune --tags origin &&
115 git rev-parse origin/master &&
116 test_must_fail git rev-parse somebranch
119 test_expect_success
'fetch --prune --tags with branch does not delete other remote-tracking branches' '
121 git clone . prune-tags-branch &&
122 cd prune-tags-branch &&
123 git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
125 git fetch --prune --tags origin master &&
126 git rev-parse origin/extrabranch
129 test_expect_success
'fetch tags when there is no tags' '
141 test_expect_success
'fetch following tags' '
144 git tag -a -m 'annotated
' anno HEAD &&
145 git tag light HEAD &&
151 git fetch .. :track &&
152 git show-ref --verify refs/tags/anno &&
153 git show-ref --verify refs/tags/light
157 test_expect_success
'fetch must not resolve short tag name' '
165 test_must_fail git fetch .. anno:five
169 test_expect_success
'fetch must not resolve short remote name' '
172 git update-ref refs/remotes/six/HEAD HEAD &&
178 test_must_fail git fetch .. six:six
182 test_expect_success
'create bundle 1' '
184 echo >file updated again by origin &&
185 git commit -a -m "tip" &&
186 git bundle create bundle1 master^..master
189 test_expect_success
'header of bundle looks right' '
190 head -n 1 "$D"/bundle1 | grep "^#" &&
191 head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
192 head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
193 head -n 4 "$D"/bundle1 | grep "^$"
196 test_expect_success
'create bundle 2' '
198 git bundle create bundle2 master~2..master
201 test_expect_success
'unbundle 1' '
203 git checkout -b some-branch &&
204 test_must_fail git fetch "$D/bundle1" master:master
208 test_expect_success
'bundle 1 has only 3 files ' '
211 while read x && test -n "$x"
216 ) <bundle1 >bundle.pack &&
217 git index-pack bundle.pack &&
218 test_bundle_object_count bundle.pack 3
221 test_expect_success
'unbundle 2' '
223 git fetch ../bundle2 master:master &&
224 test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
227 test_expect_success
'bundle does not prerequisite objects' '
231 git commit -m add.file2 file2 &&
232 git bundle create bundle3 -1 HEAD &&
234 while read x && test -n "$x"
239 ) <bundle3 >bundle.pack &&
240 git index-pack bundle.pack &&
241 test_bundle_object_count bundle.pack 3
244 test_expect_success
'bundle should be able to create a full history' '
247 git tag -a -m '1.0' v1.0 master &&
248 git bundle create bundle4 v1.0
252 ! rsync
--help > /dev
/null
2> /dev
/null
&&
253 say
'Skipping rsync tests because rsync was not found' ||
{
254 test_expect_success
'fetch via rsync' '
259 git fetch "rsync:$(pwd)/../.git" master:refs/heads/master &&
261 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
265 test_expect_success
'push via rsync' '
270 git push "rsync:$(pwd)/../rsynced2/.git" master) &&
273 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
277 test_expect_success
'push via rsync' '
281 git push --all "rsync:$(pwd)/rsynced3/.git" &&
283 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
288 test_expect_success
'fetch with a non-applying branch.<name>.merge' '
289 git config branch.master.remote yeti &&
290 git config branch.master.merge refs/heads/bigfoot &&
291 git config remote.blub.url one &&
292 git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
296 # URL supplied to fetch does not match the url of the configured branch's remote
297 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
298 one_head=$(cd one && git rev-parse HEAD) &&
299 this_head=$(git rev-parse HEAD) &&
300 git update-ref -d FETCH_HEAD &&
302 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
303 test $this_head = "$(git rev-parse --verify HEAD)"
306 # URL supplied to fetch matches the url of the configured branch's remote and
307 # the merge spec matches the branch the remote HEAD points to
308 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [2]' '
309 one_ref=$(cd one && git symbolic-ref HEAD) &&
310 git config branch.master.remote blub &&
311 git config branch.master.merge "$one_ref" &&
312 git update-ref -d FETCH_HEAD &&
314 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
315 test $this_head = "$(git rev-parse --verify HEAD)"
318 # URL supplied to fetch matches the url of the configured branch's remote, but
319 # the merge spec does not match the branch the remote HEAD points to
320 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
321 git config branch.master.merge "${one_ref}_not" &&
322 git update-ref -d FETCH_HEAD &&
324 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
325 test $this_head = "$(git rev-parse --verify HEAD)"
328 # the strange name is: a\!'b
329 test_expect_success
'quoting of a strangely named repo' '
330 test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
332 grep "fatal: '\''a\\\\!'\''b'\''" result
335 test_expect_success
'bundle should record HEAD correctly' '
338 git bundle create bundle5 HEAD master &&
339 git bundle list-heads bundle5 >actual &&
340 for h in HEAD refs/heads/master
342 echo "$(git rev-parse --verify $h) $h"
344 test_cmp expect actual
348 test_expect_success
'explicit fetch should not update tracking' '
351 git branch -f side &&
354 o=$(git rev-parse --verify refs/remotes/origin/master) &&
355 git fetch origin master &&
356 n=$(git rev-parse --verify refs/remotes/origin/master) &&
358 test_must_fail git rev-parse --verify refs/remotes/origin/side
362 test_expect_success
'explicit pull should not update tracking' '
365 git branch -f side &&
368 o=$(git rev-parse --verify refs/remotes/origin/master) &&
369 git pull origin master &&
370 n=$(git rev-parse --verify refs/remotes/origin/master) &&
372 test_must_fail git rev-parse --verify refs/remotes/origin/side
376 test_expect_success
'configured fetch updates tracking' '
379 git branch -f side &&
382 o=$(git rev-parse --verify refs/remotes/origin/master) &&
384 n=$(git rev-parse --verify refs/remotes/origin/master) &&
386 git rev-parse --verify refs/remotes/origin/side
390 test_expect_success
'pushing nonexistent branch by mistake should not segv' '
393 test_must_fail git push seven no:no
397 test_expect_success
'auto tag following fetches minimum' '
400 git clone .git follow &&
401 git checkout HEAD^0 &&
403 for i in 1 2 3 4 5 6 7
406 git commit -m $i -a &&
407 git tag -a -m $i excess-$i || exit 1
410 git checkout master &&
417 test_expect_success
'refuse to fetch into the current branch' '
419 test_must_fail git fetch . side:master
423 test_expect_success
'fetch into the current branch with --update-head-ok' '
425 git fetch --update-head-ok . side:master
429 test_expect_success
'fetch --dry-run' '
431 rm -f .git/FETCH_HEAD &&
432 git fetch --dry-run . &&
433 ! test -f .git/FETCH_HEAD
436 test_expect_success
"should be able to fetch with duplicate refspecs" '
440 git config branch.master.remote three &&
441 git config remote.three.url ../three/.git &&
442 git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
443 git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&