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 "^$OID_REGEX " verify.out | wc -l)
17 convert_bundle_to_pack () {
18 while read x && test -n "$x"
25 test_expect_success setup '
26 echo >file original &&
28 git commit -a -m original'
30 test_expect_success "clone and setup child repos" '
34 echo >file updated by one &&
35 git commit -a -m "updated by one"
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
47 git config branch.master.remote two &&
48 git config branch.master.merge refs/heads/one &&
49 mkdir -p .git/remotes &&
51 echo "URL: ../two/.git/"
52 echo "Pull: refs/heads/master:refs/heads/two"
53 echo "Pull: refs/heads/one:refs/heads/one"
60 test_expect_success "fetch test" '
62 echo >file updated by origin &&
63 git commit -a -m "updated by origin" &&
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"
72 test_expect_success "fetch test for-merge" '
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) &&
82 echo "$master_in_two not-for-merge"
84 cut -f -2 .git/FETCH_HEAD >actual &&
85 test_cmp expected actual'
87 test_expect_success 'fetch --prune on its own works as expected' '
91 git update-ref refs/remotes/origin/extrabranch master &&
93 git fetch --prune origin &&
94 test_must_fail git rev-parse origin/extrabranch
97 test_expect_success 'fetch --prune with a branch name keeps branches' '
99 git clone . prune-branch &&
101 git update-ref refs/remotes/origin/extrabranch master &&
103 git fetch --prune origin master &&
104 git rev-parse origin/extrabranch
107 test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
109 git clone . prune-namespace &&
110 cd prune-namespace &&
112 git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
113 git rev-parse origin/master
116 test_expect_success 'fetch --prune handles overlapping refspecs' '
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/* &&
123 git fetch --prune origin &&
124 git rev-parse origin/master &&
125 git rev-parse origin/pr/42 &&
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/* &&
131 git fetch --prune origin &&
132 git rev-parse origin/master &&
133 git rev-parse origin/pr/42
136 test_expect_success 'fetch --prune --tags prunes branches but not tags' '
138 git clone . 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 &&
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
151 test_expect_success 'fetch --prune --tags with branch does not prune other things' '
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 &&
158 git fetch --prune --tags origin master &&
159 git rev-parse origin/extrabranch &&
160 git rev-parse sometag
163 test_expect_success 'fetch --prune --tags with refspec prunes based on refspec' '
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 &&
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
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 &&
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
201 test_expect_success 'fetch tags when there is no tags' '
213 test_expect_success 'fetch following tags' '
216 git tag -a -m "annotated" anno HEAD &&
217 git tag light HEAD &&
223 git fetch .. :track &&
224 git show-ref --verify refs/tags/anno &&
225 git show-ref --verify refs/tags/light
229 test_expect_success 'fetch uses remote ref names to describe new refs' '
231 git init 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/*" &&
239 git tag -a -m "Descriptive tag" descriptive-tag &&
240 git branch descriptive-branch &&
241 git checkout descriptive-branch &&
242 echo "Nuts" >crazy &&
244 git commit -a -m "descriptive commit" &&
245 git update-ref refs/others/crazy HEAD &&
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
256 test_expect_success 'fetch must not resolve short tag name' '
264 test_must_fail git fetch .. anno:five
268 test_expect_success 'fetch can now resolve short remote name' '
271 git update-ref refs/remotes/six/HEAD HEAD &&
280 test_expect_success 'create bundle 1' '
282 echo >file updated again by origin &&
283 git commit -a -m "tip" &&
284 git bundle create --version=3 bundle1 master^..master
287 test_expect_success 'header of bundle looks right' '
288 cat >expect <<-EOF &&
290 @object-format=$(test_oid algo)
291 -OID updated by origin
292 OID refs/heads/master
295 sed -e "s/$OID_REGEX/OID/g" -e "5q" "$D"/bundle1 >actual &&
296 test_cmp expect actual
299 test_expect_success 'create bundle 2' '
301 git bundle create bundle2 master~2..master
304 test_expect_success 'unbundle 1' '
306 git checkout -b some-branch &&
307 test_must_fail git fetch "$D/bundle1" master:master
311 test_expect_success 'bundle 1 has only 3 files ' '
313 convert_bundle_to_pack <bundle1 >bundle.pack &&
314 git index-pack bundle.pack &&
315 test_bundle_object_count bundle.pack 3
318 test_expect_success 'unbundle 2' '
320 git fetch ../bundle2 master:master &&
321 test "tip" = "$(git log -1 --pretty=oneline master | cut -d" " -f2)"
324 test_expect_success 'bundle does not prerequisite objects' '
328 git commit -m add.file2 file2 &&
329 git bundle create bundle3 -1 HEAD &&
330 convert_bundle_to_pack <bundle3 >bundle.pack &&
331 git index-pack bundle.pack &&
332 test_bundle_object_count bundle.pack 3
335 test_expect_success 'bundle should be able to create a full history' '
338 git tag -a -m "1.0" v1.0 master &&
339 git bundle create bundle4 v1.0
343 test_expect_success 'fetch with a non-applying branch.<name>.merge' '
344 git config branch.master.remote yeti &&
345 git config branch.master.merge refs/heads/bigfoot &&
346 git config remote.blub.url one &&
347 git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
351 # URL supplied to fetch does not match the url of the configured branch's remote
352 test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
353 one_head=$(cd one && git rev-parse HEAD) &&
354 this_head=$(git rev-parse HEAD) &&
355 git update-ref -d FETCH_HEAD &&
357 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
358 test $this_head = "$(git rev-parse --verify HEAD)"
361 # URL supplied to fetch matches the url of the configured branch's remote and
362 # the merge spec matches the branch the remote HEAD points to
363 test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [2]' '
364 one_ref=$(cd one && git symbolic-ref HEAD) &&
365 git config branch.master.remote blub &&
366 git config branch.master.merge "$one_ref" &&
367 git update-ref -d FETCH_HEAD &&
369 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
370 test $this_head = "$(git rev-parse --verify HEAD)"
373 # URL supplied to fetch matches the url of the configured branch's remote, but
374 # the merge spec does not match the branch the remote HEAD points to
375 test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
376 git config branch.master.merge "${one_ref}_not" &&
377 git update-ref -d FETCH_HEAD &&
379 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
380 test $this_head = "$(git rev-parse --verify HEAD)"
383 # the strange name is: a\!'b
384 test_expect_success 'quoting of a strangely named repo' '
385 test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
386 grep "fatal: '\''a\\\\!'\''b'\''" result
389 test_expect_success 'bundle should record HEAD correctly' '
392 git bundle create bundle5 HEAD master &&
393 git bundle list-heads bundle5 >actual &&
394 for h in HEAD refs/heads/master
396 echo "$(git rev-parse --verify $h) $h"
398 test_cmp expect actual
402 test_expect_success 'mark initial state of origin/master' '
405 git tag base-origin-master refs/remotes/origin/master
409 test_expect_success 'explicit fetch should update tracking' '
412 git branch -f side &&
415 git update-ref refs/remotes/origin/master base-origin-master &&
416 o=$(git rev-parse --verify refs/remotes/origin/master) &&
417 git fetch origin master &&
418 n=$(git rev-parse --verify refs/remotes/origin/master) &&
420 test_must_fail git rev-parse --verify refs/remotes/origin/side
424 test_expect_success 'explicit pull should update tracking' '
427 git branch -f side &&
430 git update-ref refs/remotes/origin/master base-origin-master &&
431 o=$(git rev-parse --verify refs/remotes/origin/master) &&
432 git pull origin master &&
433 n=$(git rev-parse --verify refs/remotes/origin/master) &&
435 test_must_fail git rev-parse --verify refs/remotes/origin/side
439 test_expect_success 'explicit --refmap is allowed only with command-line refspec' '
443 test_must_fail git fetch --refmap="*:refs/remotes/none/*"
447 test_expect_success 'explicit --refmap option overrides remote.*.fetch' '
449 git branch -f side &&
452 git update-ref refs/remotes/origin/master base-origin-master &&
453 o=$(git rev-parse --verify refs/remotes/origin/master) &&
454 git fetch --refmap="refs/heads/*:refs/remotes/other/*" origin master &&
455 n=$(git rev-parse --verify refs/remotes/origin/master) &&
457 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
458 git rev-parse --verify refs/remotes/other/master
462 test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' '
464 git branch -f side &&
467 git update-ref refs/remotes/origin/master base-origin-master &&
468 o=$(git rev-parse --verify refs/remotes/origin/master) &&
469 git fetch --refmap="" origin master &&
470 n=$(git rev-parse --verify refs/remotes/origin/master) &&
472 test_must_fail git rev-parse --verify refs/remotes/origin/side
476 test_expect_success 'configured fetch updates tracking' '
479 git branch -f side &&
482 git update-ref refs/remotes/origin/master base-origin-master &&
483 o=$(git rev-parse --verify refs/remotes/origin/master) &&
485 n=$(git rev-parse --verify refs/remotes/origin/master) &&
487 git rev-parse --verify refs/remotes/origin/side
491 test_expect_success 'non-matching refspecs do not confuse tracking update' '
493 git update-ref refs/odd/location HEAD &&
496 git update-ref refs/remotes/origin/master base-origin-master &&
497 git config --add remote.origin.fetch \
498 refs/odd/location:refs/remotes/origin/odd &&
499 o=$(git rev-parse --verify refs/remotes/origin/master) &&
500 git fetch origin master &&
501 n=$(git rev-parse --verify refs/remotes/origin/master) &&
503 test_must_fail git rev-parse --verify refs/remotes/origin/odd
507 test_expect_success 'pushing nonexistent branch by mistake should not segv' '
510 test_must_fail git push seven no:no
514 test_expect_success 'auto tag following fetches minimum' '
517 git clone .git follow &&
518 git checkout HEAD^0 &&
520 for i in 1 2 3 4 5 6 7
523 git commit -m $i -a &&
524 git tag -a -m $i excess-$i || exit 1
527 git checkout master &&
534 test_expect_success 'refuse to fetch into the current branch' '
536 test_must_fail git fetch . side:master
540 test_expect_success 'fetch into the current branch with --update-head-ok' '
542 git fetch --update-head-ok . side:master
546 test_expect_success 'fetch --dry-run' '
548 rm -f .git/FETCH_HEAD &&
549 git fetch --dry-run . &&
550 ! test -f .git/FETCH_HEAD
553 test_expect_success "should be able to fetch with duplicate refspecs" '
558 git config branch.master.remote three &&
559 git config remote.three.url ../three/.git &&
560 git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
561 git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
566 test_expect_success 'LHS of refspec follows ref disambiguation rules' '
567 mkdir lhs-ambiguous &&
571 test_commit -C server unwanted &&
572 test_commit -C server wanted &&
576 # Check a name coming after "refs" alphabetically ...
577 git -C server update-ref refs/heads/s wanted &&
578 git -C server update-ref refs/heads/refs/heads/s unwanted &&
579 git -C client fetch ../server +refs/heads/s:refs/heads/checkthis &&
580 git -C server rev-parse wanted >expect &&
581 git -C client rev-parse checkthis >actual &&
582 test_cmp expect actual &&
584 # ... and one before.
585 git -C server update-ref refs/heads/q wanted &&
586 git -C server update-ref refs/heads/refs/heads/q unwanted &&
587 git -C client fetch ../server +refs/heads/q:refs/heads/checkthis &&
588 git -C server rev-parse wanted >expect &&
589 git -C client rev-parse checkthis >actual &&
590 test_cmp expect actual &&
592 # Tags are preferred over branches like refs/{heads,tags}/*
593 git -C server update-ref refs/tags/t wanted &&
594 git -C server update-ref refs/heads/t unwanted &&
595 git -C client fetch ../server +t:refs/heads/checkthis &&
596 git -C server rev-parse wanted >expect &&
597 git -C client rev-parse checkthis >actual
601 test_expect_success 'fetch.writeCommitGraph' '
602 git clone three write &&
609 git -c fetch.writeCommitGraph fetch origin &&
610 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
614 test_expect_success 'fetch.writeCommitGraph with submodules' '
615 git clone dups super &&
618 git submodule add "file://$TRASH_DIRECTORY/three" &&
619 git commit -m "add submodule"
621 git clone "super" super-clone &&
624 rm -rf .git/objects/info &&
625 git -c fetch.writeCommitGraph=true fetch origin &&
626 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
630 # configured prune tests
632 set_config_tristate () {
640 key=$(echo $1 | sed -e 's/^remote\.origin/fetch/')
641 git_fetch_c="$git_fetch_c -c $key=$2"
646 test_configured_prune () {
647 test_configured_prune_type "$@" "name"
648 test_configured_prune_type "$@" "link"
651 test_configured_prune_type () {
653 remote_origin_prune=$2
655 remote_origin_prune_tags=$4
661 if test -z "$cmdline_setup"
663 test_expect_success 'setup cmdline_setup variable for subsequent test' '
664 remote_url="file://$(git -C one config remote.origin.url)" &&
665 remote_fetch="$(git -C one config remote.origin.fetch)" &&
666 cmdline_setup="\"$remote_url\" \"$remote_fetch\""
670 if test "$mode" = 'link'
674 if test "$cmdline" = ""
676 new_cmdline=$cmdline_setup
678 new_cmdline=$(printf "%s" "$cmdline" | perl -pe 's[origin(?!/)]["'"$remote_url"'"]g')
681 if test "$fetch_prune_tags" = 'true' ||
682 test "$remote_origin_prune_tags" = 'true'
684 if ! printf '%s' "$cmdline\n" | grep -q refs/remotes/origin/
686 new_cmdline="$new_cmdline refs/tags/*:refs/tags/*"
690 cmdline="$new_cmdline"
693 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" '
694 # make sure a newbranch is there in . and also in one
695 git branch -f newbranch &&
699 test_unconfig fetch.prune &&
700 test_unconfig fetch.pruneTags &&
701 test_unconfig remote.origin.prune &&
702 test_unconfig remote.origin.pruneTags &&
703 git fetch '"$cmdline_setup"' &&
704 git rev-parse --verify refs/remotes/origin/newbranch &&
705 git rev-parse --verify refs/tags/newtag
709 git branch -d newbranch &&
716 set_config_tristate fetch.prune $fetch_prune &&
717 set_config_tristate fetch.pruneTags $fetch_prune_tags &&
718 set_config_tristate remote.origin.prune $remote_origin_prune &&
719 set_config_tristate remote.origin.pruneTags $remote_origin_prune_tags &&
721 if test "$mode" != "link"
725 git$git_fetch_c fetch '"$cmdline"' &&
726 case "$expected_branch" in
728 test_must_fail git rev-parse --verify refs/remotes/origin/newbranch
731 git rev-parse --verify refs/remotes/origin/newbranch
734 case "$expected_tag" in
736 test_must_fail git rev-parse --verify refs/tags/newtag
739 git rev-parse --verify refs/tags/newtag
746 # $1 config: fetch.prune
747 # $2 config: remote.<name>.prune
748 # $3 config: fetch.pruneTags
749 # $4 config: remote.<name>.pruneTags
750 # $5 expect: branch to be pruned?
751 # $6 expect: tag to be pruned?
752 # $7 git-fetch $cmdline:
754 # $1 $2 $3 $4 $5 $6 $7
755 test_configured_prune unset unset unset unset kept kept ""
756 test_configured_prune unset unset unset unset kept kept "--no-prune"
757 test_configured_prune unset unset unset unset pruned kept "--prune"
758 test_configured_prune unset unset unset unset kept pruned \
759 "--prune origin refs/tags/*:refs/tags/*"
760 test_configured_prune unset unset unset unset pruned pruned \
761 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
763 test_configured_prune false unset unset unset kept kept ""
764 test_configured_prune false unset unset unset kept kept "--no-prune"
765 test_configured_prune false unset unset unset pruned kept "--prune"
767 test_configured_prune true unset unset unset pruned kept ""
768 test_configured_prune true unset unset unset pruned kept "--prune"
769 test_configured_prune true unset unset unset kept kept "--no-prune"
771 test_configured_prune unset false unset unset kept kept ""
772 test_configured_prune unset false unset unset kept kept "--no-prune"
773 test_configured_prune unset false unset unset pruned kept "--prune"
775 test_configured_prune false false unset unset kept kept ""
776 test_configured_prune false false unset unset kept kept "--no-prune"
777 test_configured_prune false false unset unset pruned kept "--prune"
778 test_configured_prune false false unset unset kept pruned \
779 "--prune origin refs/tags/*:refs/tags/*"
780 test_configured_prune false false unset unset pruned pruned \
781 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
783 test_configured_prune true false unset unset kept kept ""
784 test_configured_prune true false unset unset pruned kept "--prune"
785 test_configured_prune true false unset unset kept kept "--no-prune"
787 test_configured_prune unset true unset unset pruned kept ""
788 test_configured_prune unset true unset unset kept kept "--no-prune"
789 test_configured_prune unset true unset unset pruned kept "--prune"
791 test_configured_prune false true unset unset pruned kept ""
792 test_configured_prune false true unset unset kept kept "--no-prune"
793 test_configured_prune false true unset unset pruned kept "--prune"
795 test_configured_prune true true unset unset pruned kept ""
796 test_configured_prune true true unset unset pruned kept "--prune"
797 test_configured_prune true true unset unset kept kept "--no-prune"
798 test_configured_prune true true unset unset kept pruned \
799 "--prune origin refs/tags/*:refs/tags/*"
800 test_configured_prune true true unset unset pruned pruned \
801 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
803 # --prune-tags on its own does nothing, needs --prune as well, same
804 # for fetch.pruneTags without fetch.prune
805 test_configured_prune unset unset unset unset kept kept "--prune-tags"
806 test_configured_prune unset unset true unset kept kept ""
807 test_configured_prune unset unset unset true kept kept ""
809 # These will prune the tags
810 test_configured_prune unset unset unset unset pruned pruned "--prune --prune-tags"
811 test_configured_prune true unset true unset pruned pruned ""
812 test_configured_prune unset true unset true pruned pruned ""
814 # remote.<name>.pruneTags overrides fetch.pruneTags, just like
815 # remote.<name>.prune overrides fetch.prune if set.
816 test_configured_prune true unset true unset pruned pruned ""
817 test_configured_prune false true false true pruned pruned ""
818 test_configured_prune true false true false kept kept ""
820 # When --prune-tags is supplied it's ignored if an explicit refspec is
821 # given, same for the configuration options.
822 test_configured_prune unset unset unset unset pruned kept \
823 "--prune --prune-tags origin +refs/heads/*:refs/remotes/origin/*"
824 test_configured_prune unset unset true unset pruned kept \
825 "--prune origin +refs/heads/*:refs/remotes/origin/*"
826 test_configured_prune unset unset unset true pruned kept \
827 "--prune origin +refs/heads/*:refs/remotes/origin/*"
829 # Pruning that also takes place if a file:// url replaces a named
830 # remote. However, because there's no implicit
831 # +refs/heads/*:refs/remotes/origin/* refspec and supplying it on the
832 # command-line negates --prune-tags, the branches will not be pruned.
833 test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "name"
834 test_configured_prune_type unset unset unset unset kept kept "origin --prune-tags" "link"
835 test_configured_prune_type unset unset unset unset pruned pruned "origin --prune --prune-tags" "name"
836 test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "link"
837 test_configured_prune_type unset unset unset unset pruned pruned "--prune --prune-tags origin" "name"
838 test_configured_prune_type unset unset unset unset kept pruned "--prune --prune-tags origin" "link"
839 test_configured_prune_type unset unset true unset pruned pruned "--prune origin" "name"
840 test_configured_prune_type unset unset true unset kept pruned "--prune origin" "link"
841 test_configured_prune_type unset unset unset true pruned pruned "--prune origin" "name"
842 test_configured_prune_type unset unset unset true kept pruned "--prune origin" "link"
843 test_configured_prune_type true unset true unset pruned pruned "origin" "name"
844 test_configured_prune_type true unset true unset kept pruned "origin" "link"
845 test_configured_prune_type unset true true unset pruned pruned "origin" "name"
846 test_configured_prune_type unset true true unset kept pruned "origin" "link"
847 test_configured_prune_type unset true unset true pruned pruned "origin" "name"
848 test_configured_prune_type unset true unset true kept pruned "origin" "link"
850 # When all remote.origin.fetch settings are deleted a --prune
851 # --prune-tags still implicitly supplies refs/tags/*:refs/tags/* so
852 # tags, but not tracking branches, will be deleted.
853 test_expect_success 'remove remote.origin.fetch "one"' '
856 git config --unset-all remote.origin.fetch
859 test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "name"
860 test_configured_prune_type unset unset unset unset kept pruned "origin --prune --prune-tags" "link"
862 test_expect_success 'all boundary commits are excluded' '
864 test_commit oneside &&
865 git checkout HEAD^ &&
866 test_commit otherside &&
867 git checkout master &&
869 git merge otherside &&
870 ad=$(git log --no-walk --format=%ad HEAD) &&
871 git bundle create twoside-boundary.bdl master --since="$ad" &&
872 convert_bundle_to_pack <twoside-boundary.bdl >twoside-boundary.pack &&
873 pack=$(git index-pack --fix-thin --stdin <twoside-boundary.pack) &&
874 test_bundle_object_count .git/objects/pack/pack-${pack##pack }.pack 3
877 test_expect_success 'fetch --prune prints the remotes url' '
878 git branch goodbye &&
879 git clone . only-prunes &&
880 git branch -D goodbye &&
883 git fetch --prune origin 2>&1 | head -n1 >../actual
885 echo "From ${D}/." >expect &&
886 test_i18ncmp expect actual
889 test_expect_success 'branchname D/F conflict resolved by --prune' '
890 git branch dir/file &&
891 git clone . prune-df-conflict &&
892 git branch -D dir/file &&
895 cd prune-df-conflict &&
897 git rev-parse origin/dir >../actual
899 git rev-parse dir >expect &&
900 test_cmp expect actual
903 test_expect_success 'fetching a one-level ref works' '
905 git reset --hard HEAD^ &&
906 git update-ref refs/foo extra &&
907 git init one-level &&
910 git fetch .. HEAD refs/foo
914 test_expect_success 'fetching with auto-gc does not lock up' '
915 write_script askyesno <<-\EOF &&
919 git clone "file://$D" auto-gc &&
923 git config fetch.unpackLimit 1 &&
924 git config gc.autoPackLimit 1 &&
925 git config gc.autoDetach false &&
926 GIT_ASK_YESNO="$D/askyesno" git fetch >fetch.out 2>&1 &&
927 test_i18ngrep "Auto packing the repository" fetch.out &&
928 ! grep "Should I try again" fetch.out
932 test_expect_success C_LOCALE_OUTPUT 'fetch aligned output' '
933 git clone . full-output &&
934 test_commit looooooooooooong-tag &&
937 git -c fetch.output=full fetch origin >actual 2>&1 &&
938 grep -e "->" actual | cut -c 22- >../actual
940 cat >expect <<-\EOF &&
941 master -> origin/master
942 looooooooooooong-tag -> looooooooooooong-tag
944 test_cmp expect actual
947 test_expect_success C_LOCALE_OUTPUT 'fetch compact output' '
948 git clone . compact &&
949 test_commit extraaa &&
952 git -c fetch.output=compact fetch origin >actual 2>&1 &&
953 grep -e "->" actual | cut -c 22- >../actual
955 cat >expect <<-\EOF &&
959 test_cmp expect actual
962 test_expect_success '--no-show-forced-updates' '
963 mkdir forced-updates &&
970 git clone forced-updates forced-update-clone &&
971 git clone forced-updates no-forced-update-clone &&
972 git -C forced-updates reset --hard HEAD~1 &&
974 cd forced-update-clone &&
975 git fetch --show-forced-updates origin 2>output &&
976 test_i18ngrep "(forced update)" output
979 cd no-forced-update-clone &&
980 git fetch --no-show-forced-updates origin 2>output &&
981 test_i18ngrep ! "(forced update)" output
985 setup_negotiation_tip () {
990 rm -rf "$SERVER" client trace &&
991 git init "$SERVER" &&
992 test_commit -C "$SERVER" alpha_1 &&
993 test_commit -C "$SERVER" alpha_2 &&
994 git -C "$SERVER" checkout --orphan beta &&
995 test_commit -C "$SERVER" beta_1 &&
996 test_commit -C "$SERVER" beta_2 &&
998 git clone "$URL" client &&
1000 if test "$USE_PROTOCOL_V2" -eq 1
1002 git -C "$SERVER" config protocol.version 2 &&
1003 git -C client config protocol.version 2
1006 test_commit -C "$SERVER" beta_s &&
1007 git -C "$SERVER" checkout master &&
1008 test_commit -C "$SERVER" alpha_s &&
1009 git -C "$SERVER" tag -d alpha_1 alpha_2 beta_1 beta_2
1012 check_negotiation_tip () {
1013 # Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2
1014 ALPHA_1=$(git -C client rev-parse alpha_1) &&
1015 grep "fetch> have $ALPHA_1" trace &&
1016 BETA_1=$(git -C client rev-parse beta_1) &&
1017 grep "fetch> have $BETA_1" trace &&
1018 ALPHA_2=$(git -C client rev-parse alpha_2) &&
1019 ! grep "fetch> have $ALPHA_2" trace &&
1020 BETA_2=$(git -C client rev-parse beta_2) &&
1021 ! grep "fetch> have $BETA_2" trace
1024 test_expect_success '--negotiation-tip limits "have" lines sent' '
1025 setup_negotiation_tip server server 0 &&
1026 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1027 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1028 origin alpha_s beta_s &&
1029 check_negotiation_tip
1032 test_expect_success '--negotiation-tip understands globs' '
1033 setup_negotiation_tip server server 0 &&
1034 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1035 --negotiation-tip=*_1 \
1036 origin alpha_s beta_s &&
1037 check_negotiation_tip
1040 test_expect_success '--negotiation-tip understands abbreviated SHA-1' '
1041 setup_negotiation_tip server server 0 &&
1042 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1043 --negotiation-tip=$(git -C client rev-parse --short alpha_1) \
1044 --negotiation-tip=$(git -C client rev-parse --short beta_1) \
1045 origin alpha_s beta_s &&
1046 check_negotiation_tip
1049 . "$TEST_DIRECTORY"/lib-httpd.sh
1052 test_expect_success '--negotiation-tip limits "have" lines sent with HTTP protocol v2' '
1053 setup_negotiation_tip "$HTTPD_DOCUMENT_ROOT_PATH/server" \
1054 "$HTTPD_URL/smart/server" 1 &&
1055 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1056 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1057 origin alpha_s beta_s &&
1058 check_negotiation_tip
1061 # DO NOT add non-httpd-specific tests here, because the last part of this
1062 # test script is only executed when httpd is available and enabled.