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" '
25 echo >file updated by one &&
26 git commit -a -m "updated by one" &&
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 &&
36 git config branch.master.remote two &&
37 git config branch.master.merge refs/heads/one &&
38 mkdir -p .git/remotes &&
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 &&
49 test_expect_success
"fetch test" '
51 echo >file updated by origin &&
52 git commit -a -m "updated by origin" &&
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"
61 test_expect_success
"fetch test for-merge" '
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` &&
70 echo "$master_in_two not-for-merge"
73 cut -f -2 .git/FETCH_HEAD >actual &&
74 test_cmp expected actual'
76 test_expect_success
'fetch tags when there is no tags' '
88 test_expect_success
'fetch following tags' '
91 git tag -a -m 'annotated
' anno HEAD &&
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' '
112 test_must_fail git fetch .. anno:five
116 test_expect_success
'fetch must not resolve short remote name' '
119 git update-ref refs/remotes/six/HEAD HEAD
125 test_must_fail git fetch .. six:six
129 test_expect_success
'create bundle 1' '
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' '
145 git bundle create bundle2 master~2..master
148 test_expect_success
'unbundle 1' '
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 ' '
158 while read x && test -n "$x"
163 ) <bundle1 >bundle.pack &&
164 git index-pack bundle.pack &&
165 test_bundle_object_count bundle.pack 3
168 test_expect_success
'unbundle 2' '
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' '
178 git commit -m add.file2 file2 &&
179 git bundle create bundle3 -1 HEAD &&
181 while read x && test -n "$x"
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' '
194 git tag -a -m '1.0' v1.0 master &&
195 git bundle create bundle4 v1.0
199 ! rsync
--help > /dev
/null
2> /dev
/null
&&
200 say
'Skipping rsync tests because rsync was not found' ||
{
201 test_expect_success
'fetch via rsync' '
206 git fetch "rsync:$(pwd)/../.git" master:refs/heads/master &&
208 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
212 test_expect_success
'push via rsync' '
217 git push "rsync:$(pwd)/../rsynced2/.git" master) &&
220 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
224 test_expect_success
'push via rsync' '
228 git push --all "rsync:$(pwd)/rsynced3/.git" &&
230 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
235 test_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/*" &&
243 # URL supplied to fetch does not match the url of the configured branch's remote
244 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
245 one_head=$(cd one && git rev-parse HEAD) &&
246 this_head=$(git rev-parse HEAD) &&
247 git update-ref -d FETCH_HEAD &&
249 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
250 test $this_head = "$(git rev-parse --verify HEAD)"
253 # URL supplied to fetch matches the url of the configured branch's remote and
254 # the merge spec matches the branch the remote HEAD points to
255 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [2]' '
256 one_ref=$(cd one && git symbolic-ref HEAD) &&
257 git config branch.master.remote blub &&
258 git config branch.master.merge "$one_ref" &&
259 git update-ref -d FETCH_HEAD &&
261 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
262 test $this_head = "$(git rev-parse --verify HEAD)"
265 # URL supplied to fetch matches the url of the configured branch's remote, but
266 # the merge spec does not match the branch the remote HEAD points to
267 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
268 git config branch.master.merge "${one_ref}_not" &&
269 git update-ref -d FETCH_HEAD &&
271 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
272 test $this_head = "$(git rev-parse --verify HEAD)"
275 # the strange name is: a\!'b
276 test_expect_success
'quoting of a strangely named repo' '
277 test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
279 grep "fatal: '\''a\\\\!'\''b'\''" result
282 test_expect_success
'bundle should record HEAD correctly' '
285 git bundle create bundle5 HEAD master &&
286 git bundle list-heads bundle5 >actual &&
287 for h in HEAD refs/heads/master
289 echo "$(git rev-parse --verify $h) $h"
291 test_cmp expect actual
295 test_expect_success
'explicit fetch should not update tracking' '
298 git branch -f side &&
301 o=$(git rev-parse --verify refs/remotes/origin/master) &&
302 git fetch origin master &&
303 n=$(git rev-parse --verify refs/remotes/origin/master) &&
305 test_must_fail git rev-parse --verify refs/remotes/origin/side
309 test_expect_success
'explicit pull should not update tracking' '
312 git branch -f side &&
315 o=$(git rev-parse --verify refs/remotes/origin/master) &&
316 git pull origin master &&
317 n=$(git rev-parse --verify refs/remotes/origin/master) &&
319 test_must_fail git rev-parse --verify refs/remotes/origin/side
323 test_expect_success
'configured fetch updates tracking' '
326 git branch -f side &&
329 o=$(git rev-parse --verify refs/remotes/origin/master) &&
331 n=$(git rev-parse --verify refs/remotes/origin/master) &&
333 git rev-parse --verify refs/remotes/origin/side
337 test_expect_success
'pushing nonexistent branch by mistake should not segv' '
340 test_must_fail git push seven no:no
344 test_expect_success
'auto tag following fetches minimum' '
347 git clone .git follow &&
348 git checkout HEAD^0 &&
350 for i in 1 2 3 4 5 6 7
353 git commit -m $i -a &&
354 git tag -a -m $i excess-$i || exit 1
357 git checkout master &&
364 test_expect_success
'refuse to fetch into the current branch' '
366 test_must_fail git fetch . side:master
370 test_expect_success
'fetch into the current branch with --update-head-ok' '
372 git fetch --update-head-ok . side:master
376 test_expect_success
'fetch --dry-run' '
378 rm -f .git/FETCH_HEAD &&
379 git fetch --dry-run . &&
380 ! test -f .git/FETCH_HEAD
383 test_expect_success
"should be able to fetch with duplicate refspecs" '
387 git config branch.master.remote three &&
388 git config remote.three.url ../three/.git &&
389 git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
390 git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&