]>
Commit | Line | Data |
---|---|---|
7be1d62c JH |
1 | #!/bin/sh |
2 | # Copyright (c) 2006, Junio C Hamano. | |
3 | ||
4 | test_description='Per branch config variables affects "git fetch". | |
5 | ||
6 | ' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
10 | D=`pwd` | |
11 | ||
2e674a9d JH |
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 | } | |
16 | ||
7be1d62c JH |
17 | test_expect_success setup ' |
18 | echo >file original && | |
19 | git add file && | |
20 | git commit -a -m original' | |
21 | ||
22 | test_expect_success "clone and setup child repos" ' | |
23 | git clone . one && | |
18a82692 JN |
24 | ( |
25 | cd one && | |
26 | echo >file updated by one && | |
27 | git commit -a -m "updated by one" | |
fd4ec4f2 | 28 | ) && |
7be1d62c | 29 | git clone . two && |
18a82692 JN |
30 | ( |
31 | cd two && | |
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 | |
fd4ec4f2 | 35 | ) && |
6cc7c36d | 36 | git clone . three && |
18a82692 JN |
37 | ( |
38 | cd three && | |
39 | git config branch.master.remote two && | |
40 | git config branch.master.merge refs/heads/one && | |
41 | mkdir -p .git/remotes && | |
42 | { | |
43 | echo "URL: ../two/.git/" | |
44 | echo "Pull: refs/heads/master:refs/heads/two" | |
45 | echo "Pull: refs/heads/one:refs/heads/one" | |
46 | } >.git/remotes/two | |
fd4ec4f2 | 47 | ) && |
9a7bbd1d JK |
48 | git clone . bundle && |
49 | git clone . seven | |
7be1d62c JH |
50 | ' |
51 | ||
52 | test_expect_success "fetch test" ' | |
53 | cd "$D" && | |
54 | echo >file updated by origin && | |
55 | git commit -a -m "updated by origin" && | |
56 | cd two && | |
57 | git fetch && | |
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" | |
62 | ' | |
63 | ||
6cc7c36d SB |
64 | test_expect_success "fetch test for-merge" ' |
65 | cd "$D" && | |
66 | cd three && | |
67 | git fetch && | |
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` && | |
72 | { | |
73 | echo "$master_in_two not-for-merge" | |
74 | echo "$one_in_two " | |
75 | } >expected && | |
76 | cut -f -2 .git/FETCH_HEAD >actual && | |
4fdf71be | 77 | test_cmp expected actual' |
6cc7c36d | 78 | |
f539d0d6 VJ |
79 | test_expect_success 'fetch tags when there is no tags' ' |
80 | ||
81 | cd "$D" && | |
82 | ||
83 | mkdir notags && | |
84 | cd notags && | |
85 | git init && | |
86 | ||
87 | git fetch -t .. | |
88 | ||
89 | ' | |
90 | ||
6c96c0f1 JH |
91 | test_expect_success 'fetch following tags' ' |
92 | ||
93 | cd "$D" && | |
94 | git tag -a -m 'annotated' anno HEAD && | |
95 | git tag light HEAD && | |
96 | ||
97 | mkdir four && | |
98 | cd four && | |
5c94f87e | 99 | git init && |
6c96c0f1 JH |
100 | |
101 | git fetch .. :track && | |
102 | git show-ref --verify refs/tags/anno && | |
103 | git show-ref --verify refs/tags/light | |
104 | ||
105 | ' | |
106 | ||
41ac414e | 107 | test_expect_success 'fetch must not resolve short tag name' ' |
605b4978 SP |
108 | |
109 | cd "$D" && | |
110 | ||
111 | mkdir five && | |
112 | cd five && | |
113 | git init && | |
114 | ||
d492b31c | 115 | test_must_fail git fetch .. anno:five |
605b4978 SP |
116 | |
117 | ' | |
118 | ||
41ac414e | 119 | test_expect_success 'fetch must not resolve short remote name' ' |
605b4978 SP |
120 | |
121 | cd "$D" && | |
a48fcd83 | 122 | git update-ref refs/remotes/six/HEAD HEAD && |
605b4978 SP |
123 | |
124 | mkdir six && | |
125 | cd six && | |
126 | git init && | |
127 | ||
d492b31c | 128 | test_must_fail git fetch .. six:six |
605b4978 SP |
129 | |
130 | ' | |
131 | ||
2e0afafe JS |
132 | test_expect_success 'create bundle 1' ' |
133 | cd "$D" && | |
134 | echo >file updated again by origin && | |
135 | git commit -a -m "tip" && | |
136 | git bundle create bundle1 master^..master | |
137 | ' | |
138 | ||
8315588b JS |
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 "^$" | |
144 | ' | |
145 | ||
2e0afafe JS |
146 | test_expect_success 'create bundle 2' ' |
147 | cd "$D" && | |
148 | git bundle create bundle2 master~2..master | |
149 | ' | |
150 | ||
41ac414e | 151 | test_expect_success 'unbundle 1' ' |
2e0afafe JS |
152 | cd "$D/bundle" && |
153 | git checkout -b some-branch && | |
d492b31c | 154 | test_must_fail git fetch "$D/bundle1" master:master |
2e0afafe JS |
155 | ' |
156 | ||
2e674a9d | 157 | |
8315588b JS |
158 | test_expect_success 'bundle 1 has only 3 files ' ' |
159 | cd "$D" && | |
160 | ( | |
161 | while read x && test -n "$x" | |
162 | do | |
163 | :; | |
164 | done | |
165 | cat | |
166 | ) <bundle1 >bundle.pack && | |
167 | git index-pack bundle.pack && | |
2e674a9d | 168 | test_bundle_object_count bundle.pack 3 |
8315588b JS |
169 | ' |
170 | ||
2e0afafe JS |
171 | test_expect_success 'unbundle 2' ' |
172 | cd "$D/bundle" && | |
173 | git fetch ../bundle2 master:master && | |
174 | test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)" | |
175 | ' | |
176 | ||
18449ab0 JS |
177 | test_expect_success 'bundle does not prerequisite objects' ' |
178 | cd "$D" && | |
179 | touch file2 && | |
180 | git add file2 && | |
181 | git commit -m add.file2 file2 && | |
182 | git bundle create bundle3 -1 HEAD && | |
6016e35b SP |
183 | ( |
184 | while read x && test -n "$x" | |
185 | do | |
186 | :; | |
187 | done | |
188 | cat | |
189 | ) <bundle3 >bundle.pack && | |
18449ab0 | 190 | git index-pack bundle.pack && |
2e674a9d | 191 | test_bundle_object_count bundle.pack 3 |
18449ab0 JS |
192 | ' |
193 | ||
7fa8254f JH |
194 | test_expect_success 'bundle should be able to create a full history' ' |
195 | ||
196 | cd "$D" && | |
197 | git tag -a -m '1.0' v1.0 master && | |
198 | git bundle create bundle4 v1.0 | |
199 | ||
200 | ' | |
201 | ||
7efaeba2 JS |
202 | ! rsync --help > /dev/null 2> /dev/null && |
203 | say 'Skipping rsync tests because rsync was not found' || { | |
cd547b48 JS |
204 | test_expect_success 'fetch via rsync' ' |
205 | git pack-refs && | |
206 | mkdir rsynced && | |
7efaeba2 JS |
207 | (cd rsynced && |
208 | git init --bare && | |
209 | git fetch "rsync:$(pwd)/../.git" master:refs/heads/master && | |
210 | git gc --prune && | |
211 | test $(git rev-parse master) = $(cd .. && git rev-parse master) && | |
212 | git fsck --full) | |
cd547b48 JS |
213 | ' |
214 | ||
215 | test_expect_success 'push via rsync' ' | |
7efaeba2 JS |
216 | mkdir rsynced2 && |
217 | (cd rsynced2 && | |
cd547b48 | 218 | git init) && |
7efaeba2 JS |
219 | (cd rsynced && |
220 | git push "rsync:$(pwd)/../rsynced2/.git" master) && | |
221 | (cd rsynced2 && | |
222 | git gc --prune && | |
223 | test $(git rev-parse master) = $(cd .. && git rev-parse master) && | |
224 | git fsck --full) | |
cd547b48 JS |
225 | ' |
226 | ||
227 | test_expect_success 'push via rsync' ' | |
cd547b48 JS |
228 | mkdir rsynced3 && |
229 | (cd rsynced3 && | |
230 | git init) && | |
7efaeba2 JS |
231 | git push --all "rsync:$(pwd)/rsynced3/.git" && |
232 | (cd rsynced3 && | |
233 | test $(git rev-parse master) = $(cd .. && git rev-parse master) && | |
234 | git fsck --full) | |
cd547b48 JS |
235 | ' |
236 | } | |
237 | ||
da0204df JS |
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/*" && | |
243 | git fetch blub | |
244 | ' | |
245 | ||
042cca38 BC |
246 | # URL supplied to fetch does not match the url of the configured branch's remote |
247 | test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [1]' ' | |
248 | one_head=$(cd one && git rev-parse HEAD) && | |
249 | this_head=$(git rev-parse HEAD) && | |
6106ce46 BC |
250 | git update-ref -d FETCH_HEAD && |
251 | git fetch one && | |
042cca38 BC |
252 | test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && |
253 | test $this_head = "$(git rev-parse --verify HEAD)" | |
254 | ' | |
255 | ||
256 | # URL supplied to fetch matches the url of the configured branch's remote and | |
257 | # the merge spec matches the branch the remote HEAD points to | |
258 | test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [2]' ' | |
259 | one_ref=$(cd one && git symbolic-ref HEAD) && | |
260 | git config branch.master.remote blub && | |
261 | git config branch.master.merge "$one_ref" && | |
262 | git update-ref -d FETCH_HEAD && | |
263 | git fetch one && | |
264 | test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && | |
265 | test $this_head = "$(git rev-parse --verify HEAD)" | |
266 | ' | |
267 | ||
268 | # URL supplied to fetch matches the url of the configured branch's remote, but | |
269 | # the merge spec does not match the branch the remote HEAD points to | |
270 | test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [3]' ' | |
271 | git config branch.master.merge "${one_ref}_not" && | |
272 | git update-ref -d FETCH_HEAD && | |
273 | git fetch one && | |
274 | test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && | |
275 | test $this_head = "$(git rev-parse --verify HEAD)" | |
6106ce46 BC |
276 | ' |
277 | ||
c2015b3a JS |
278 | # the strange name is: a\!'b |
279 | test_expect_success 'quoting of a strangely named repo' ' | |
d492b31c | 280 | test_must_fail git fetch "a\\!'\''b" > result 2>&1 && |
c2015b3a JS |
281 | cat result && |
282 | grep "fatal: '\''a\\\\!'\''b'\''" result | |
283 | ' | |
284 | ||
c5546e88 JS |
285 | test_expect_success 'bundle should record HEAD correctly' ' |
286 | ||
287 | cd "$D" && | |
288 | git bundle create bundle5 HEAD master && | |
289 | git bundle list-heads bundle5 >actual && | |
290 | for h in HEAD refs/heads/master | |
291 | do | |
292 | echo "$(git rev-parse --verify $h) $h" | |
293 | done >expect && | |
82ebb0b6 | 294 | test_cmp expect actual |
c5546e88 JS |
295 | |
296 | ' | |
297 | ||
c7015961 JH |
298 | test_expect_success 'explicit fetch should not update tracking' ' |
299 | ||
300 | cd "$D" && | |
301 | git branch -f side && | |
302 | ( | |
303 | cd three && | |
304 | o=$(git rev-parse --verify refs/remotes/origin/master) && | |
305 | git fetch origin master && | |
306 | n=$(git rev-parse --verify refs/remotes/origin/master) && | |
307 | test "$o" = "$n" && | |
d492b31c | 308 | test_must_fail git rev-parse --verify refs/remotes/origin/side |
c7015961 JH |
309 | ) |
310 | ' | |
311 | ||
312 | test_expect_success 'explicit pull should not update tracking' ' | |
313 | ||
314 | cd "$D" && | |
315 | git branch -f side && | |
316 | ( | |
317 | cd three && | |
318 | o=$(git rev-parse --verify refs/remotes/origin/master) && | |
319 | git pull origin master && | |
320 | n=$(git rev-parse --verify refs/remotes/origin/master) && | |
321 | test "$o" = "$n" && | |
d492b31c | 322 | test_must_fail git rev-parse --verify refs/remotes/origin/side |
c7015961 JH |
323 | ) |
324 | ' | |
325 | ||
326 | test_expect_success 'configured fetch updates tracking' ' | |
327 | ||
328 | cd "$D" && | |
329 | git branch -f side && | |
330 | ( | |
331 | cd three && | |
332 | o=$(git rev-parse --verify refs/remotes/origin/master) && | |
333 | git fetch origin && | |
334 | n=$(git rev-parse --verify refs/remotes/origin/master) && | |
335 | test "$o" != "$n" && | |
336 | git rev-parse --verify refs/remotes/origin/side | |
337 | ) | |
338 | ' | |
339 | ||
9a7bbd1d JK |
340 | test_expect_success 'pushing nonexistent branch by mistake should not segv' ' |
341 | ||
342 | cd "$D" && | |
343 | test_must_fail git push seven no:no | |
344 | ||
345 | ' | |
346 | ||
49420252 JH |
347 | test_expect_success 'auto tag following fetches minimum' ' |
348 | ||
349 | cd "$D" && | |
350 | git clone .git follow && | |
351 | git checkout HEAD^0 && | |
352 | ( | |
353 | for i in 1 2 3 4 5 6 7 | |
354 | do | |
355 | echo $i >>file && | |
356 | git commit -m $i -a && | |
357 | git tag -a -m $i excess-$i || exit 1 | |
358 | done | |
359 | ) && | |
360 | git checkout master && | |
361 | ( | |
362 | cd follow && | |
363 | git fetch | |
364 | ) | |
365 | ' | |
366 | ||
8ee5d731 JS |
367 | test_expect_success 'refuse to fetch into the current branch' ' |
368 | ||
369 | test_must_fail git fetch . side:master | |
370 | ||
371 | ' | |
372 | ||
373 | test_expect_success 'fetch into the current branch with --update-head-ok' ' | |
374 | ||
375 | git fetch --update-head-ok . side:master | |
376 | ||
377 | ' | |
378 | ||
3fdcdbdf JS |
379 | test_expect_success 'fetch --dry-run' ' |
380 | ||
381 | rm -f .git/FETCH_HEAD && | |
382 | git fetch --dry-run . && | |
383 | ! test -f .git/FETCH_HEAD | |
384 | ' | |
385 | ||
95c96d48 JP |
386 | test_expect_success "should be able to fetch with duplicate refspecs" ' |
387 | mkdir dups && | |
388 | cd dups && | |
389 | git init && | |
390 | git config branch.master.remote three && | |
391 | git config remote.three.url ../three/.git && | |
392 | git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* && | |
393 | git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* && | |
394 | git fetch three | |
395 | ' | |
396 | ||
7be1d62c | 397 | test_done |