2 # Copyright (c) 2006, Junio C Hamano.
4 test_description
='Per branch config variables affects "git fetch".
12 test_expect_success setup
'
13 echo >file original &&
15 git commit -a -m original'
17 test_expect_success
"clone and setup child repos" '
20 echo >file updated by one &&
21 git commit -a -m "updated by one" &&
25 git config branch.master.remote one &&
26 git config remote.one.url ../one/.git/ &&
27 git config remote.one.fetch refs/heads/master:refs/heads/one &&
31 git config branch.master.remote two &&
32 git config branch.master.merge refs/heads/one &&
33 mkdir -p .git/remotes &&
35 echo "URL: ../two/.git/"
36 echo "Pull: refs/heads/master:refs/heads/two"
37 echo "Pull: refs/heads/one:refs/heads/one"
38 } >.git/remotes/two &&
44 test_expect_success
"fetch test" '
46 echo >file updated by origin &&
47 git commit -a -m "updated by origin" &&
50 test -f .git/refs/heads/one &&
51 mine=`git rev-parse refs/heads/one` &&
52 his=`cd ../one && git rev-parse refs/heads/master` &&
53 test "z$mine" = "z$his"
56 test_expect_success
"fetch test for-merge" '
60 test -f .git/refs/heads/two &&
61 test -f .git/refs/heads/one &&
62 master_in_two=`cd ../two && git rev-parse master` &&
63 one_in_two=`cd ../two && git rev-parse one` &&
65 echo "$master_in_two not-for-merge"
68 cut -f -2 .git/FETCH_HEAD >actual &&
71 test_expect_success
'fetch tags when there is no tags' '
83 test_expect_success
'fetch following tags' '
86 git tag -a -m 'annotated
' anno HEAD &&
93 git fetch .. :track &&
94 git show-ref --verify refs/tags/anno &&
95 git show-ref --verify refs/tags/light
99 test_expect_success
'fetch must not resolve short tag name' '
107 test_must_fail git fetch .. anno:five
111 test_expect_success
'fetch must not resolve short remote name' '
114 git update-ref refs/remotes/six/HEAD HEAD
120 test_must_fail git fetch .. six:six
124 test_expect_success
'create bundle 1' '
126 echo >file updated again by origin &&
127 git commit -a -m "tip" &&
128 git bundle create bundle1 master^..master
131 test_expect_success
'header of bundle looks right' '
132 head -n 1 "$D"/bundle1 | grep "^#" &&
133 head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
134 head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
135 head -n 4 "$D"/bundle1 | grep "^$"
138 test_expect_success
'create bundle 2' '
140 git bundle create bundle2 master~2..master
143 test_expect_success
'unbundle 1' '
145 git checkout -b some-branch &&
146 test_must_fail git fetch "$D/bundle1" master:master
149 test_expect_success
'bundle 1 has only 3 files ' '
152 while read x && test -n "$x"
157 ) <bundle1 >bundle.pack &&
158 git index-pack bundle.pack &&
159 verify=$(git verify-pack -v bundle.pack) &&
160 test 4 = $(echo "$verify" | wc -l)
163 test_expect_success
'unbundle 2' '
165 git fetch ../bundle2 master:master &&
166 test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
169 test_expect_success
'bundle does not prerequisite objects' '
173 git commit -m add.file2 file2 &&
174 git bundle create bundle3 -1 HEAD &&
176 while read x && test -n "$x"
181 ) <bundle3 >bundle.pack &&
182 git index-pack bundle.pack &&
183 test 4 = $(git verify-pack -v bundle.pack | wc -l)
186 test_expect_success
'bundle should be able to create a full history' '
189 git tag -a -m '1.0' v1.0 master &&
190 git bundle create bundle4 v1.0
194 ! rsync
--help > /dev
/null
2> /dev
/null
&&
195 say
'Skipping rsync tests because rsync was not found' ||
{
196 test_expect_success
'fetch via rsync' '
201 git fetch "rsync:$(pwd)/../.git" master:refs/heads/master &&
203 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
207 test_expect_success
'push via rsync' '
212 git push "rsync:$(pwd)/../rsynced2/.git" master) &&
215 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
219 test_expect_success
'push via rsync' '
223 git push --all "rsync:$(pwd)/rsynced3/.git" &&
225 test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
230 test_expect_success
'fetch with a non-applying branch.<name>.merge' '
231 git config branch.master.remote yeti &&
232 git config branch.master.merge refs/heads/bigfoot &&
233 git config remote.blub.url one &&
234 git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
238 # the strange name is: a\!'b
239 test_expect_success
'quoting of a strangely named repo' '
240 test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
242 grep "fatal: '\''a\\\\!'\''b'\''" result
245 test_expect_success
'bundle should record HEAD correctly' '
248 git bundle create bundle5 HEAD master &&
249 git bundle list-heads bundle5 >actual &&
250 for h in HEAD refs/heads/master
252 echo "$(git rev-parse --verify $h) $h"
254 test_cmp expect actual
258 test_expect_success
'explicit fetch should not update tracking' '
261 git branch -f side &&
264 o=$(git rev-parse --verify refs/remotes/origin/master) &&
265 git fetch origin master &&
266 n=$(git rev-parse --verify refs/remotes/origin/master) &&
268 test_must_fail git rev-parse --verify refs/remotes/origin/side
272 test_expect_success
'explicit pull should not update tracking' '
275 git branch -f side &&
278 o=$(git rev-parse --verify refs/remotes/origin/master) &&
279 git pull origin master &&
280 n=$(git rev-parse --verify refs/remotes/origin/master) &&
282 test_must_fail git rev-parse --verify refs/remotes/origin/side
286 test_expect_success
'configured fetch updates tracking' '
289 git branch -f side &&
292 o=$(git rev-parse --verify refs/remotes/origin/master) &&
294 n=$(git rev-parse --verify refs/remotes/origin/master) &&
296 git rev-parse --verify refs/remotes/origin/side
300 test_expect_success
'pushing nonexistent branch by mistake should not segv' '
303 test_must_fail git push seven no:no
307 test_expect_success
'auto tag following fetches minimum' '
310 git clone .git follow &&
311 git checkout HEAD^0 &&
313 for i in 1 2 3 4 5 6 7
316 git commit -m $i -a &&
317 git tag -a -m $i excess-$i || exit 1
320 git checkout master &&
327 test_expect_success
'refuse to fetch into the current branch' '
329 test_must_fail git fetch . side:master
333 test_expect_success
'fetch into the current branch with --update-head-ok' '
335 git fetch --update-head-ok . side:master