]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5510-fetch.sh
Merge branch 'ma/test-cleanup'
[thirdparty/git.git] / t / t5510-fetch.sh
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
12 test_bundle_object_count () {
13 git verify-pack -v "$1" >verify.out &&
14 test "$2" = $(grep "^$OID_REGEX " verify.out | wc -l)
15 }
16
17 convert_bundle_to_pack () {
18 while read x && test -n "$x"
19 do
20 :;
21 done
22 cat
23 }
24
25 test_expect_success setup '
26 echo >file original &&
27 git add file &&
28 git commit -a -m original'
29
30 test_expect_success "clone and setup child repos" '
31 git clone . one &&
32 (
33 cd one &&
34 echo >file updated by one &&
35 git commit -a -m "updated by one"
36 ) &&
37 git clone . two &&
38 (
39 cd two &&
40 git config branch.master.remote one &&
41 git config remote.one.url ../one/.git/ &&
42 git config remote.one.fetch refs/heads/master:refs/heads/one
43 ) &&
44 git clone . three &&
45 (
46 cd three &&
47 git config branch.master.remote two &&
48 git config branch.master.merge refs/heads/one &&
49 mkdir -p .git/remotes &&
50 {
51 echo "URL: ../two/.git/"
52 echo "Pull: refs/heads/master:refs/heads/two"
53 echo "Pull: refs/heads/one:refs/heads/one"
54 } >.git/remotes/two
55 ) &&
56 git clone . bundle &&
57 git clone . seven
58 '
59
60 test_expect_success "fetch test" '
61 cd "$D" &&
62 echo >file updated by origin &&
63 git commit -a -m "updated by origin" &&
64 cd two &&
65 git fetch &&
66 git rev-parse --verify refs/heads/one &&
67 mine=$(git rev-parse refs/heads/one) &&
68 his=$(cd ../one && git rev-parse refs/heads/master) &&
69 test "z$mine" = "z$his"
70 '
71
72 test_expect_success "fetch test for-merge" '
73 cd "$D" &&
74 cd three &&
75 git fetch &&
76 git rev-parse --verify refs/heads/two &&
77 git rev-parse --verify refs/heads/one &&
78 master_in_two=$(cd ../two && git rev-parse master) &&
79 one_in_two=$(cd ../two && git rev-parse one) &&
80 {
81 echo "$one_in_two "
82 echo "$master_in_two not-for-merge"
83 } >expected &&
84 cut -f -2 .git/FETCH_HEAD >actual &&
85 test_cmp expected actual'
86
87 test_expect_success 'fetch --prune on its own works as expected' '
88 cd "$D" &&
89 git clone . prune &&
90 cd prune &&
91 git update-ref refs/remotes/origin/extrabranch master &&
92
93 git fetch --prune origin &&
94 test_must_fail git rev-parse origin/extrabranch
95 '
96
97 test_expect_success 'fetch --prune with a branch name keeps branches' '
98 cd "$D" &&
99 git clone . prune-branch &&
100 cd prune-branch &&
101 git update-ref refs/remotes/origin/extrabranch master &&
102
103 git fetch --prune origin master &&
104 git rev-parse origin/extrabranch
105 '
106
107 test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
108 cd "$D" &&
109 git clone . prune-namespace &&
110 cd prune-namespace &&
111
112 git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
113 git rev-parse origin/master
114 '
115
116 test_expect_success 'fetch --prune handles overlapping refspecs' '
117 cd "$D" &&
118 git update-ref refs/pull/42/head master &&
119 git clone . prune-overlapping &&
120 cd prune-overlapping &&
121 git config --add remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
122
123 git fetch --prune origin &&
124 git rev-parse origin/master &&
125 git rev-parse origin/pr/42 &&
126
127 git config --unset-all remote.origin.fetch &&
128 git config remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
129 git config --add remote.origin.fetch refs/heads/*:refs/remotes/origin/* &&
130
131 git fetch --prune origin &&
132 git rev-parse origin/master &&
133 git rev-parse origin/pr/42
134 '
135
136 test_expect_success 'fetch --prune --tags prunes branches but not tags' '
137 cd "$D" &&
138 git clone . prune-tags &&
139 cd prune-tags &&
140 git tag sometag master &&
141 # Create what looks like a remote-tracking branch from an earlier
142 # fetch that has since been deleted from the remote:
143 git update-ref refs/remotes/origin/fake-remote master &&
144
145 git fetch --prune --tags origin &&
146 git rev-parse origin/master &&
147 test_must_fail git rev-parse origin/fake-remote &&
148 git rev-parse sometag
149 '
150
151 test_expect_success 'fetch --prune --tags with branch does not prune other things' '
152 cd "$D" &&
153 git clone . prune-tags-branch &&
154 cd prune-tags-branch &&
155 git tag sometag master &&
156 git update-ref refs/remotes/origin/extrabranch master &&
157
158 git fetch --prune --tags origin master &&
159 git rev-parse origin/extrabranch &&
160 git rev-parse sometag
161 '
162
163 test_expect_success 'fetch --prune --tags with refspec prunes based on refspec' '
164 cd "$D" &&
165 git clone . prune-tags-refspec &&
166 cd prune-tags-refspec &&
167 git tag sometag master &&
168 git update-ref refs/remotes/origin/foo/otherbranch master &&
169 git update-ref refs/remotes/origin/extrabranch master &&
170
171 git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
172 test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
173 git rev-parse origin/extrabranch &&
174 git rev-parse sometag
175 '
176
177 test_expect_success '--refmap="" ignores configured refspec' '
178 cd "$TRASH_DIRECTORY" &&
179 git clone "$D" remote-refs &&
180 git -C remote-refs rev-parse remotes/origin/master >old &&
181 git -C remote-refs update-ref refs/remotes/origin/master master~1 &&
182 git -C remote-refs rev-parse remotes/origin/master >new &&
183 git -C remote-refs fetch --refmap= origin "+refs/heads/*:refs/hidden/origin/*" &&
184 git -C remote-refs rev-parse remotes/origin/master >actual &&
185 test_cmp new actual &&
186 git -C remote-refs fetch origin &&
187 git -C remote-refs rev-parse remotes/origin/master >actual &&
188 test_cmp old actual
189 '
190
191 test_expect_success '--refmap="" and --prune' '
192 git -C remote-refs update-ref refs/remotes/origin/foo/otherbranch master &&
193 git -C remote-refs update-ref refs/hidden/foo/otherbranch master &&
194 git -C remote-refs fetch --prune --refmap="" origin +refs/heads/*:refs/hidden/* &&
195 git -C remote-refs rev-parse remotes/origin/foo/otherbranch &&
196 test_must_fail git -C remote-refs rev-parse refs/hidden/foo/otherbranch &&
197 git -C remote-refs fetch --prune origin &&
198 test_must_fail git -C remote-refs rev-parse remotes/origin/foo/otherbranch
199 '
200
201 test_expect_success 'fetch tags when there is no tags' '
202
203 cd "$D" &&
204
205 mkdir notags &&
206 cd notags &&
207 git init &&
208
209 git fetch -t ..
210
211 '
212
213 test_expect_success 'fetch following tags' '
214
215 cd "$D" &&
216 git tag -a -m 'annotated' anno HEAD &&
217 git tag light HEAD &&
218
219 mkdir four &&
220 cd four &&
221 git init &&
222
223 git fetch .. :track &&
224 git show-ref --verify refs/tags/anno &&
225 git show-ref --verify refs/tags/light
226
227 '
228
229 test_expect_success 'fetch uses remote ref names to describe new refs' '
230 cd "$D" &&
231 git init descriptive &&
232 (
233 cd descriptive &&
234 git config remote.o.url .. &&
235 git config remote.o.fetch "refs/heads/*:refs/crazyheads/*" &&
236 git config --add remote.o.fetch "refs/others/*:refs/heads/*" &&
237 git fetch o
238 ) &&
239 git tag -a -m "Descriptive tag" descriptive-tag &&
240 git branch descriptive-branch &&
241 git checkout descriptive-branch &&
242 echo "Nuts" >crazy &&
243 git add crazy &&
244 git commit -a -m "descriptive commit" &&
245 git update-ref refs/others/crazy HEAD &&
246 (
247 cd descriptive &&
248 git fetch o 2>actual &&
249 test_i18ngrep "new branch.* -> refs/crazyheads/descriptive-branch$" actual &&
250 test_i18ngrep "new tag.* -> descriptive-tag$" actual &&
251 test_i18ngrep "new ref.* -> crazy$" actual
252 ) &&
253 git checkout master
254 '
255
256 test_expect_success 'fetch must not resolve short tag name' '
257
258 cd "$D" &&
259
260 mkdir five &&
261 cd five &&
262 git init &&
263
264 test_must_fail git fetch .. anno:five
265
266 '
267
268 test_expect_success 'fetch can now resolve short remote name' '
269
270 cd "$D" &&
271 git update-ref refs/remotes/six/HEAD HEAD &&
272
273 mkdir six &&
274 cd six &&
275 git init &&
276
277 git fetch .. six:six
278 '
279
280 test_expect_success 'create bundle 1' '
281 cd "$D" &&
282 echo >file updated again by origin &&
283 git commit -a -m "tip" &&
284 git bundle create bundle1 master^..master
285 '
286
287 test_expect_success 'header of bundle looks right' '
288 head -n 4 "$D"/bundle1 &&
289 head -n 1 "$D"/bundle1 | grep "^#" &&
290 head -n 2 "$D"/bundle1 | grep "^-$OID_REGEX " &&
291 head -n 3 "$D"/bundle1 | grep "^$OID_REGEX " &&
292 head -n 4 "$D"/bundle1 | grep "^$"
293 '
294
295 test_expect_success 'create bundle 2' '
296 cd "$D" &&
297 git bundle create bundle2 master~2..master
298 '
299
300 test_expect_success 'unbundle 1' '
301 cd "$D/bundle" &&
302 git checkout -b some-branch &&
303 test_must_fail git fetch "$D/bundle1" master:master
304 '
305
306
307 test_expect_success 'bundle 1 has only 3 files ' '
308 cd "$D" &&
309 convert_bundle_to_pack <bundle1 >bundle.pack &&
310 git index-pack bundle.pack &&
311 test_bundle_object_count bundle.pack 3
312 '
313
314 test_expect_success 'unbundle 2' '
315 cd "$D/bundle" &&
316 git fetch ../bundle2 master:master &&
317 test "tip" = "$(git log -1 --pretty=oneline master | cut -d" " -f2)"
318 '
319
320 test_expect_success 'bundle does not prerequisite objects' '
321 cd "$D" &&
322 touch file2 &&
323 git add file2 &&
324 git commit -m add.file2 file2 &&
325 git bundle create bundle3 -1 HEAD &&
326 convert_bundle_to_pack <bundle3 >bundle.pack &&
327 git index-pack bundle.pack &&
328 test_bundle_object_count bundle.pack 3
329 '
330
331 test_expect_success 'bundle should be able to create a full history' '
332
333 cd "$D" &&
334 git tag -a -m '1.0' v1.0 master &&
335 git bundle create bundle4 v1.0
336
337 '
338
339 test_expect_success 'fetch with a non-applying branch.<name>.merge' '
340 git config branch.master.remote yeti &&
341 git config branch.master.merge refs/heads/bigfoot &&
342 git config remote.blub.url one &&
343 git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
344 git fetch blub
345 '
346
347 # URL supplied to fetch does not match the url of the configured branch's remote
348 test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
349 one_head=$(cd one && git rev-parse HEAD) &&
350 this_head=$(git rev-parse HEAD) &&
351 git update-ref -d FETCH_HEAD &&
352 git fetch one &&
353 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
354 test $this_head = "$(git rev-parse --verify HEAD)"
355 '
356
357 # URL supplied to fetch matches the url of the configured branch's remote and
358 # the merge spec matches the branch the remote HEAD points to
359 test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [2]' '
360 one_ref=$(cd one && git symbolic-ref HEAD) &&
361 git config branch.master.remote blub &&
362 git config branch.master.merge "$one_ref" &&
363 git update-ref -d FETCH_HEAD &&
364 git fetch one &&
365 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
366 test $this_head = "$(git rev-parse --verify HEAD)"
367 '
368
369 # URL supplied to fetch matches the url of the configured branch's remote, but
370 # the merge spec does not match the branch the remote HEAD points to
371 test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
372 git config branch.master.merge "${one_ref}_not" &&
373 git update-ref -d FETCH_HEAD &&
374 git fetch one &&
375 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
376 test $this_head = "$(git rev-parse --verify HEAD)"
377 '
378
379 # the strange name is: a\!'b
380 test_expect_success 'quoting of a strangely named repo' '
381 test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
382 grep "fatal: '\''a\\\\!'\''b'\''" result
383 '
384
385 test_expect_success 'bundle should record HEAD correctly' '
386
387 cd "$D" &&
388 git bundle create bundle5 HEAD master &&
389 git bundle list-heads bundle5 >actual &&
390 for h in HEAD refs/heads/master
391 do
392 echo "$(git rev-parse --verify $h) $h"
393 done >expect &&
394 test_cmp expect actual
395
396 '
397
398 test_expect_success 'mark initial state of origin/master' '
399 (
400 cd three &&
401 git tag base-origin-master refs/remotes/origin/master
402 )
403 '
404
405 test_expect_success 'explicit fetch should update tracking' '
406
407 cd "$D" &&
408 git branch -f side &&
409 (
410 cd three &&
411 git update-ref refs/remotes/origin/master base-origin-master &&
412 o=$(git rev-parse --verify refs/remotes/origin/master) &&
413 git fetch origin master &&
414 n=$(git rev-parse --verify refs/remotes/origin/master) &&
415 test "$o" != "$n" &&
416 test_must_fail git rev-parse --verify refs/remotes/origin/side
417 )
418 '
419
420 test_expect_success 'explicit pull should update tracking' '
421
422 cd "$D" &&
423 git branch -f side &&
424 (
425 cd three &&
426 git update-ref refs/remotes/origin/master base-origin-master &&
427 o=$(git rev-parse --verify refs/remotes/origin/master) &&
428 git pull origin master &&
429 n=$(git rev-parse --verify refs/remotes/origin/master) &&
430 test "$o" != "$n" &&
431 test_must_fail git rev-parse --verify refs/remotes/origin/side
432 )
433 '
434
435 test_expect_success 'explicit --refmap is allowed only with command-line refspec' '
436 cd "$D" &&
437 (
438 cd three &&
439 test_must_fail git fetch --refmap="*:refs/remotes/none/*"
440 )
441 '
442
443 test_expect_success 'explicit --refmap option overrides remote.*.fetch' '
444 cd "$D" &&
445 git branch -f side &&
446 (
447 cd three &&
448 git update-ref refs/remotes/origin/master base-origin-master &&
449 o=$(git rev-parse --verify refs/remotes/origin/master) &&
450 git fetch --refmap="refs/heads/*:refs/remotes/other/*" origin master &&
451 n=$(git rev-parse --verify refs/remotes/origin/master) &&
452 test "$o" = "$n" &&
453 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
454 git rev-parse --verify refs/remotes/other/master
455 )
456 '
457
458 test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' '
459 cd "$D" &&
460 git branch -f side &&
461 (
462 cd three &&
463 git update-ref refs/remotes/origin/master base-origin-master &&
464 o=$(git rev-parse --verify refs/remotes/origin/master) &&
465 git fetch --refmap="" origin master &&
466 n=$(git rev-parse --verify refs/remotes/origin/master) &&
467 test "$o" = "$n" &&
468 test_must_fail git rev-parse --verify refs/remotes/origin/side
469 )
470 '
471
472 test_expect_success 'configured fetch updates tracking' '
473
474 cd "$D" &&
475 git branch -f side &&
476 (
477 cd three &&
478 git update-ref refs/remotes/origin/master base-origin-master &&
479 o=$(git rev-parse --verify refs/remotes/origin/master) &&
480 git fetch origin &&
481 n=$(git rev-parse --verify refs/remotes/origin/master) &&
482 test "$o" != "$n" &&
483 git rev-parse --verify refs/remotes/origin/side
484 )
485 '
486
487 test_expect_success 'non-matching refspecs do not confuse tracking update' '
488 cd "$D" &&
489 git update-ref refs/odd/location HEAD &&
490 (
491 cd three &&
492 git update-ref refs/remotes/origin/master base-origin-master &&
493 git config --add remote.origin.fetch \
494 refs/odd/location:refs/remotes/origin/odd &&
495 o=$(git rev-parse --verify refs/remotes/origin/master) &&
496 git fetch origin master &&
497 n=$(git rev-parse --verify refs/remotes/origin/master) &&
498 test "$o" != "$n" &&
499 test_must_fail git rev-parse --verify refs/remotes/origin/odd
500 )
501 '
502
503 test_expect_success 'pushing nonexistent branch by mistake should not segv' '
504
505 cd "$D" &&
506 test_must_fail git push seven no:no
507
508 '
509
510 test_expect_success 'auto tag following fetches minimum' '
511
512 cd "$D" &&
513 git clone .git follow &&
514 git checkout HEAD^0 &&
515 (
516 for i in 1 2 3 4 5 6 7
517 do
518 echo $i >>file &&
519 git commit -m $i -a &&
520 git tag -a -m $i excess-$i || exit 1
521 done
522 ) &&
523 git checkout master &&
524 (
525 cd follow &&
526 git fetch
527 )
528 '
529
530 test_expect_success 'refuse to fetch into the current branch' '
531
532 test_must_fail git fetch . side:master
533
534 '
535
536 test_expect_success 'fetch into the current branch with --update-head-ok' '
537
538 git fetch --update-head-ok . side:master
539
540 '
541
542 test_expect_success 'fetch --dry-run' '
543
544 rm -f .git/FETCH_HEAD &&
545 git fetch --dry-run . &&
546 ! test -f .git/FETCH_HEAD
547 '
548
549 test_expect_success "should be able to fetch with duplicate refspecs" '
550 mkdir dups &&
551 (
552 cd dups &&
553 git init &&
554 git config branch.master.remote three &&
555 git config remote.three.url ../three/.git &&
556 git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
557 git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
558 git fetch three
559 )
560 '
561
562 test_expect_success 'LHS of refspec follows ref disambiguation rules' '
563 mkdir lhs-ambiguous &&
564 (
565 cd lhs-ambiguous &&
566 git init server &&
567 test_commit -C server unwanted &&
568 test_commit -C server wanted &&
569
570 git init client &&
571
572 # Check a name coming after "refs" alphabetically ...
573 git -C server update-ref refs/heads/s wanted &&
574 git -C server update-ref refs/heads/refs/heads/s unwanted &&
575 git -C client fetch ../server +refs/heads/s:refs/heads/checkthis &&
576 git -C server rev-parse wanted >expect &&
577 git -C client rev-parse checkthis >actual &&
578 test_cmp expect actual &&
579
580 # ... and one before.
581 git -C server update-ref refs/heads/q wanted &&
582 git -C server update-ref refs/heads/refs/heads/q unwanted &&
583 git -C client fetch ../server +refs/heads/q:refs/heads/checkthis &&
584 git -C server rev-parse wanted >expect &&
585 git -C client rev-parse checkthis >actual &&
586 test_cmp expect actual &&
587
588 # Tags are preferred over branches like refs/{heads,tags}/*
589 git -C server update-ref refs/tags/t wanted &&
590 git -C server update-ref refs/heads/t unwanted &&
591 git -C client fetch ../server +t:refs/heads/checkthis &&
592 git -C server rev-parse wanted >expect &&
593 git -C client rev-parse checkthis >actual
594 )
595 '
596
597 test_expect_success 'fetch.writeCommitGraph' '
598 git clone three write &&
599 (
600 cd three &&
601 test_commit new
602 ) &&
603 (
604 cd write &&
605 git -c fetch.writeCommitGraph fetch origin &&
606 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
607 )
608 '
609
610 test_expect_success 'fetch.writeCommitGraph with submodules' '
611 git clone dups super &&
612 (
613 cd super &&
614 git submodule add "file://$TRASH_DIRECTORY/three" &&
615 git commit -m "add submodule"
616 ) &&
617 git clone "super" super-clone &&
618 (
619 cd super-clone &&
620 rm -rf .git/objects/info &&
621 git -c fetch.writeCommitGraph=true fetch origin &&
622 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
623 )
624 '
625
626 # configured prune tests
627
628 set_config_tristate () {
629 # var=$1 val=$2
630 case "$2" in
631 unset)
632 test_unconfig "$1"
633 ;;
634 *)
635 git config "$1" "$2"
636 key=$(echo $1 | sed -e 's/^remote\.origin/fetch/')
637 git_fetch_c="$git_fetch_c -c $key=$2"
638 ;;
639 esac
640 }
641
642 test_configured_prune () {
643 test_configured_prune_type "$@" "name"
644 test_configured_prune_type "$@" "link"
645 }
646
647 test_configured_prune_type () {
648 fetch_prune=$1
649 remote_origin_prune=$2
650 fetch_prune_tags=$3
651 remote_origin_prune_tags=$4
652 expected_branch=$5
653 expected_tag=$6
654 cmdline=$7
655 mode=$8
656
657 if test -z "$cmdline_setup"
658 then
659 test_expect_success 'setup cmdline_setup variable for subsequent test' '
660 remote_url="file://$(git -C one config remote.origin.url)" &&
661 remote_fetch="$(git -C one config remote.origin.fetch)" &&
662 cmdline_setup="\"$remote_url\" \"$remote_fetch\""
663 '
664 fi
665
666 if test "$mode" = 'link'
667 then
668 new_cmdline=""
669
670 if test "$cmdline" = ""
671 then
672 new_cmdline=$cmdline_setup
673 else
674 new_cmdline=$(printf "%s" "$cmdline" | perl -pe 's[origin(?!/)]["'"$remote_url"'"]g')
675 fi
676
677 if test "$fetch_prune_tags" = 'true' ||
678 test "$remote_origin_prune_tags" = 'true'
679 then
680 if ! printf '%s' "$cmdline\n" | grep -q refs/remotes/origin/
681 then
682 new_cmdline="$new_cmdline refs/tags/*:refs/tags/*"
683 fi
684 fi
685
686 cmdline="$new_cmdline"
687 fi
688
689 test_expect_success "$mode prune fetch.prune=$1 remote.origin.prune=$2 fetch.pruneTags=$3 remote.origin.pruneTags=$4${7:+ $7}; branch:$5 tag:$6" '
690 # make sure a newbranch is there in . and also in one
691 git branch -f newbranch &&
692 git tag -f newtag &&
693 (
694 cd one &&
695 test_unconfig fetch.prune &&
696 test_unconfig fetch.pruneTags &&
697 test_unconfig remote.origin.prune &&
698 test_unconfig remote.origin.pruneTags &&
699 git fetch '"$cmdline_setup"' &&
700 git rev-parse --verify refs/remotes/origin/newbranch &&
701 git rev-parse --verify refs/tags/newtag
702 ) &&
703
704 # now remove them
705 git branch -d newbranch &&
706 git tag -d newtag &&
707
708 # then test
709 (
710 cd one &&
711 git_fetch_c="" &&
712 set_config_tristate fetch.prune $fetch_prune &&
713 set_config_tristate fetch.pruneTags $fetch_prune_tags &&
714 set_config_tristate remote.origin.prune $remote_origin_prune &&
715 set_config_tristate remote.origin.pruneTags $remote_origin_prune_tags &&
716
717 if test "$mode" != "link"
718 then
719 git_fetch_c=""
720 fi &&
721 git$git_fetch_c fetch '"$cmdline"' &&
722 case "$expected_branch" in
723 pruned)
724 test_must_fail git rev-parse --verify refs/remotes/origin/newbranch
725 ;;
726 kept)
727 git rev-parse --verify refs/remotes/origin/newbranch
728 ;;
729 esac &&
730 case "$expected_tag" in
731 pruned)
732 test_must_fail git rev-parse --verify refs/tags/newtag
733 ;;
734 kept)
735 git rev-parse --verify refs/tags/newtag
736 ;;
737 esac
738 )
739 '
740 }
741
742 # $1 config: fetch.prune
743 # $2 config: remote.<name>.prune
744 # $3 config: fetch.pruneTags
745 # $4 config: remote.<name>.pruneTags
746 # $5 expect: branch to be pruned?
747 # $6 expect: tag to be pruned?
748 # $7 git-fetch $cmdline:
749 #
750 # $1 $2 $3 $4 $5 $6 $7
751 test_configured_prune unset unset unset unset kept kept ""
752 test_configured_prune unset unset unset unset kept kept "--no-prune"
753 test_configured_prune unset unset unset unset pruned kept "--prune"
754 test_configured_prune unset unset unset unset kept pruned \
755 "--prune origin refs/tags/*:refs/tags/*"
756 test_configured_prune unset unset unset unset pruned pruned \
757 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
758
759 test_configured_prune false unset unset unset kept kept ""
760 test_configured_prune false unset unset unset kept kept "--no-prune"
761 test_configured_prune false unset unset unset pruned kept "--prune"
762
763 test_configured_prune true unset unset unset pruned kept ""
764 test_configured_prune true unset unset unset pruned kept "--prune"
765 test_configured_prune true unset unset unset kept kept "--no-prune"
766
767 test_configured_prune unset false unset unset kept kept ""
768 test_configured_prune unset false unset unset kept kept "--no-prune"
769 test_configured_prune unset false unset unset pruned kept "--prune"
770
771 test_configured_prune false false unset unset kept kept ""
772 test_configured_prune false false unset unset kept kept "--no-prune"
773 test_configured_prune false false unset unset pruned kept "--prune"
774 test_configured_prune false false unset unset kept pruned \
775 "--prune origin refs/tags/*:refs/tags/*"
776 test_configured_prune false false unset unset pruned pruned \
777 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
778
779 test_configured_prune true false unset unset kept kept ""
780 test_configured_prune true false unset unset pruned kept "--prune"
781 test_configured_prune true false unset unset kept kept "--no-prune"
782
783 test_configured_prune unset true unset unset pruned kept ""
784 test_configured_prune unset true unset unset kept kept "--no-prune"
785 test_configured_prune unset true unset unset pruned kept "--prune"
786
787 test_configured_prune false true unset unset pruned kept ""
788 test_configured_prune false true unset unset kept kept "--no-prune"
789 test_configured_prune false true unset unset pruned kept "--prune"
790
791 test_configured_prune true true unset unset pruned kept ""
792 test_configured_prune true true unset unset pruned kept "--prune"
793 test_configured_prune true true unset unset kept kept "--no-prune"
794 test_configured_prune true true unset unset kept pruned \
795 "--prune origin refs/tags/*:refs/tags/*"
796 test_configured_prune true true unset unset pruned pruned \
797 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
798
799 # --prune-tags on its own does nothing, needs --prune as well, same
800 # for for fetch.pruneTags without fetch.prune
801 test_configured_prune unset unset unset unset kept kept "--prune-tags"
802 test_configured_prune unset unset true unset kept kept ""
803 test_configured_prune unset unset unset true kept kept ""
804
805 # These will prune the tags
806 test_configured_prune unset unset unset unset pruned pruned "--prune --prune-tags"
807 test_configured_prune true unset true unset pruned pruned ""
808 test_configured_prune unset true unset true pruned pruned ""
809
810 # remote.<name>.pruneTags overrides fetch.pruneTags, just like
811 # remote.<name>.prune overrides fetch.prune if set.
812 test_configured_prune true unset true unset pruned pruned ""
813 test_configured_prune false true false true pruned pruned ""
814 test_configured_prune true false true false kept kept ""
815
816 # When --prune-tags is supplied it's ignored if an explicit refspec is
817 # given, same for the configuration options.
818 test_configured_prune unset unset unset unset pruned kept \
819 "--prune --prune-tags origin +refs/heads/*:refs/remotes/origin/*"
820 test_configured_prune unset unset true unset pruned kept \
821 "--prune origin +refs/heads/*:refs/remotes/origin/*"
822 test_configured_prune unset unset unset true pruned kept \
823 "--prune origin +refs/heads/*:refs/remotes/origin/*"
824
825 # Pruning that also takes place if a file:// url replaces a named
826 # remote. However, because there's no implicit
827 # +refs/heads/*:refs/remotes/origin/* refspec and supplying it on the
828 # command-line negates --prune-tags, the branches will not be pruned.
829 test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "name"
830 test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "link"
831 test_configured_prune_type unset unset unset unset pruned pruned "origin --prune --prune-tags" "name"
832 test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "link"
833 test_configured_prune_type unset unset unset unset pruned pruned "--prune --prune-tags origin" "name"
834 test_configured_prune_type unset unset unset unset kept pruned "--prune --prune-tags origin" "link"
835 test_configured_prune_type unset unset true unset pruned pruned "--prune origin" "name"
836 test_configured_prune_type unset unset true unset kept pruned "--prune origin" "link"
837 test_configured_prune_type unset unset unset true pruned pruned "--prune origin" "name"
838 test_configured_prune_type unset unset unset true kept pruned "--prune origin" "link"
839 test_configured_prune_type true unset true unset pruned pruned "origin" "name"
840 test_configured_prune_type true unset true unset kept pruned "origin" "link"
841 test_configured_prune_type unset true true unset pruned pruned "origin" "name"
842 test_configured_prune_type unset true true unset kept pruned "origin" "link"
843 test_configured_prune_type unset true unset true pruned pruned "origin" "name"
844 test_configured_prune_type unset true unset true kept pruned "origin" "link"
845
846 # When all remote.origin.fetch settings are deleted a --prune
847 # --prune-tags still implicitly supplies refs/tags/*:refs/tags/* so
848 # tags, but not tracking branches, will be deleted.
849 test_expect_success 'remove remote.origin.fetch "one"' '
850 (
851 cd one &&
852 git config --unset-all remote.origin.fetch
853 )
854 '
855 test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "name"
856 test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "link"
857
858 test_expect_success 'all boundary commits are excluded' '
859 test_commit base &&
860 test_commit oneside &&
861 git checkout HEAD^ &&
862 test_commit otherside &&
863 git checkout master &&
864 test_tick &&
865 git merge otherside &&
866 ad=$(git log --no-walk --format=%ad HEAD) &&
867 git bundle create twoside-boundary.bdl master --since="$ad" &&
868 convert_bundle_to_pack <twoside-boundary.bdl >twoside-boundary.pack &&
869 pack=$(git index-pack --fix-thin --stdin <twoside-boundary.pack) &&
870 test_bundle_object_count .git/objects/pack/pack-${pack##pack }.pack 3
871 '
872
873 test_expect_success 'fetch --prune prints the remotes url' '
874 git branch goodbye &&
875 git clone . only-prunes &&
876 git branch -D goodbye &&
877 (
878 cd only-prunes &&
879 git fetch --prune origin 2>&1 | head -n1 >../actual
880 ) &&
881 echo "From ${D}/." >expect &&
882 test_i18ncmp expect actual
883 '
884
885 test_expect_success 'branchname D/F conflict resolved by --prune' '
886 git branch dir/file &&
887 git clone . prune-df-conflict &&
888 git branch -D dir/file &&
889 git branch dir &&
890 (
891 cd prune-df-conflict &&
892 git fetch --prune &&
893 git rev-parse origin/dir >../actual
894 ) &&
895 git rev-parse dir >expect &&
896 test_cmp expect actual
897 '
898
899 test_expect_success 'fetching a one-level ref works' '
900 test_commit extra &&
901 git reset --hard HEAD^ &&
902 git update-ref refs/foo extra &&
903 git init one-level &&
904 (
905 cd one-level &&
906 git fetch .. HEAD refs/foo
907 )
908 '
909
910 test_expect_success 'fetching with auto-gc does not lock up' '
911 write_script askyesno <<-\EOF &&
912 echo "$*" &&
913 false
914 EOF
915 git clone "file://$D" auto-gc &&
916 test_commit test2 &&
917 (
918 cd auto-gc &&
919 git config fetch.unpackLimit 1 &&
920 git config gc.autoPackLimit 1 &&
921 git config gc.autoDetach false &&
922 GIT_ASK_YESNO="$D/askyesno" git fetch >fetch.out 2>&1 &&
923 test_i18ngrep "Auto packing the repository" fetch.out &&
924 ! grep "Should I try again" fetch.out
925 )
926 '
927
928 test_expect_success C_LOCALE_OUTPUT 'fetch aligned output' '
929 git clone . full-output &&
930 test_commit looooooooooooong-tag &&
931 (
932 cd full-output &&
933 git -c fetch.output=full fetch origin >actual 2>&1 &&
934 grep -e "->" actual | cut -c 22- >../actual
935 ) &&
936 cat >expect <<-\EOF &&
937 master -> origin/master
938 looooooooooooong-tag -> looooooooooooong-tag
939 EOF
940 test_cmp expect actual
941 '
942
943 test_expect_success C_LOCALE_OUTPUT 'fetch compact output' '
944 git clone . compact &&
945 test_commit extraaa &&
946 (
947 cd compact &&
948 git -c fetch.output=compact fetch origin >actual 2>&1 &&
949 grep -e "->" actual | cut -c 22- >../actual
950 ) &&
951 cat >expect <<-\EOF &&
952 master -> origin/*
953 extraaa -> *
954 EOF
955 test_cmp expect actual
956 '
957
958 test_expect_success '--no-show-forced-updates' '
959 mkdir forced-updates &&
960 (
961 cd forced-updates &&
962 git init &&
963 test_commit 1 &&
964 test_commit 2
965 ) &&
966 git clone forced-updates forced-update-clone &&
967 git clone forced-updates no-forced-update-clone &&
968 git -C forced-updates reset --hard HEAD~1 &&
969 (
970 cd forced-update-clone &&
971 git fetch --show-forced-updates origin 2>output &&
972 test_i18ngrep "(forced update)" output
973 ) &&
974 (
975 cd no-forced-update-clone &&
976 git fetch --no-show-forced-updates origin 2>output &&
977 test_i18ngrep ! "(forced update)" output
978 )
979 '
980
981 setup_negotiation_tip () {
982 SERVER="$1"
983 URL="$2"
984 USE_PROTOCOL_V2="$3"
985
986 rm -rf "$SERVER" client trace &&
987 git init "$SERVER" &&
988 test_commit -C "$SERVER" alpha_1 &&
989 test_commit -C "$SERVER" alpha_2 &&
990 git -C "$SERVER" checkout --orphan beta &&
991 test_commit -C "$SERVER" beta_1 &&
992 test_commit -C "$SERVER" beta_2 &&
993
994 git clone "$URL" client &&
995
996 if test "$USE_PROTOCOL_V2" -eq 1
997 then
998 git -C "$SERVER" config protocol.version 2 &&
999 git -C client config protocol.version 2
1000 fi &&
1001
1002 test_commit -C "$SERVER" beta_s &&
1003 git -C "$SERVER" checkout master &&
1004 test_commit -C "$SERVER" alpha_s &&
1005 git -C "$SERVER" tag -d alpha_1 alpha_2 beta_1 beta_2
1006 }
1007
1008 check_negotiation_tip () {
1009 # Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2
1010 ALPHA_1=$(git -C client rev-parse alpha_1) &&
1011 grep "fetch> have $ALPHA_1" trace &&
1012 BETA_1=$(git -C client rev-parse beta_1) &&
1013 grep "fetch> have $BETA_1" trace &&
1014 ALPHA_2=$(git -C client rev-parse alpha_2) &&
1015 ! grep "fetch> have $ALPHA_2" trace &&
1016 BETA_2=$(git -C client rev-parse beta_2) &&
1017 ! grep "fetch> have $BETA_2" trace
1018 }
1019
1020 test_expect_success '--negotiation-tip limits "have" lines sent' '
1021 setup_negotiation_tip server server 0 &&
1022 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1023 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1024 origin alpha_s beta_s &&
1025 check_negotiation_tip
1026 '
1027
1028 test_expect_success '--negotiation-tip understands globs' '
1029 setup_negotiation_tip server server 0 &&
1030 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1031 --negotiation-tip=*_1 \
1032 origin alpha_s beta_s &&
1033 check_negotiation_tip
1034 '
1035
1036 test_expect_success '--negotiation-tip understands abbreviated SHA-1' '
1037 setup_negotiation_tip server server 0 &&
1038 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1039 --negotiation-tip=$(git -C client rev-parse --short alpha_1) \
1040 --negotiation-tip=$(git -C client rev-parse --short beta_1) \
1041 origin alpha_s beta_s &&
1042 check_negotiation_tip
1043 '
1044
1045 . "$TEST_DIRECTORY"/lib-httpd.sh
1046 start_httpd
1047
1048 test_expect_success '--negotiation-tip limits "have" lines sent with HTTP protocol v2' '
1049 setup_negotiation_tip "$HTTPD_DOCUMENT_ROOT_PATH/server" \
1050 "$HTTPD_URL/smart/server" 1 &&
1051 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1052 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1053 origin alpha_s beta_s &&
1054 check_negotiation_tip
1055 '
1056
1057 # DO NOT add non-httpd-specific tests here, because the last part of this
1058 # test script is only executed when httpd is available and enabled.
1059
1060 test_done