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 bundle1 master^..master
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 "^$"
295 test_expect_success
'create bundle 2' '
297 git bundle create bundle2 master~2..master
300 test_expect_success
'unbundle 1' '
302 git checkout -b some-branch &&
303 test_must_fail git fetch "$D/bundle1" master:master
307 test_expect_success
'bundle 1 has only 3 files ' '
309 convert_bundle_to_pack <bundle1 >bundle.pack &&
310 git index-pack bundle.pack &&
311 test_bundle_object_count bundle.pack 3
314 test_expect_success
'unbundle 2' '
316 git fetch ../bundle2 master:master &&
317 test "tip" = "$(git log -1 --pretty=oneline master | cut -d" " -f2)"
320 test_expect_success
'bundle does not prerequisite objects' '
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
331 test_expect_success
'bundle should be able to create a full history' '
334 git tag -a -m '1.0' v1.0 master &&
335 git bundle create bundle4 v1.0
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/*" &&
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 &&
353 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
354 test $this_head = "$(git rev-parse --verify HEAD)"
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 &&
365 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
366 test $this_head = "$(git rev-parse --verify HEAD)"
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 &&
375 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
376 test $this_head = "$(git rev-parse --verify HEAD)"
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
385 test_expect_success
'bundle should record HEAD correctly' '
388 git bundle create bundle5 HEAD master &&
389 git bundle list-heads bundle5 >actual &&
390 for h in HEAD refs/heads/master
392 echo "$(git rev-parse --verify $h) $h"
394 test_cmp expect actual
398 test_expect_success
'mark initial state of origin/master' '
401 git tag base-origin-master refs/remotes/origin/master
405 test_expect_success
'explicit fetch should update tracking' '
408 git branch -f side &&
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) &&
416 test_must_fail git rev-parse --verify refs/remotes/origin/side
420 test_expect_success
'explicit pull should update tracking' '
423 git branch -f side &&
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) &&
431 test_must_fail git rev-parse --verify refs/remotes/origin/side
435 test_expect_success
'explicit --refmap is allowed only with command-line refspec' '
439 test_must_fail git fetch --refmap="*:refs/remotes/none/*"
443 test_expect_success
'explicit --refmap option overrides remote.*.fetch' '
445 git branch -f side &&
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) &&
453 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
454 git rev-parse --verify refs/remotes/other/master
458 test_expect_success
'explicitly empty --refmap option disables remote.*.fetch' '
460 git branch -f side &&
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) &&
468 test_must_fail git rev-parse --verify refs/remotes/origin/side
472 test_expect_success
'configured fetch updates tracking' '
475 git branch -f side &&
478 git update-ref refs/remotes/origin/master base-origin-master &&
479 o=$(git rev-parse --verify refs/remotes/origin/master) &&
481 n=$(git rev-parse --verify refs/remotes/origin/master) &&
483 git rev-parse --verify refs/remotes/origin/side
487 test_expect_success
'non-matching refspecs do not confuse tracking update' '
489 git update-ref refs/odd/location HEAD &&
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) &&
499 test_must_fail git rev-parse --verify refs/remotes/origin/odd
503 test_expect_success
'pushing nonexistent branch by mistake should not segv' '
506 test_must_fail git push seven no:no
510 test_expect_success
'auto tag following fetches minimum' '
513 git clone .git follow &&
514 git checkout HEAD^0 &&
516 for i in 1 2 3 4 5 6 7
519 git commit -m $i -a &&
520 git tag -a -m $i excess-$i || exit 1
523 git checkout master &&
530 test_expect_success
'refuse to fetch into the current branch' '
532 test_must_fail git fetch . side:master
536 test_expect_success
'fetch into the current branch with --update-head-ok' '
538 git fetch --update-head-ok . side:master
542 test_expect_success
'fetch --dry-run' '
544 rm -f .git/FETCH_HEAD &&
545 git fetch --dry-run . &&
546 ! test -f .git/FETCH_HEAD
549 test_expect_success
"should be able to fetch with duplicate refspecs" '
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/* &&
562 test_expect_success
'LHS of refspec follows ref disambiguation rules' '
563 mkdir lhs-ambiguous &&
567 test_commit -C server unwanted &&
568 test_commit -C server wanted &&
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 &&
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 &&
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
597 test_expect_success
'fetch.writeCommitGraph' '
598 git clone three write &&
605 git -c fetch.writeCommitGraph fetch origin &&
606 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
610 test_expect_success
'fetch.writeCommitGraph with submodules' '
611 git clone dups super &&
614 git submodule add "file://$TRASH_DIRECTORY/three" &&
615 git commit -m "add submodule"
617 git clone "super" 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
626 # configured prune tests
628 set_config_tristate
() {
636 key
=$
(echo $1 |
sed -e 's/^remote\.origin/fetch/')
637 git_fetch_c
="$git_fetch_c -c $key=$2"
642 test_configured_prune
() {
643 test_configured_prune_type
"$@" "name"
644 test_configured_prune_type
"$@" "link"
647 test_configured_prune_type
() {
649 remote_origin_prune
=$2
651 remote_origin_prune_tags
=$4
657 if test -z "$cmdline_setup"
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\""
666 if test "$mode" = 'link'
670 if test "$cmdline" = ""
672 new_cmdline
=$cmdline_setup
674 new_cmdline
=$
(printf "%s" "$cmdline" | perl
-pe 's[origin(?!/)]["'"$remote_url"'"]g')
677 if test "$fetch_prune_tags" = 'true' ||
678 test "$remote_origin_prune_tags" = 'true'
680 if ! printf '%s' "$cmdline\n" |
grep -q refs
/remotes
/origin
/
682 new_cmdline
="$new_cmdline refs/tags/*:refs/tags/*"
686 cmdline
="$new_cmdline"
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 &&
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
705 git branch -d newbranch &&
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 &&
717 if test "$mode" != "link"
721 git$git_fetch_c fetch '"$cmdline"' &&
722 case "$expected_branch" in
724 test_must_fail git rev-parse --verify refs/remotes/origin/newbranch
727 git rev-parse --verify refs/remotes/origin/newbranch
730 case "$expected_tag" in
732 test_must_fail git rev-parse --verify refs/tags/newtag
735 git rev-parse --verify refs/tags/newtag
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:
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/*"
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"
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"
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"
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/*"
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"
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"
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"
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/*"
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
""
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
""
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
""
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/*"
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"
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"' '
852 git config --unset-all remote.origin.fetch
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"
858 test_expect_success
'all boundary commits are excluded' '
860 test_commit oneside &&
861 git checkout HEAD^ &&
862 test_commit otherside &&
863 git checkout master &&
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
873 test_expect_success
'fetch --prune prints the remotes url' '
874 git branch goodbye &&
875 git clone . only-prunes &&
876 git branch -D goodbye &&
879 git fetch --prune origin 2>&1 | head -n1 >../actual
881 echo "From ${D}/." >expect &&
882 test_i18ncmp expect actual
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 &&
891 cd prune-df-conflict &&
893 git rev-parse origin/dir >../actual
895 git rev-parse dir >expect &&
896 test_cmp expect actual
899 test_expect_success
'fetching a one-level ref works' '
901 git reset --hard HEAD^ &&
902 git update-ref refs/foo extra &&
903 git init one-level &&
906 git fetch .. HEAD refs/foo
910 test_expect_success
'fetching with auto-gc does not lock up' '
911 write_script askyesno <<-\EOF &&
915 git clone "file://$D" 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
928 test_expect_success C_LOCALE_OUTPUT
'fetch aligned output' '
929 git clone . full-output &&
930 test_commit looooooooooooong-tag &&
933 git -c fetch.output=full fetch origin >actual 2>&1 &&
934 grep -e "->" actual | cut -c 22- >../actual
936 cat >expect <<-\EOF &&
937 master -> origin/master
938 looooooooooooong-tag -> looooooooooooong-tag
940 test_cmp expect actual
943 test_expect_success C_LOCALE_OUTPUT
'fetch compact output' '
944 git clone . compact &&
945 test_commit extraaa &&
948 git -c fetch.output=compact fetch origin >actual 2>&1 &&
949 grep -e "->" actual | cut -c 22- >../actual
951 cat >expect <<-\EOF &&
955 test_cmp expect actual
958 test_expect_success
'--no-show-forced-updates' '
959 mkdir forced-updates &&
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 &&
970 cd forced-update-clone &&
971 git fetch --show-forced-updates origin 2>output &&
972 test_i18ngrep "(forced update)" output
975 cd no-forced-update-clone &&
976 git fetch --no-show-forced-updates origin 2>output &&
977 test_i18ngrep ! "(forced update)" output
981 setup_negotiation_tip
() {
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
&&
994 git clone
"$URL" client
&&
996 if test "$USE_PROTOCOL_V2" -eq 1
998 git
-C "$SERVER" config protocol.version
2 &&
999 git
-C client config protocol.version
2
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
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
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
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
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
1045 .
"$TEST_DIRECTORY"/lib-httpd.sh
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
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.