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 tags when there is no tags' '
91 test_expect_success 'fetch following tags' '
94 git tag -a -m 'annotated' anno HEAD &&
101 git fetch .. :track &&
102 git show-ref --verify refs/tags/anno &&
103 git show-ref --verify refs/tags/light
107 test_expect_success 'fetch must not resolve short tag name' '
115 test_must_fail git fetch .. anno:five
119 test_expect_success 'fetch must not resolve short remote name' '
122 git update-ref refs/remotes/six/HEAD HEAD
128 test_must_fail git fetch .. six:six
132 test_expect_success 'create bundle 1' '
134 echo >file updated again by origin &&
135 git commit -a -m "tip" &&
136 git bundle create bundle1 master^..master
139 test_expect_success 'header of bundle looks right' '
140 head -n 1 "$D"/bundle1 | grep "^#" &&
141 head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
142 head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
143 head -n 4 "$D"/bundle1 | grep "^$"
146 test_expect_success 'create bundle 2' '
148 git bundle create bundle2 master~2..master
151 test_expect_success 'unbundle 1' '
153 git checkout -b some-branch &&
154 test_must_fail git fetch "$D/bundle1" master:master
158 test_expect_success 'bundle 1 has only 3 files ' '
161 while read x && test -n "$x"
166 ) <bundle1 >bundle.pack &&
167 git index-pack bundle.pack &&
168 test_bundle_object_count bundle.pack 3
171 test_expect_success 'unbundle 2' '
173 git fetch ../bundle2 master:master &&
174 test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
177 test_expect_success 'bundle does not prerequisite objects' '
181 git commit -m add.file2 file2 &&
182 git bundle create bundle3 -1 HEAD &&
184 while read x && test -n "$x"
189 ) <bundle3 >bundle.pack &&
190 git index-pack bundle.pack &&
191 test_bundle_object_count bundle.pack 3
194 test_expect_success 'bundle should be able to create a full history' '
197 git tag -a -m '1.0' v1.0 master &&
198 git bundle create bundle4 v1.0
202 ! rsync --help > /dev/null 2> /dev/null &&
203 say 'Skipping rsync tests because rsync was not found' || {
204 test_expect_success 'fetch via rsync' '
209 git fetch "rsync:$(pwd)/../.git" master:refs/heads/master &&
211 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
215 test_expect_success 'push via rsync' '
220 git push "rsync:$(pwd)/../rsynced2/.git" master) &&
223 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
227 test_expect_success 'push via rsync' '
231 git push --all "rsync:$(pwd)/rsynced3/.git" &&
233 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
238 test_expect_success 'fetch with a non-applying branch.<name>.merge' '
239 git config branch.master.remote yeti &&
240 git config branch.master.merge refs/heads/bigfoot &&
241 git config remote.blub.url one &&
242 git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
246 # the strange name is: a\!'b
247 test_expect_success 'quoting of a strangely named repo' '
248 test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
250 grep "fatal: '\''a\\\\!'\''b'\''" result
253 test_expect_success 'bundle should record HEAD correctly' '
256 git bundle create bundle5 HEAD master &&
257 git bundle list-heads bundle5 >actual &&
258 for h in HEAD refs/heads/master
260 echo "$(git rev-parse --verify $h) $h"
262 test_cmp expect actual
266 test_expect_success 'explicit fetch should not update tracking' '
269 git branch -f side &&
272 o=$(git rev-parse --verify refs/remotes/origin/master) &&
273 git fetch origin master &&
274 n=$(git rev-parse --verify refs/remotes/origin/master) &&
276 test_must_fail git rev-parse --verify refs/remotes/origin/side
280 test_expect_success 'explicit pull should not update tracking' '
283 git branch -f side &&
286 o=$(git rev-parse --verify refs/remotes/origin/master) &&
287 git pull origin master &&
288 n=$(git rev-parse --verify refs/remotes/origin/master) &&
290 test_must_fail git rev-parse --verify refs/remotes/origin/side
294 test_expect_success 'configured fetch updates tracking' '
297 git branch -f side &&
300 o=$(git rev-parse --verify refs/remotes/origin/master) &&
302 n=$(git rev-parse --verify refs/remotes/origin/master) &&
304 git rev-parse --verify refs/remotes/origin/side
308 test_expect_success 'pushing nonexistent branch by mistake should not segv' '
311 test_must_fail git push seven no:no
315 test_expect_success 'auto tag following fetches minimum' '
318 git clone .git follow &&
319 git checkout HEAD^0 &&
321 for i in 1 2 3 4 5 6 7
324 git commit -m $i -a &&
325 git tag -a -m $i excess-$i || exit 1
328 git checkout master &&
335 test_expect_success 'refuse to fetch into the current branch' '
337 test_must_fail git fetch . side:master
341 test_expect_success 'fetch into the current branch with --update-head-ok' '
343 git fetch --update-head-ok . side:master
347 test_expect_success 'fetch --dry-run' '
349 rm -f .git/FETCH_HEAD &&
350 git fetch --dry-run . &&
351 ! test -f .git/FETCH_HEAD
354 test_expect_success "should be able to fetch with duplicate refspecs" '
358 git config branch.master.remote three &&
359 git config remote.three.url ../three/.git &&
360 git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
361 git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&