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 &&
32 test_expect_success
"clone and setup child repos" '
36 echo >file updated by one &&
37 git commit -a -m "updated by one"
42 git config branch.main.remote one &&
43 git config remote.one.url ../one/.git/ &&
44 git config remote.one.fetch refs/heads/main:refs/heads/one
49 git config branch.main.remote two &&
50 git config branch.main.merge refs/heads/one &&
51 mkdir -p .git/remotes &&
53 echo "URL: ../two/.git/"
54 echo "Pull: refs/heads/main:refs/heads/two"
55 echo "Pull: refs/heads/one:refs/heads/one"
62 test_expect_success
"fetch test" '
64 echo >file updated by origin &&
65 git commit -a -m "updated by origin" &&
68 git rev-parse --verify refs/heads/one &&
69 mine=$(git rev-parse refs/heads/one) &&
70 his=$(cd ../one && git rev-parse refs/heads/main) &&
71 test "z$mine" = "z$his"
74 test_expect_success
"fetch test for-merge" '
78 git rev-parse --verify refs/heads/two &&
79 git rev-parse --verify refs/heads/one &&
80 main_in_two=$(cd ../two && git rev-parse main) &&
81 one_in_two=$(cd ../two && git rev-parse one) &&
84 echo "$main_in_two not-for-merge"
86 cut -f -2 .git/FETCH_HEAD >actual &&
87 test_cmp expected actual'
89 test_expect_success
'fetch --prune on its own works as expected' '
93 git update-ref refs/remotes/origin/extrabranch main &&
95 git fetch --prune origin &&
96 test_must_fail git rev-parse origin/extrabranch
99 test_expect_success
'fetch --prune with a branch name keeps branches' '
101 git clone . prune-branch &&
103 git update-ref refs/remotes/origin/extrabranch main &&
105 git fetch --prune origin main &&
106 git rev-parse origin/extrabranch
109 test_expect_success
'fetch --prune with a namespace keeps other namespaces' '
111 git clone . prune-namespace &&
112 cd prune-namespace &&
114 git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
115 git rev-parse origin/main
118 test_expect_success
'fetch --prune handles overlapping refspecs' '
120 git update-ref refs/pull/42/head main &&
121 git clone . prune-overlapping &&
122 cd prune-overlapping &&
123 git config --add remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
125 git fetch --prune origin &&
126 git rev-parse origin/main &&
127 git rev-parse origin/pr/42 &&
129 git config --unset-all remote.origin.fetch &&
130 git config remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
131 git config --add remote.origin.fetch refs/heads/*:refs/remotes/origin/* &&
133 git fetch --prune origin &&
134 git rev-parse origin/main &&
135 git rev-parse origin/pr/42
138 test_expect_success
'fetch --prune --tags prunes branches but not tags' '
140 git clone . prune-tags &&
142 git tag sometag main &&
143 # Create what looks like a remote-tracking branch from an earlier
144 # fetch that has since been deleted from the remote:
145 git update-ref refs/remotes/origin/fake-remote main &&
147 git fetch --prune --tags origin &&
148 git rev-parse origin/main &&
149 test_must_fail git rev-parse origin/fake-remote &&
150 git rev-parse sometag
153 test_expect_success
'fetch --prune --tags with branch does not prune other things' '
155 git clone . prune-tags-branch &&
156 cd prune-tags-branch &&
157 git tag sometag main &&
158 git update-ref refs/remotes/origin/extrabranch main &&
160 git fetch --prune --tags origin main &&
161 git rev-parse origin/extrabranch &&
162 git rev-parse sometag
165 test_expect_success
'fetch --prune --tags with refspec prunes based on refspec' '
167 git clone . prune-tags-refspec &&
168 cd prune-tags-refspec &&
169 git tag sometag main &&
170 git update-ref refs/remotes/origin/foo/otherbranch main &&
171 git update-ref refs/remotes/origin/extrabranch main &&
173 git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
174 test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
175 git rev-parse origin/extrabranch &&
176 git rev-parse sometag
179 test_expect_success
'--refmap="" ignores configured refspec' '
180 cd "$TRASH_DIRECTORY" &&
181 git clone "$D" remote-refs &&
182 git -C remote-refs rev-parse remotes/origin/main >old &&
183 git -C remote-refs update-ref refs/remotes/origin/main main~1 &&
184 git -C remote-refs rev-parse remotes/origin/main >new &&
185 git -C remote-refs fetch --refmap= origin "+refs/heads/*:refs/hidden/origin/*" &&
186 git -C remote-refs rev-parse remotes/origin/main >actual &&
187 test_cmp new actual &&
188 git -C remote-refs fetch origin &&
189 git -C remote-refs rev-parse remotes/origin/main >actual &&
193 test_expect_success
'--refmap="" and --prune' '
194 git -C remote-refs update-ref refs/remotes/origin/foo/otherbranch main &&
195 git -C remote-refs update-ref refs/hidden/foo/otherbranch main &&
196 git -C remote-refs fetch --prune --refmap="" origin +refs/heads/*:refs/hidden/* &&
197 git -C remote-refs rev-parse remotes/origin/foo/otherbranch &&
198 test_must_fail git -C remote-refs rev-parse refs/hidden/foo/otherbranch &&
199 git -C remote-refs fetch --prune origin &&
200 test_must_fail git -C remote-refs rev-parse remotes/origin/foo/otherbranch
203 test_expect_success
'fetch tags when there is no tags' '
215 test_expect_success
'fetch following tags' '
218 git tag -a -m "annotated" anno HEAD &&
219 git tag light HEAD &&
225 git fetch .. :track &&
226 git show-ref --verify refs/tags/anno &&
227 git show-ref --verify refs/tags/light
231 test_expect_success
'fetch uses remote ref names to describe new refs' '
233 git init descriptive &&
236 git config remote.o.url .. &&
237 git config remote.o.fetch "refs/heads/*:refs/crazyheads/*" &&
238 git config --add remote.o.fetch "refs/others/*:refs/heads/*" &&
241 git tag -a -m "Descriptive tag" descriptive-tag &&
242 git branch descriptive-branch &&
243 git checkout descriptive-branch &&
244 echo "Nuts" >crazy &&
246 git commit -a -m "descriptive commit" &&
247 git update-ref refs/others/crazy HEAD &&
250 git fetch o 2>actual &&
251 test_i18ngrep "new branch.* -> refs/crazyheads/descriptive-branch$" actual &&
252 test_i18ngrep "new tag.* -> descriptive-tag$" actual &&
253 test_i18ngrep "new ref.* -> crazy$" actual
258 test_expect_success
'fetch must not resolve short tag name' '
266 test_must_fail git fetch .. anno:five
270 test_expect_success
'fetch can now resolve short remote name' '
273 git update-ref refs/remotes/six/HEAD HEAD &&
282 test_expect_success
'create bundle 1' '
284 echo >file updated again by origin &&
285 git commit -a -m "tip" &&
286 git bundle create --version=3 bundle1 main^..main
289 test_expect_success
'header of bundle looks right' '
290 cat >expect <<-EOF &&
292 @object-format=$(test_oid algo)
293 -OID updated by origin
297 sed -e "s/$OID_REGEX/OID/g" -e "5q" "$D"/bundle1 >actual &&
298 test_cmp expect actual
301 test_expect_success
'create bundle 2' '
303 git bundle create bundle2 main~2..main
306 test_expect_success
'unbundle 1' '
308 git checkout -b some-branch &&
309 test_must_fail git fetch "$D/bundle1" main:main
313 test_expect_success
'bundle 1 has only 3 files ' '
315 convert_bundle_to_pack <bundle1 >bundle.pack &&
316 git index-pack bundle.pack &&
317 test_bundle_object_count bundle.pack 3
320 test_expect_success
'unbundle 2' '
322 git fetch ../bundle2 main:main &&
323 test "tip" = "$(git log -1 --pretty=oneline main | cut -d" " -f2)"
326 test_expect_success
'bundle does not prerequisite objects' '
330 git commit -m add.file2 file2 &&
331 git bundle create bundle3 -1 HEAD &&
332 convert_bundle_to_pack <bundle3 >bundle.pack &&
333 git index-pack bundle.pack &&
334 test_bundle_object_count bundle.pack 3
337 test_expect_success
'bundle should be able to create a full history' '
340 git tag -a -m "1.0" v1.0 main &&
341 git bundle create bundle4 v1.0
345 test_expect_success
'fetch with a non-applying branch.<name>.merge' '
346 git config branch.main.remote yeti &&
347 git config branch.main.merge refs/heads/bigfoot &&
348 git config remote.blub.url one &&
349 git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
353 # URL supplied to fetch does not match the url of the configured branch's remote
354 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
355 one_head=$(cd one && git rev-parse HEAD) &&
356 this_head=$(git rev-parse HEAD) &&
357 git update-ref -d FETCH_HEAD &&
359 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
360 test $this_head = "$(git rev-parse --verify HEAD)"
363 # URL supplied to fetch matches the url of the configured branch's remote and
364 # the merge spec matches the branch the remote HEAD points to
365 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [2]' '
366 one_ref=$(cd one && git symbolic-ref HEAD) &&
367 git config branch.main.remote blub &&
368 git config branch.main.merge "$one_ref" &&
369 git update-ref -d FETCH_HEAD &&
371 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
372 test $this_head = "$(git rev-parse --verify HEAD)"
375 # URL supplied to fetch matches the url of the configured branch's remote, but
376 # the merge spec does not match the branch the remote HEAD points to
377 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
378 git config branch.main.merge "${one_ref}_not" &&
379 git update-ref -d FETCH_HEAD &&
381 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
382 test $this_head = "$(git rev-parse --verify HEAD)"
385 # the strange name is: a\!'b
386 test_expect_success
'quoting of a strangely named repo' '
387 test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
388 grep "fatal: '\''a\\\\!'\''b'\''" result
391 test_expect_success
'bundle should record HEAD correctly' '
394 git bundle create bundle5 HEAD main &&
395 git bundle list-heads bundle5 >actual &&
396 for h in HEAD refs/heads/main
398 echo "$(git rev-parse --verify $h) $h"
400 test_cmp expect actual
404 test_expect_success
'mark initial state of origin/main' '
407 git tag base-origin-main refs/remotes/origin/main
411 test_expect_success
'explicit fetch should update tracking' '
414 git branch -f side &&
417 git update-ref refs/remotes/origin/main base-origin-main &&
418 o=$(git rev-parse --verify refs/remotes/origin/main) &&
419 git fetch origin main &&
420 n=$(git rev-parse --verify refs/remotes/origin/main) &&
422 test_must_fail git rev-parse --verify refs/remotes/origin/side
426 test_expect_success
'explicit pull should update tracking' '
429 git branch -f side &&
432 git update-ref refs/remotes/origin/main base-origin-main &&
433 o=$(git rev-parse --verify refs/remotes/origin/main) &&
434 git pull origin main &&
435 n=$(git rev-parse --verify refs/remotes/origin/main) &&
437 test_must_fail git rev-parse --verify refs/remotes/origin/side
441 test_expect_success
'explicit --refmap is allowed only with command-line refspec' '
445 test_must_fail git fetch --refmap="*:refs/remotes/none/*"
449 test_expect_success
'explicit --refmap option overrides remote.*.fetch' '
451 git branch -f side &&
454 git update-ref refs/remotes/origin/main base-origin-main &&
455 o=$(git rev-parse --verify refs/remotes/origin/main) &&
456 git fetch --refmap="refs/heads/*:refs/remotes/other/*" origin main &&
457 n=$(git rev-parse --verify refs/remotes/origin/main) &&
459 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
460 git rev-parse --verify refs/remotes/other/main
464 test_expect_success
'explicitly empty --refmap option disables remote.*.fetch' '
466 git branch -f side &&
469 git update-ref refs/remotes/origin/main base-origin-main &&
470 o=$(git rev-parse --verify refs/remotes/origin/main) &&
471 git fetch --refmap="" origin main &&
472 n=$(git rev-parse --verify refs/remotes/origin/main) &&
474 test_must_fail git rev-parse --verify refs/remotes/origin/side
478 test_expect_success
'configured fetch updates tracking' '
481 git branch -f side &&
484 git update-ref refs/remotes/origin/main base-origin-main &&
485 o=$(git rev-parse --verify refs/remotes/origin/main) &&
487 n=$(git rev-parse --verify refs/remotes/origin/main) &&
489 git rev-parse --verify refs/remotes/origin/side
493 test_expect_success
'non-matching refspecs do not confuse tracking update' '
495 git update-ref refs/odd/location HEAD &&
498 git update-ref refs/remotes/origin/main base-origin-main &&
499 git config --add remote.origin.fetch \
500 refs/odd/location:refs/remotes/origin/odd &&
501 o=$(git rev-parse --verify refs/remotes/origin/main) &&
502 git fetch origin main &&
503 n=$(git rev-parse --verify refs/remotes/origin/main) &&
505 test_must_fail git rev-parse --verify refs/remotes/origin/odd
509 test_expect_success
'pushing nonexistent branch by mistake should not segv' '
512 test_must_fail git push seven no:no
516 test_expect_success
'auto tag following fetches minimum' '
519 git clone .git follow &&
520 git checkout HEAD^0 &&
522 for i in 1 2 3 4 5 6 7
525 git commit -m $i -a &&
526 git tag -a -m $i excess-$i || exit 1
536 test_expect_success
'refuse to fetch into the current branch' '
538 test_must_fail git fetch . side:main
542 test_expect_success
'fetch into the current branch with --update-head-ok' '
544 git fetch --update-head-ok . side:main
548 test_expect_success
'fetch --dry-run does not touch FETCH_HEAD, but still prints what would be written' '
549 rm -f .git/FETCH_HEAD err &&
550 git fetch --dry-run . 2>err &&
551 ! test -f .git/FETCH_HEAD &&
555 test_expect_success
'--no-write-fetch-head does not touch FETCH_HEAD, and does not print what would be written' '
556 rm -f .git/FETCH_HEAD err &&
557 git fetch --no-write-fetch-head . 2>err &&
558 ! test -f .git/FETCH_HEAD &&
559 ! grep FETCH_HEAD err
562 test_expect_success
'--write-fetch-head gets defeated by --dry-run' '
563 rm -f .git/FETCH_HEAD &&
564 git fetch --dry-run --write-fetch-head . &&
565 ! test -f .git/FETCH_HEAD
568 test_expect_success
"should be able to fetch with duplicate refspecs" '
573 git config branch.main.remote three &&
574 git config remote.three.url ../three/.git &&
575 git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
576 git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
581 test_expect_success
'LHS of refspec follows ref disambiguation rules' '
582 mkdir lhs-ambiguous &&
586 test_commit -C server unwanted &&
587 test_commit -C server wanted &&
591 # Check a name coming after "refs" alphabetically ...
592 git -C server update-ref refs/heads/s wanted &&
593 git -C server update-ref refs/heads/refs/heads/s unwanted &&
594 git -C client fetch ../server +refs/heads/s:refs/heads/checkthis &&
595 git -C server rev-parse wanted >expect &&
596 git -C client rev-parse checkthis >actual &&
597 test_cmp expect actual &&
599 # ... and one before.
600 git -C server update-ref refs/heads/q wanted &&
601 git -C server update-ref refs/heads/refs/heads/q unwanted &&
602 git -C client fetch ../server +refs/heads/q:refs/heads/checkthis &&
603 git -C server rev-parse wanted >expect &&
604 git -C client rev-parse checkthis >actual &&
605 test_cmp expect actual &&
607 # Tags are preferred over branches like refs/{heads,tags}/*
608 git -C server update-ref refs/tags/t wanted &&
609 git -C server update-ref refs/heads/t unwanted &&
610 git -C client fetch ../server +t:refs/heads/checkthis &&
611 git -C server rev-parse wanted >expect &&
612 git -C client rev-parse checkthis >actual
616 test_expect_success
'fetch.writeCommitGraph' '
617 git clone three write &&
624 git -c fetch.writeCommitGraph fetch origin &&
625 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
629 test_expect_success
'fetch.writeCommitGraph with submodules' '
630 git clone dups super &&
633 git submodule add "file://$TRASH_DIRECTORY/three" &&
634 git commit -m "add submodule"
636 git clone "super" super-clone &&
639 rm -rf .git/objects/info &&
640 git -c fetch.writeCommitGraph=true fetch origin &&
641 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
645 # configured prune tests
647 set_config_tristate
() {
655 key
=$
(echo $1 |
sed -e 's/^remote\.origin/fetch/')
656 git_fetch_c
="$git_fetch_c -c $key=$2"
661 test_configured_prune
() {
662 test_configured_prune_type
"$@" "name"
663 test_configured_prune_type
"$@" "link"
666 test_configured_prune_type
() {
668 remote_origin_prune
=$2
670 remote_origin_prune_tags
=$4
676 if test -z "$cmdline_setup"
678 test_expect_success
'setup cmdline_setup variable for subsequent test' '
679 remote_url="file://$(git -C one config remote.origin.url)" &&
680 remote_fetch="$(git -C one config remote.origin.fetch)" &&
681 cmdline_setup="\"$remote_url\" \"$remote_fetch\""
685 if test "$mode" = 'link'
689 if test "$cmdline" = ""
691 new_cmdline
=$cmdline_setup
693 new_cmdline
=$
(printf "%s" "$cmdline" | perl
-pe 's[origin(?!/)]["'"$remote_url"'"]g')
696 if test "$fetch_prune_tags" = 'true' ||
697 test "$remote_origin_prune_tags" = 'true'
699 if ! printf '%s' "$cmdline\n" |
grep -q refs
/remotes
/origin
/
701 new_cmdline
="$new_cmdline refs/tags/*:refs/tags/*"
705 cmdline
="$new_cmdline"
708 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" '
709 # make sure a newbranch is there in . and also in one
710 git branch -f newbranch &&
714 test_unconfig fetch.prune &&
715 test_unconfig fetch.pruneTags &&
716 test_unconfig remote.origin.prune &&
717 test_unconfig remote.origin.pruneTags &&
718 git fetch '"$cmdline_setup"' &&
719 git rev-parse --verify refs/remotes/origin/newbranch &&
720 git rev-parse --verify refs/tags/newtag
724 git branch -d newbranch &&
731 set_config_tristate fetch.prune $fetch_prune &&
732 set_config_tristate fetch.pruneTags $fetch_prune_tags &&
733 set_config_tristate remote.origin.prune $remote_origin_prune &&
734 set_config_tristate remote.origin.pruneTags $remote_origin_prune_tags &&
736 if test "$mode" != "link"
740 git$git_fetch_c fetch '"$cmdline"' &&
741 case "$expected_branch" in
743 test_must_fail git rev-parse --verify refs/remotes/origin/newbranch
746 git rev-parse --verify refs/remotes/origin/newbranch
749 case "$expected_tag" in
751 test_must_fail git rev-parse --verify refs/tags/newtag
754 git rev-parse --verify refs/tags/newtag
761 # $1 config: fetch.prune
762 # $2 config: remote.<name>.prune
763 # $3 config: fetch.pruneTags
764 # $4 config: remote.<name>.pruneTags
765 # $5 expect: branch to be pruned?
766 # $6 expect: tag to be pruned?
767 # $7 git-fetch $cmdline:
769 # $1 $2 $3 $4 $5 $6 $7
770 test_configured_prune
unset unset unset unset kept kept
""
771 test_configured_prune
unset unset unset unset kept kept
"--no-prune"
772 test_configured_prune
unset unset unset unset pruned kept
"--prune"
773 test_configured_prune
unset unset unset unset kept pruned \
774 "--prune origin refs/tags/*:refs/tags/*"
775 test_configured_prune
unset unset unset unset pruned pruned \
776 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
778 test_configured_prune false
unset unset unset kept kept
""
779 test_configured_prune false
unset unset unset kept kept
"--no-prune"
780 test_configured_prune false
unset unset unset pruned kept
"--prune"
782 test_configured_prune true
unset unset unset pruned kept
""
783 test_configured_prune true
unset unset unset pruned kept
"--prune"
784 test_configured_prune true
unset unset unset kept kept
"--no-prune"
786 test_configured_prune
unset false
unset unset kept kept
""
787 test_configured_prune
unset false
unset unset kept kept
"--no-prune"
788 test_configured_prune
unset false
unset unset pruned kept
"--prune"
790 test_configured_prune false false
unset unset kept kept
""
791 test_configured_prune false false
unset unset kept kept
"--no-prune"
792 test_configured_prune false false
unset unset pruned kept
"--prune"
793 test_configured_prune false false
unset unset kept pruned \
794 "--prune origin refs/tags/*:refs/tags/*"
795 test_configured_prune false false
unset unset pruned pruned \
796 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
798 test_configured_prune true false
unset unset kept kept
""
799 test_configured_prune true false
unset unset pruned kept
"--prune"
800 test_configured_prune true false
unset unset kept kept
"--no-prune"
802 test_configured_prune
unset true
unset unset pruned kept
""
803 test_configured_prune
unset true
unset unset kept kept
"--no-prune"
804 test_configured_prune
unset true
unset unset pruned kept
"--prune"
806 test_configured_prune false true
unset unset pruned kept
""
807 test_configured_prune false true
unset unset kept kept
"--no-prune"
808 test_configured_prune false true
unset unset pruned kept
"--prune"
810 test_configured_prune true true
unset unset pruned kept
""
811 test_configured_prune true true
unset unset pruned kept
"--prune"
812 test_configured_prune true true
unset unset kept kept
"--no-prune"
813 test_configured_prune true true
unset unset kept pruned \
814 "--prune origin refs/tags/*:refs/tags/*"
815 test_configured_prune true true
unset unset pruned pruned \
816 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
818 # --prune-tags on its own does nothing, needs --prune as well, same
819 # for fetch.pruneTags without fetch.prune
820 test_configured_prune
unset unset unset unset kept kept
"--prune-tags"
821 test_configured_prune
unset unset true
unset kept kept
""
822 test_configured_prune
unset unset unset true kept kept
""
824 # These will prune the tags
825 test_configured_prune
unset unset unset unset pruned pruned
"--prune --prune-tags"
826 test_configured_prune true
unset true
unset pruned pruned
""
827 test_configured_prune
unset true
unset true pruned pruned
""
829 # remote.<name>.pruneTags overrides fetch.pruneTags, just like
830 # remote.<name>.prune overrides fetch.prune if set.
831 test_configured_prune true
unset true
unset pruned pruned
""
832 test_configured_prune false true false true pruned pruned
""
833 test_configured_prune true false true false kept kept
""
835 # When --prune-tags is supplied it's ignored if an explicit refspec is
836 # given, same for the configuration options.
837 test_configured_prune
unset unset unset unset pruned kept \
838 "--prune --prune-tags origin +refs/heads/*:refs/remotes/origin/*"
839 test_configured_prune
unset unset true
unset pruned kept \
840 "--prune origin +refs/heads/*:refs/remotes/origin/*"
841 test_configured_prune
unset unset unset true pruned kept \
842 "--prune origin +refs/heads/*:refs/remotes/origin/*"
844 # Pruning that also takes place if a file:// url replaces a named
845 # remote. However, because there's no implicit
846 # +refs/heads/*:refs/remotes/origin/* refspec and supplying it on the
847 # command-line negates --prune-tags, the branches will not be pruned.
848 test_configured_prune_type
unset unset unset unset kept kept
"origin --prune-tags" "name"
849 test_configured_prune_type
unset unset unset unset kept kept
"origin --prune-tags" "link"
850 test_configured_prune_type
unset unset unset unset pruned pruned
"origin --prune --prune-tags" "name"
851 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "link"
852 test_configured_prune_type
unset unset unset unset pruned pruned
"--prune --prune-tags origin" "name"
853 test_configured_prune_type
unset unset unset unset kept pruned
"--prune --prune-tags origin" "link"
854 test_configured_prune_type
unset unset true
unset pruned pruned
"--prune origin" "name"
855 test_configured_prune_type
unset unset true
unset kept pruned
"--prune origin" "link"
856 test_configured_prune_type
unset unset unset true pruned pruned
"--prune origin" "name"
857 test_configured_prune_type
unset unset unset true kept pruned
"--prune origin" "link"
858 test_configured_prune_type true
unset true
unset pruned pruned
"origin" "name"
859 test_configured_prune_type true
unset true
unset kept pruned
"origin" "link"
860 test_configured_prune_type
unset true true
unset pruned pruned
"origin" "name"
861 test_configured_prune_type
unset true true
unset kept pruned
"origin" "link"
862 test_configured_prune_type
unset true
unset true pruned pruned
"origin" "name"
863 test_configured_prune_type
unset true
unset true kept pruned
"origin" "link"
865 # When all remote.origin.fetch settings are deleted a --prune
866 # --prune-tags still implicitly supplies refs/tags/*:refs/tags/* so
867 # tags, but not tracking branches, will be deleted.
868 test_expect_success
'remove remote.origin.fetch "one"' '
871 git config --unset-all remote.origin.fetch
874 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "name"
875 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "link"
877 test_expect_success
'all boundary commits are excluded' '
879 test_commit oneside &&
880 git checkout HEAD^ &&
881 test_commit otherside &&
884 git merge otherside &&
885 ad=$(git log --no-walk --format=%ad HEAD) &&
886 git bundle create twoside-boundary.bdl main --since="$ad" &&
887 convert_bundle_to_pack <twoside-boundary.bdl >twoside-boundary.pack &&
888 pack=$(git index-pack --fix-thin --stdin <twoside-boundary.pack) &&
889 test_bundle_object_count .git/objects/pack/pack-${pack##pack }.pack 3
892 test_expect_success
'fetch --prune prints the remotes url' '
893 git branch goodbye &&
894 git clone . only-prunes &&
895 git branch -D goodbye &&
898 git fetch --prune origin 2>&1 | head -n1 >../actual
900 echo "From ${D}/." >expect &&
901 test_i18ncmp expect actual
904 test_expect_success
'branchname D/F conflict resolved by --prune' '
905 git branch dir/file &&
906 git clone . prune-df-conflict &&
907 git branch -D dir/file &&
910 cd prune-df-conflict &&
912 git rev-parse origin/dir >../actual
914 git rev-parse dir >expect &&
915 test_cmp expect actual
918 test_expect_success
'fetching a one-level ref works' '
920 git reset --hard HEAD^ &&
921 git update-ref refs/foo extra &&
922 git init one-level &&
925 git fetch .. HEAD refs/foo
929 test_expect_success
'fetching with auto-gc does not lock up' '
930 write_script askyesno <<-\EOF &&
934 git clone "file://$D" auto-gc &&
938 git config fetch.unpackLimit 1 &&
939 git config gc.autoPackLimit 1 &&
940 git config gc.autoDetach false &&
941 GIT_ASK_YESNO="$D/askyesno" git fetch --verbose >fetch.out 2>&1 &&
942 test_i18ngrep "Auto packing the repository" fetch.out &&
943 ! grep "Should I try again" fetch.out
947 test_expect_success C_LOCALE_OUTPUT
'fetch aligned output' '
948 git clone . full-output &&
949 test_commit looooooooooooong-tag &&
952 git -c fetch.output=full fetch origin >actual 2>&1 &&
953 grep -e "->" actual | cut -c 22- >../actual
955 cat >expect <<-\EOF &&
957 looooooooooooong-tag -> looooooooooooong-tag
959 test_cmp expect actual
962 test_expect_success C_LOCALE_OUTPUT
'fetch compact output' '
963 git clone . compact &&
964 test_commit extraaa &&
967 git -c fetch.output=compact fetch origin >actual 2>&1 &&
968 grep -e "->" actual | cut -c 22- >../actual
970 cat >expect <<-\EOF &&
974 test_cmp expect actual
977 test_expect_success
'--no-show-forced-updates' '
978 mkdir forced-updates &&
985 git clone forced-updates forced-update-clone &&
986 git clone forced-updates no-forced-update-clone &&
987 git -C forced-updates reset --hard HEAD~1 &&
989 cd forced-update-clone &&
990 git fetch --show-forced-updates origin 2>output &&
991 test_i18ngrep "(forced update)" output
994 cd no-forced-update-clone &&
995 git fetch --no-show-forced-updates origin 2>output &&
996 test_i18ngrep ! "(forced update)" output
1000 setup_negotiation_tip
() {
1003 USE_PROTOCOL_V2
="$3"
1005 rm -rf "$SERVER" client trace
&&
1006 git init
-b main
"$SERVER" &&
1007 test_commit
-C "$SERVER" alpha_1
&&
1008 test_commit
-C "$SERVER" alpha_2
&&
1009 git
-C "$SERVER" checkout
--orphan beta
&&
1010 test_commit
-C "$SERVER" beta_1
&&
1011 test_commit
-C "$SERVER" beta_2
&&
1013 git clone
"$URL" client
&&
1015 if test "$USE_PROTOCOL_V2" -eq 1
1017 git
-C "$SERVER" config protocol.version
2 &&
1018 git
-C client config protocol.version
2
1021 test_commit
-C "$SERVER" beta_s
&&
1022 git
-C "$SERVER" checkout main
&&
1023 test_commit
-C "$SERVER" alpha_s
&&
1024 git
-C "$SERVER" tag
-d alpha_1 alpha_2 beta_1 beta_2
1027 check_negotiation_tip
() {
1028 # Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2
1029 ALPHA_1
=$
(git
-C client rev-parse alpha_1
) &&
1030 grep "fetch> have $ALPHA_1" trace
&&
1031 BETA_1
=$
(git
-C client rev-parse beta_1
) &&
1032 grep "fetch> have $BETA_1" trace
&&
1033 ALPHA_2
=$
(git
-C client rev-parse alpha_2
) &&
1034 ! grep "fetch> have $ALPHA_2" trace
&&
1035 BETA_2
=$
(git
-C client rev-parse beta_2
) &&
1036 ! grep "fetch> have $BETA_2" trace
1039 test_expect_success
'--negotiation-tip limits "have" lines sent' '
1040 setup_negotiation_tip server server 0 &&
1041 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1042 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1043 origin alpha_s beta_s &&
1044 check_negotiation_tip
1047 test_expect_success
'--negotiation-tip understands globs' '
1048 setup_negotiation_tip server server 0 &&
1049 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1050 --negotiation-tip=*_1 \
1051 origin alpha_s beta_s &&
1052 check_negotiation_tip
1055 test_expect_success
'--negotiation-tip understands abbreviated SHA-1' '
1056 setup_negotiation_tip server server 0 &&
1057 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1058 --negotiation-tip=$(git -C client rev-parse --short alpha_1) \
1059 --negotiation-tip=$(git -C client rev-parse --short beta_1) \
1060 origin alpha_s beta_s &&
1061 check_negotiation_tip
1064 .
"$TEST_DIRECTORY"/lib-httpd.sh
1067 test_expect_success
'--negotiation-tip limits "have" lines sent with HTTP protocol v2' '
1068 setup_negotiation_tip "$HTTPD_DOCUMENT_ROOT_PATH/server" \
1069 "$HTTPD_URL/smart/server" 1 &&
1070 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1071 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1072 origin alpha_s beta_s &&
1073 check_negotiation_tip
1076 # DO NOT add non-httpd-specific tests here, because the last part of this
1077 # test script is only executed when httpd is available and enabled.