2 # Copyright (c) 2006, Junio C Hamano.
4 test_description
='Per branch config variables affects "git fetch".
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 .
"$TEST_DIRECTORY"/lib-bundle.sh
16 test_expect_success setup
'
17 echo >file original &&
19 git commit -a -m original &&
23 test_expect_success
"clone and setup child repos" '
27 echo >file updated by one &&
28 git commit -a -m "updated by one"
33 git config branch.main.remote one &&
34 git config remote.one.url ../one/.git/ &&
35 git config remote.one.fetch refs/heads/main:refs/heads/one
40 git config branch.main.remote two &&
41 git config branch.main.merge refs/heads/one &&
42 mkdir -p .git/remotes &&
44 echo "URL: ../two/.git/"
45 echo "Pull: refs/heads/main:refs/heads/two"
46 echo "Pull: refs/heads/one:refs/heads/one"
53 test_expect_success
"fetch test" '
55 echo >file updated by origin &&
56 git commit -a -m "updated by origin" &&
59 git rev-parse --verify refs/heads/one &&
60 mine=$(git rev-parse refs/heads/one) &&
61 his=$(cd ../one && git rev-parse refs/heads/main) &&
62 test "z$mine" = "z$his"
65 test_expect_success
"fetch test for-merge" '
69 git rev-parse --verify refs/heads/two &&
70 git rev-parse --verify refs/heads/one &&
71 main_in_two=$(cd ../two && git rev-parse main) &&
72 one_in_two=$(cd ../two && git rev-parse one) &&
75 echo "$main_in_two not-for-merge"
77 cut -f -2 .git/FETCH_HEAD >actual &&
78 test_cmp expected actual'
80 test_expect_success
'fetch --prune on its own works as expected' '
84 git update-ref refs/remotes/origin/extrabranch main &&
86 git fetch --prune origin &&
87 test_must_fail git rev-parse origin/extrabranch
90 test_expect_success
'fetch --prune with a branch name keeps branches' '
92 git clone . prune-branch &&
94 git update-ref refs/remotes/origin/extrabranch main &&
96 git fetch --prune origin main &&
97 git rev-parse origin/extrabranch
100 test_expect_success
'fetch --prune with a namespace keeps other namespaces' '
102 git clone . prune-namespace &&
103 cd prune-namespace &&
105 git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
106 git rev-parse origin/main
109 test_expect_success
'fetch --prune handles overlapping refspecs' '
111 git update-ref refs/pull/42/head main &&
112 git clone . prune-overlapping &&
113 cd prune-overlapping &&
114 git config --add remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
116 git fetch --prune origin &&
117 git rev-parse origin/main &&
118 git rev-parse origin/pr/42 &&
120 git config --unset-all remote.origin.fetch &&
121 git config remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
122 git config --add remote.origin.fetch refs/heads/*:refs/remotes/origin/* &&
124 git fetch --prune origin &&
125 git rev-parse origin/main &&
126 git rev-parse origin/pr/42
129 test_expect_success
'fetch --prune --tags prunes branches but not tags' '
131 git clone . prune-tags &&
133 git tag sometag main &&
134 # Create what looks like a remote-tracking branch from an earlier
135 # fetch that has since been deleted from the remote:
136 git update-ref refs/remotes/origin/fake-remote main &&
138 git fetch --prune --tags origin &&
139 git rev-parse origin/main &&
140 test_must_fail git rev-parse origin/fake-remote &&
141 git rev-parse sometag
144 test_expect_success
'fetch --prune --tags with branch does not prune other things' '
146 git clone . prune-tags-branch &&
147 cd prune-tags-branch &&
148 git tag sometag main &&
149 git update-ref refs/remotes/origin/extrabranch main &&
151 git fetch --prune --tags origin main &&
152 git rev-parse origin/extrabranch &&
153 git rev-parse sometag
156 test_expect_success
'fetch --prune --tags with refspec prunes based on refspec' '
158 git clone . prune-tags-refspec &&
159 cd prune-tags-refspec &&
160 git tag sometag main &&
161 git update-ref refs/remotes/origin/foo/otherbranch main &&
162 git update-ref refs/remotes/origin/extrabranch main &&
164 git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
165 test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
166 git rev-parse origin/extrabranch &&
167 git rev-parse sometag
170 test_expect_success
'fetch --atomic works with a single branch' '
171 test_when_finished "rm -rf \"$D\"/atomic" &&
174 git clone . atomic &&
175 git branch atomic-branch &&
176 oid=$(git rev-parse atomic-branch) &&
177 echo "$oid" >expected &&
179 git -C atomic fetch --atomic origin &&
180 git -C atomic rev-parse origin/atomic-branch >actual &&
181 test_cmp expected actual &&
182 test $oid = "$(git -C atomic rev-parse --verify FETCH_HEAD)"
185 test_expect_success
'fetch --atomic works with multiple branches' '
186 test_when_finished "rm -rf \"$D\"/atomic" &&
189 git clone . atomic &&
190 git branch atomic-branch-1 &&
191 git branch atomic-branch-2 &&
192 git branch atomic-branch-3 &&
193 git rev-parse refs/heads/atomic-branch-1 refs/heads/atomic-branch-2 refs/heads/atomic-branch-3 >actual &&
195 git -C atomic fetch --atomic origin &&
196 git -C atomic rev-parse refs/remotes/origin/atomic-branch-1 refs/remotes/origin/atomic-branch-2 refs/remotes/origin/atomic-branch-3 >expected &&
197 test_cmp expected actual
200 test_expect_success
'fetch --atomic works with mixed branches and tags' '
201 test_when_finished "rm -rf \"$D\"/atomic" &&
204 git clone . atomic &&
205 git branch atomic-mixed-branch &&
206 git tag atomic-mixed-tag &&
207 git rev-parse refs/heads/atomic-mixed-branch refs/tags/atomic-mixed-tag >actual &&
209 git -C atomic fetch --tags --atomic origin &&
210 git -C atomic rev-parse refs/remotes/origin/atomic-mixed-branch refs/tags/atomic-mixed-tag >expected &&
211 test_cmp expected actual
214 test_expect_success
'fetch --atomic prunes references' '
215 test_when_finished "rm -rf \"$D\"/atomic" &&
218 git branch atomic-prune-delete &&
219 git clone . atomic &&
220 git branch --delete atomic-prune-delete &&
221 git branch atomic-prune-create &&
222 git rev-parse refs/heads/atomic-prune-create >actual &&
224 git -C atomic fetch --prune --atomic origin &&
225 test_must_fail git -C atomic rev-parse refs/remotes/origin/atomic-prune-delete &&
226 git -C atomic rev-parse refs/remotes/origin/atomic-prune-create >expected &&
227 test_cmp expected actual
230 test_expect_success
'fetch --atomic aborts with non-fast-forward update' '
231 test_when_finished "rm -rf \"$D\"/atomic" &&
234 git branch atomic-non-ff &&
235 git clone . atomic &&
236 git rev-parse HEAD >actual &&
238 git branch atomic-new-branch &&
239 parent_commit=$(git rev-parse atomic-non-ff~) &&
240 git update-ref refs/heads/atomic-non-ff $parent_commit &&
242 test_must_fail git -C atomic fetch --atomic origin refs/heads/*:refs/remotes/origin/* &&
243 test_must_fail git -C atomic rev-parse refs/remotes/origin/atomic-new-branch &&
244 git -C atomic rev-parse refs/remotes/origin/atomic-non-ff >expected &&
245 test_cmp expected actual &&
246 test_must_be_empty atomic/.git/FETCH_HEAD
249 test_expect_success
'fetch --atomic executes a single reference transaction only' '
250 test_when_finished "rm -rf \"$D\"/atomic" &&
253 git clone . atomic &&
254 git branch atomic-hooks-1 &&
255 git branch atomic-hooks-2 &&
256 head_oid=$(git rev-parse HEAD) &&
258 cat >expected <<-EOF &&
260 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1
261 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2
263 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1
264 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2
267 rm -f atomic/actual &&
268 write_script atomic/.git/hooks/reference-transaction <<-\EOF &&
269 ( echo "$*" && cat ) >>actual
272 git -C atomic fetch --atomic origin &&
273 test_cmp expected atomic/actual
276 test_expect_success
'fetch --atomic aborts all reference updates if hook aborts' '
277 test_when_finished "rm -rf \"$D\"/atomic" &&
280 git clone . atomic &&
281 git branch atomic-hooks-abort-1 &&
282 git branch atomic-hooks-abort-2 &&
283 git branch atomic-hooks-abort-3 &&
284 git tag atomic-hooks-abort &&
285 head_oid=$(git rev-parse HEAD) &&
287 cat >expected <<-EOF &&
289 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-1
290 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-2
291 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-3
292 $ZERO_OID $head_oid refs/tags/atomic-hooks-abort
294 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-1
295 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-2
296 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-3
297 $ZERO_OID $head_oid refs/tags/atomic-hooks-abort
300 rm -f atomic/actual &&
301 write_script atomic/.git/hooks/reference-transaction <<-\EOF &&
302 ( echo "$*" && cat ) >>actual
306 git -C atomic for-each-ref >expected-refs &&
307 test_must_fail git -C atomic fetch --tags --atomic origin &&
308 git -C atomic for-each-ref >actual-refs &&
309 test_cmp expected-refs actual-refs &&
310 test_must_be_empty atomic/.git/FETCH_HEAD
313 test_expect_success
'fetch --atomic --append appends to FETCH_HEAD' '
314 test_when_finished "rm -rf \"$D\"/atomic" &&
317 git clone . atomic &&
318 oid=$(git rev-parse HEAD) &&
320 git branch atomic-fetch-head-1 &&
321 git -C atomic fetch --atomic origin atomic-fetch-head-1 &&
322 test_line_count = 1 atomic/.git/FETCH_HEAD &&
324 git branch atomic-fetch-head-2 &&
325 git -C atomic fetch --atomic --append origin atomic-fetch-head-2 &&
326 test_line_count = 2 atomic/.git/FETCH_HEAD &&
327 cp atomic/.git/FETCH_HEAD expected &&
329 write_script atomic/.git/hooks/reference-transaction <<-\EOF &&
333 git branch atomic-fetch-head-3 &&
334 test_must_fail git -C atomic fetch --atomic --append origin atomic-fetch-head-3 &&
335 test_cmp expected atomic/.git/FETCH_HEAD
338 test_expect_success
'--refmap="" ignores configured refspec' '
339 cd "$TRASH_DIRECTORY" &&
340 git clone "$D" remote-refs &&
341 git -C remote-refs rev-parse remotes/origin/main >old &&
342 git -C remote-refs update-ref refs/remotes/origin/main main~1 &&
343 git -C remote-refs rev-parse remotes/origin/main >new &&
344 git -C remote-refs fetch --refmap= origin "+refs/heads/*:refs/hidden/origin/*" &&
345 git -C remote-refs rev-parse remotes/origin/main >actual &&
346 test_cmp new actual &&
347 git -C remote-refs fetch origin &&
348 git -C remote-refs rev-parse remotes/origin/main >actual &&
352 test_expect_success
'--refmap="" and --prune' '
353 git -C remote-refs update-ref refs/remotes/origin/foo/otherbranch main &&
354 git -C remote-refs update-ref refs/hidden/foo/otherbranch main &&
355 git -C remote-refs fetch --prune --refmap="" origin +refs/heads/*:refs/hidden/* &&
356 git -C remote-refs rev-parse remotes/origin/foo/otherbranch &&
357 test_must_fail git -C remote-refs rev-parse refs/hidden/foo/otherbranch &&
358 git -C remote-refs fetch --prune origin &&
359 test_must_fail git -C remote-refs rev-parse remotes/origin/foo/otherbranch
362 test_expect_success
'fetch tags when there is no tags' '
374 test_expect_success
'fetch following tags' '
377 git tag -a -m "annotated" anno HEAD &&
378 git tag light HEAD &&
384 git fetch .. :track &&
385 git show-ref --verify refs/tags/anno &&
386 git show-ref --verify refs/tags/light
390 test_expect_success
'fetch uses remote ref names to describe new refs' '
392 git init descriptive &&
395 git config remote.o.url .. &&
396 git config remote.o.fetch "refs/heads/*:refs/crazyheads/*" &&
397 git config --add remote.o.fetch "refs/others/*:refs/heads/*" &&
400 git tag -a -m "Descriptive tag" descriptive-tag &&
401 git branch descriptive-branch &&
402 git checkout descriptive-branch &&
403 echo "Nuts" >crazy &&
405 git commit -a -m "descriptive commit" &&
406 git update-ref refs/others/crazy HEAD &&
409 git fetch o 2>actual &&
410 test_i18ngrep "new branch.* -> refs/crazyheads/descriptive-branch$" actual &&
411 test_i18ngrep "new tag.* -> descriptive-tag$" actual &&
412 test_i18ngrep "new ref.* -> crazy$" actual
417 test_expect_success
'fetch must not resolve short tag name' '
425 test_must_fail git fetch .. anno:five
429 test_expect_success
'fetch can now resolve short remote name' '
432 git update-ref refs/remotes/six/HEAD HEAD &&
441 test_expect_success
'create bundle 1' '
443 echo >file updated again by origin &&
444 git commit -a -m "tip" &&
445 git bundle create --version=3 bundle1 main^..main
448 test_expect_success
'header of bundle looks right' '
449 cat >expect <<-EOF &&
451 @object-format=$(test_oid algo)
452 -OID updated by origin
456 sed -e "s/$OID_REGEX/OID/g" -e "5q" "$D"/bundle1 >actual &&
457 test_cmp expect actual
460 test_expect_success
'create bundle 2' '
462 git bundle create bundle2 main~2..main
465 test_expect_success
'unbundle 1' '
467 git checkout -b some-branch &&
468 test_must_fail git fetch "$D/bundle1" main:main
472 test_expect_success
'bundle 1 has only 3 files ' '
474 test_bundle_object_count bundle1 3
477 test_expect_success
'unbundle 2' '
479 git fetch ../bundle2 main:main &&
480 test "tip" = "$(git log -1 --pretty=oneline main | cut -d" " -f2)"
483 test_expect_success
'bundle does not prerequisite objects' '
487 git commit -m add.file2 file2 &&
488 git bundle create bundle3 -1 HEAD &&
489 test_bundle_object_count bundle3 3
492 test_expect_success
'bundle should be able to create a full history' '
495 git tag -a -m "1.0" v1.0 main &&
496 git bundle create bundle4 v1.0
500 test_expect_success
'fetch with a non-applying branch.<name>.merge' '
501 git config branch.main.remote yeti &&
502 git config branch.main.merge refs/heads/bigfoot &&
503 git config remote.blub.url one &&
504 git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
508 # URL supplied to fetch does not match the url of the configured branch's remote
509 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
510 one_head=$(cd one && git rev-parse HEAD) &&
511 this_head=$(git rev-parse HEAD) &&
512 git update-ref -d FETCH_HEAD &&
514 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
515 test $this_head = "$(git rev-parse --verify HEAD)"
518 # URL supplied to fetch matches the url of the configured branch's remote and
519 # the merge spec matches the branch the remote HEAD points to
520 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [2]' '
521 one_ref=$(cd one && git symbolic-ref HEAD) &&
522 git config branch.main.remote blub &&
523 git config branch.main.merge "$one_ref" &&
524 git update-ref -d FETCH_HEAD &&
526 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
527 test $this_head = "$(git rev-parse --verify HEAD)"
530 # URL supplied to fetch matches the url of the configured branch's remote, but
531 # the merge spec does not match the branch the remote HEAD points to
532 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
533 git config branch.main.merge "${one_ref}_not" &&
534 git update-ref -d FETCH_HEAD &&
536 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
537 test $this_head = "$(git rev-parse --verify HEAD)"
540 # the strange name is: a\!'b
541 test_expect_success
'quoting of a strangely named repo' '
542 test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
543 grep "fatal: '\''a\\\\!'\''b'\''" result
546 test_expect_success
'bundle should record HEAD correctly' '
549 git bundle create bundle5 HEAD main &&
550 git bundle list-heads bundle5 >actual &&
551 for h in HEAD refs/heads/main
553 echo "$(git rev-parse --verify $h) $h"
555 test_cmp expect actual
559 test_expect_success
'mark initial state of origin/main' '
562 git tag base-origin-main refs/remotes/origin/main
566 test_expect_success
'explicit fetch should update tracking' '
569 git branch -f side &&
572 git update-ref refs/remotes/origin/main base-origin-main &&
573 o=$(git rev-parse --verify refs/remotes/origin/main) &&
574 git fetch origin main &&
575 n=$(git rev-parse --verify refs/remotes/origin/main) &&
577 test_must_fail git rev-parse --verify refs/remotes/origin/side
581 test_expect_success
'explicit pull should update tracking' '
584 git branch -f side &&
587 git update-ref refs/remotes/origin/main base-origin-main &&
588 o=$(git rev-parse --verify refs/remotes/origin/main) &&
589 git pull origin main &&
590 n=$(git rev-parse --verify refs/remotes/origin/main) &&
592 test_must_fail git rev-parse --verify refs/remotes/origin/side
596 test_expect_success
'explicit --refmap is allowed only with command-line refspec' '
600 test_must_fail git fetch --refmap="*:refs/remotes/none/*"
604 test_expect_success
'explicit --refmap option overrides remote.*.fetch' '
606 git branch -f side &&
609 git update-ref refs/remotes/origin/main base-origin-main &&
610 o=$(git rev-parse --verify refs/remotes/origin/main) &&
611 git fetch --refmap="refs/heads/*:refs/remotes/other/*" origin main &&
612 n=$(git rev-parse --verify refs/remotes/origin/main) &&
614 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
615 git rev-parse --verify refs/remotes/other/main
619 test_expect_success
'explicitly empty --refmap option disables remote.*.fetch' '
621 git branch -f side &&
624 git update-ref refs/remotes/origin/main base-origin-main &&
625 o=$(git rev-parse --verify refs/remotes/origin/main) &&
626 git fetch --refmap="" origin main &&
627 n=$(git rev-parse --verify refs/remotes/origin/main) &&
629 test_must_fail git rev-parse --verify refs/remotes/origin/side
633 test_expect_success
'configured fetch updates tracking' '
636 git branch -f side &&
639 git update-ref refs/remotes/origin/main base-origin-main &&
640 o=$(git rev-parse --verify refs/remotes/origin/main) &&
642 n=$(git rev-parse --verify refs/remotes/origin/main) &&
644 git rev-parse --verify refs/remotes/origin/side
648 test_expect_success
'non-matching refspecs do not confuse tracking update' '
650 git update-ref refs/odd/location HEAD &&
653 git update-ref refs/remotes/origin/main base-origin-main &&
654 git config --add remote.origin.fetch \
655 refs/odd/location:refs/remotes/origin/odd &&
656 o=$(git rev-parse --verify refs/remotes/origin/main) &&
657 git fetch origin main &&
658 n=$(git rev-parse --verify refs/remotes/origin/main) &&
660 test_must_fail git rev-parse --verify refs/remotes/origin/odd
664 test_expect_success
'pushing nonexistent branch by mistake should not segv' '
667 test_must_fail git push seven no:no
671 test_expect_success
'auto tag following fetches minimum' '
674 git clone .git follow &&
675 git checkout HEAD^0 &&
677 for i in 1 2 3 4 5 6 7
680 git commit -m $i -a &&
681 git tag -a -m $i excess-$i || exit 1
691 test_expect_success
'refuse to fetch into the current branch' '
693 test_must_fail git fetch . side:main
697 test_expect_success
'fetch into the current branch with --update-head-ok' '
699 git fetch --update-head-ok . side:main
703 test_expect_success
'fetch --dry-run does not touch FETCH_HEAD, but still prints what would be written' '
704 rm -f .git/FETCH_HEAD err &&
705 git fetch --dry-run . 2>err &&
706 ! test -f .git/FETCH_HEAD &&
710 test_expect_success
'--no-write-fetch-head does not touch FETCH_HEAD, and does not print what would be written' '
711 rm -f .git/FETCH_HEAD err &&
712 git fetch --no-write-fetch-head . 2>err &&
713 ! test -f .git/FETCH_HEAD &&
714 ! grep FETCH_HEAD err
717 test_expect_success
'--write-fetch-head gets defeated by --dry-run' '
718 rm -f .git/FETCH_HEAD &&
719 git fetch --dry-run --write-fetch-head . &&
720 ! test -f .git/FETCH_HEAD
723 test_expect_success
"should be able to fetch with duplicate refspecs" '
728 git config branch.main.remote three &&
729 git config remote.three.url ../three/.git &&
730 git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
731 git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
736 test_expect_success
'LHS of refspec follows ref disambiguation rules' '
737 mkdir lhs-ambiguous &&
741 test_commit -C server unwanted &&
742 test_commit -C server wanted &&
746 # Check a name coming after "refs" alphabetically ...
747 git -C server update-ref refs/heads/s wanted &&
748 git -C server update-ref refs/heads/refs/heads/s unwanted &&
749 git -C client fetch ../server +refs/heads/s:refs/heads/checkthis &&
750 git -C server rev-parse wanted >expect &&
751 git -C client rev-parse checkthis >actual &&
752 test_cmp expect actual &&
754 # ... and one before.
755 git -C server update-ref refs/heads/q wanted &&
756 git -C server update-ref refs/heads/refs/heads/q unwanted &&
757 git -C client fetch ../server +refs/heads/q:refs/heads/checkthis &&
758 git -C server rev-parse wanted >expect &&
759 git -C client rev-parse checkthis >actual &&
760 test_cmp expect actual &&
762 # Tags are preferred over branches like refs/{heads,tags}/*
763 git -C server update-ref refs/tags/t wanted &&
764 git -C server update-ref refs/heads/t unwanted &&
765 git -C client fetch ../server +t:refs/heads/checkthis &&
766 git -C server rev-parse wanted >expect &&
767 git -C client rev-parse checkthis >actual
771 test_expect_success
'fetch.writeCommitGraph' '
772 git clone three write &&
779 git -c fetch.writeCommitGraph fetch origin &&
780 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
784 test_expect_success
'fetch.writeCommitGraph with submodules' '
785 git clone dups super &&
788 git submodule add "file://$TRASH_DIRECTORY/three" &&
789 git commit -m "add submodule"
791 git clone "super" super-clone &&
794 rm -rf .git/objects/info &&
795 git -c fetch.writeCommitGraph=true fetch origin &&
796 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
800 # configured prune tests
802 set_config_tristate
() {
810 key
=$
(echo $1 |
sed -e 's/^remote\.origin/fetch/')
811 git_fetch_c
="$git_fetch_c -c $key=$2"
816 test_configured_prune
() {
817 test_configured_prune_type
"$@" "name"
818 test_configured_prune_type
"$@" "link"
821 test_configured_prune_type
() {
823 remote_origin_prune
=$2
825 remote_origin_prune_tags
=$4
831 if test -z "$cmdline_setup"
833 test_expect_success
'setup cmdline_setup variable for subsequent test' '
834 remote_url="file://$(git -C one config remote.origin.url)" &&
835 remote_fetch="$(git -C one config remote.origin.fetch)" &&
836 cmdline_setup="\"$remote_url\" \"$remote_fetch\""
840 if test "$mode" = 'link'
844 if test "$cmdline" = ""
846 new_cmdline
=$cmdline_setup
848 new_cmdline
=$
(printf "%s" "$cmdline" | perl
-pe 's[origin(?!/)]["'"$remote_url"'"]g')
851 if test "$fetch_prune_tags" = 'true' ||
852 test "$remote_origin_prune_tags" = 'true'
854 if ! printf '%s' "$cmdline\n" |
grep -q refs
/remotes
/origin
/
856 new_cmdline
="$new_cmdline refs/tags/*:refs/tags/*"
860 cmdline
="$new_cmdline"
863 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" '
864 # make sure a newbranch is there in . and also in one
865 git branch -f newbranch &&
869 test_unconfig fetch.prune &&
870 test_unconfig fetch.pruneTags &&
871 test_unconfig remote.origin.prune &&
872 test_unconfig remote.origin.pruneTags &&
873 git fetch '"$cmdline_setup"' &&
874 git rev-parse --verify refs/remotes/origin/newbranch &&
875 git rev-parse --verify refs/tags/newtag
879 git branch -d newbranch &&
886 set_config_tristate fetch.prune $fetch_prune &&
887 set_config_tristate fetch.pruneTags $fetch_prune_tags &&
888 set_config_tristate remote.origin.prune $remote_origin_prune &&
889 set_config_tristate remote.origin.pruneTags $remote_origin_prune_tags &&
891 if test "$mode" != "link"
895 git$git_fetch_c fetch '"$cmdline"' &&
896 case "$expected_branch" in
898 test_must_fail git rev-parse --verify refs/remotes/origin/newbranch
901 git rev-parse --verify refs/remotes/origin/newbranch
904 case "$expected_tag" in
906 test_must_fail git rev-parse --verify refs/tags/newtag
909 git rev-parse --verify refs/tags/newtag
916 # $1 config: fetch.prune
917 # $2 config: remote.<name>.prune
918 # $3 config: fetch.pruneTags
919 # $4 config: remote.<name>.pruneTags
920 # $5 expect: branch to be pruned?
921 # $6 expect: tag to be pruned?
922 # $7 git-fetch $cmdline:
924 # $1 $2 $3 $4 $5 $6 $7
925 test_configured_prune
unset unset unset unset kept kept
""
926 test_configured_prune
unset unset unset unset kept kept
"--no-prune"
927 test_configured_prune
unset unset unset unset pruned kept
"--prune"
928 test_configured_prune
unset unset unset unset kept pruned \
929 "--prune origin refs/tags/*:refs/tags/*"
930 test_configured_prune
unset unset unset unset pruned pruned \
931 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
933 test_configured_prune false
unset unset unset kept kept
""
934 test_configured_prune false
unset unset unset kept kept
"--no-prune"
935 test_configured_prune false
unset unset unset pruned kept
"--prune"
937 test_configured_prune true
unset unset unset pruned kept
""
938 test_configured_prune true
unset unset unset pruned kept
"--prune"
939 test_configured_prune true
unset unset unset kept kept
"--no-prune"
941 test_configured_prune
unset false
unset unset kept kept
""
942 test_configured_prune
unset false
unset unset kept kept
"--no-prune"
943 test_configured_prune
unset false
unset unset pruned kept
"--prune"
945 test_configured_prune false false
unset unset kept kept
""
946 test_configured_prune false false
unset unset kept kept
"--no-prune"
947 test_configured_prune false false
unset unset pruned kept
"--prune"
948 test_configured_prune false false
unset unset kept pruned \
949 "--prune origin refs/tags/*:refs/tags/*"
950 test_configured_prune false false
unset unset pruned pruned \
951 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
953 test_configured_prune true false
unset unset kept kept
""
954 test_configured_prune true false
unset unset pruned kept
"--prune"
955 test_configured_prune true false
unset unset kept kept
"--no-prune"
957 test_configured_prune
unset true
unset unset pruned kept
""
958 test_configured_prune
unset true
unset unset kept kept
"--no-prune"
959 test_configured_prune
unset true
unset unset pruned kept
"--prune"
961 test_configured_prune false true
unset unset pruned kept
""
962 test_configured_prune false true
unset unset kept kept
"--no-prune"
963 test_configured_prune false true
unset unset pruned kept
"--prune"
965 test_configured_prune true true
unset unset pruned kept
""
966 test_configured_prune true true
unset unset pruned kept
"--prune"
967 test_configured_prune true true
unset unset kept kept
"--no-prune"
968 test_configured_prune true true
unset unset kept pruned \
969 "--prune origin refs/tags/*:refs/tags/*"
970 test_configured_prune true true
unset unset pruned pruned \
971 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
973 # --prune-tags on its own does nothing, needs --prune as well, same
974 # for fetch.pruneTags without fetch.prune
975 test_configured_prune
unset unset unset unset kept kept
"--prune-tags"
976 test_configured_prune
unset unset true
unset kept kept
""
977 test_configured_prune
unset unset unset true kept kept
""
979 # These will prune the tags
980 test_configured_prune
unset unset unset unset pruned pruned
"--prune --prune-tags"
981 test_configured_prune true
unset true
unset pruned pruned
""
982 test_configured_prune
unset true
unset true pruned pruned
""
984 # remote.<name>.pruneTags overrides fetch.pruneTags, just like
985 # remote.<name>.prune overrides fetch.prune if set.
986 test_configured_prune true
unset true
unset pruned pruned
""
987 test_configured_prune false true false true pruned pruned
""
988 test_configured_prune true false true false kept kept
""
990 # When --prune-tags is supplied it's ignored if an explicit refspec is
991 # given, same for the configuration options.
992 test_configured_prune
unset unset unset unset pruned kept \
993 "--prune --prune-tags origin +refs/heads/*:refs/remotes/origin/*"
994 test_configured_prune
unset unset true
unset pruned kept \
995 "--prune origin +refs/heads/*:refs/remotes/origin/*"
996 test_configured_prune
unset unset unset true pruned kept \
997 "--prune origin +refs/heads/*:refs/remotes/origin/*"
999 # Pruning that also takes place if a file:// url replaces a named
1000 # remote. However, because there's no implicit
1001 # +refs/heads/*:refs/remotes/origin/* refspec and supplying it on the
1002 # command-line negates --prune-tags, the branches will not be pruned.
1003 test_configured_prune_type
unset unset unset unset kept kept
"origin --prune-tags" "name"
1004 test_configured_prune_type
unset unset unset unset kept kept
"origin --prune-tags" "link"
1005 test_configured_prune_type
unset unset unset unset pruned pruned
"origin --prune --prune-tags" "name"
1006 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "link"
1007 test_configured_prune_type
unset unset unset unset pruned pruned
"--prune --prune-tags origin" "name"
1008 test_configured_prune_type
unset unset unset unset kept pruned
"--prune --prune-tags origin" "link"
1009 test_configured_prune_type
unset unset true
unset pruned pruned
"--prune origin" "name"
1010 test_configured_prune_type
unset unset true
unset kept pruned
"--prune origin" "link"
1011 test_configured_prune_type
unset unset unset true pruned pruned
"--prune origin" "name"
1012 test_configured_prune_type
unset unset unset true kept pruned
"--prune origin" "link"
1013 test_configured_prune_type true
unset true
unset pruned pruned
"origin" "name"
1014 test_configured_prune_type true
unset true
unset kept pruned
"origin" "link"
1015 test_configured_prune_type
unset true true
unset pruned pruned
"origin" "name"
1016 test_configured_prune_type
unset true true
unset kept pruned
"origin" "link"
1017 test_configured_prune_type
unset true
unset true pruned pruned
"origin" "name"
1018 test_configured_prune_type
unset true
unset true kept pruned
"origin" "link"
1020 # When all remote.origin.fetch settings are deleted a --prune
1021 # --prune-tags still implicitly supplies refs/tags/*:refs/tags/* so
1022 # tags, but not tracking branches, will be deleted.
1023 test_expect_success
'remove remote.origin.fetch "one"' '
1026 git config --unset-all remote.origin.fetch
1029 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "name"
1030 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "link"
1032 test_expect_success
'all boundary commits are excluded' '
1034 test_commit oneside &&
1035 git checkout HEAD^ &&
1036 test_commit otherside &&
1037 git checkout main &&
1039 git merge otherside &&
1040 ad=$(git log --no-walk --format=%ad HEAD) &&
1041 git bundle create twoside-boundary.bdl main --since="$ad" &&
1042 test_bundle_object_count --thin twoside-boundary.bdl 3
1045 test_expect_success
'fetch --prune prints the remotes url' '
1046 git branch goodbye &&
1047 git clone . only-prunes &&
1048 git branch -D goodbye &&
1051 git fetch --prune origin 2>&1 | head -n1 >../actual
1053 echo "From ${D}/." >expect &&
1054 test_cmp expect actual
1057 test_expect_success
'branchname D/F conflict resolved by --prune' '
1058 git branch dir/file &&
1059 git clone . prune-df-conflict &&
1060 git branch -D dir/file &&
1063 cd prune-df-conflict &&
1064 git fetch --prune &&
1065 git rev-parse origin/dir >../actual
1067 git rev-parse dir >expect &&
1068 test_cmp expect actual
1071 test_expect_success
'fetching a one-level ref works' '
1072 test_commit extra &&
1073 git reset --hard HEAD^ &&
1074 git update-ref refs/foo extra &&
1075 git init one-level &&
1078 git fetch .. HEAD refs/foo
1082 test_expect_success
'fetching with auto-gc does not lock up' '
1083 write_script askyesno <<-\EOF &&
1087 git clone "file://$D" auto-gc &&
1088 test_commit test2 &&
1091 git config fetch.unpackLimit 1 &&
1092 git config gc.autoPackLimit 1 &&
1093 git config gc.autoDetach false &&
1094 GIT_ASK_YESNO="$D/askyesno" git fetch --verbose >fetch.out 2>&1 &&
1095 test_i18ngrep "Auto packing the repository" fetch.out &&
1096 ! grep "Should I try again" fetch.out
1100 test_expect_success
'fetch aligned output' '
1101 git clone . full-output &&
1102 test_commit looooooooooooong-tag &&
1105 git -c fetch.output=full fetch origin >actual 2>&1 &&
1106 grep -e "->" actual | cut -c 22- >../actual
1108 cat >expect <<-\EOF &&
1110 looooooooooooong-tag -> looooooooooooong-tag
1112 test_cmp expect actual
1115 test_expect_success
'fetch compact output' '
1116 git clone . compact &&
1117 test_commit extraaa &&
1120 git -c fetch.output=compact fetch origin >actual 2>&1 &&
1121 grep -e "->" actual | cut -c 22- >../actual
1123 cat >expect <<-\EOF &&
1127 test_cmp expect actual
1130 test_expect_success
'--no-show-forced-updates' '
1131 mkdir forced-updates &&
1133 cd forced-updates &&
1138 git clone forced-updates forced-update-clone &&
1139 git clone forced-updates no-forced-update-clone &&
1140 git -C forced-updates reset --hard HEAD~1 &&
1142 cd forced-update-clone &&
1143 git fetch --show-forced-updates origin 2>output &&
1144 test_i18ngrep "(forced update)" output
1147 cd no-forced-update-clone &&
1148 git fetch --no-show-forced-updates origin 2>output &&
1149 test_i18ngrep ! "(forced update)" output
1153 setup_negotiation_tip
() {
1156 USE_PROTOCOL_V2
="$3"
1158 rm -rf "$SERVER" client trace
&&
1159 git init
-b main
"$SERVER" &&
1160 test_commit
-C "$SERVER" alpha_1
&&
1161 test_commit
-C "$SERVER" alpha_2
&&
1162 git
-C "$SERVER" checkout
--orphan beta
&&
1163 test_commit
-C "$SERVER" beta_1
&&
1164 test_commit
-C "$SERVER" beta_2
&&
1166 git clone
"$URL" client
&&
1168 if test "$USE_PROTOCOL_V2" -eq 1
1170 git
-C "$SERVER" config protocol.version
2 &&
1171 git
-C client config protocol.version
2
1174 test_commit
-C "$SERVER" beta_s
&&
1175 git
-C "$SERVER" checkout main
&&
1176 test_commit
-C "$SERVER" alpha_s
&&
1177 git
-C "$SERVER" tag
-d alpha_1 alpha_2 beta_1 beta_2
1180 check_negotiation_tip
() {
1181 # Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2
1182 ALPHA_1
=$
(git
-C client rev-parse alpha_1
) &&
1183 grep "fetch> have $ALPHA_1" trace
&&
1184 BETA_1
=$
(git
-C client rev-parse beta_1
) &&
1185 grep "fetch> have $BETA_1" trace
&&
1186 ALPHA_2
=$
(git
-C client rev-parse alpha_2
) &&
1187 ! grep "fetch> have $ALPHA_2" trace
&&
1188 BETA_2
=$
(git
-C client rev-parse beta_2
) &&
1189 ! grep "fetch> have $BETA_2" trace
1192 test_expect_success
'--negotiation-tip limits "have" lines sent' '
1193 setup_negotiation_tip server server 0 &&
1194 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1195 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1196 origin alpha_s beta_s &&
1197 check_negotiation_tip
1200 test_expect_success
'--negotiation-tip understands globs' '
1201 setup_negotiation_tip server server 0 &&
1202 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1203 --negotiation-tip=*_1 \
1204 origin alpha_s beta_s &&
1205 check_negotiation_tip
1208 test_expect_success
'--negotiation-tip understands abbreviated SHA-1' '
1209 setup_negotiation_tip server server 0 &&
1210 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1211 --negotiation-tip=$(git -C client rev-parse --short alpha_1) \
1212 --negotiation-tip=$(git -C client rev-parse --short beta_1) \
1213 origin alpha_s beta_s &&
1214 check_negotiation_tip
1217 test_expect_success
'--negotiation-tip rejects missing OIDs' '
1218 setup_negotiation_tip server server 0 &&
1219 test_must_fail git -C client fetch \
1220 --negotiation-tip=alpha_1 \
1221 --negotiation-tip=$(test_oid zero) \
1222 origin alpha_s beta_s 2>err &&
1223 cat >fatal-expect <<-EOF &&
1224 fatal: the object $(test_oid zero) does not exist
1226 grep fatal: err >fatal-actual &&
1227 test_cmp fatal-expect fatal-actual
1230 .
"$TEST_DIRECTORY"/lib-httpd.sh
1233 test_expect_success
'--negotiation-tip limits "have" lines sent with HTTP protocol v2' '
1234 setup_negotiation_tip "$HTTPD_DOCUMENT_ROOT_PATH/server" \
1235 "$HTTPD_URL/smart/server" 1 &&
1236 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1237 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1238 origin alpha_s beta_s &&
1239 check_negotiation_tip
1242 # DO NOT add non-httpd-specific tests here, because the last part of this
1243 # test script is only executed when httpd is available and enabled.