2 # Copyright (c) 2006, Junio C Hamano.
4 test_description
='Per branch config variables affects "git fetch".
9 .
"$TEST_DIRECTORY"/lib-bundle.sh
13 test_expect_success setup
'
14 echo >file original &&
16 git commit -a -m original &&
20 test_expect_success
"clone and setup child repos" '
24 echo >file updated by one &&
25 git commit -a -m "updated by one"
30 git config branch.main.remote one &&
31 git config remote.one.url ../one/.git/ &&
32 git config remote.one.fetch refs/heads/main:refs/heads/one
37 git config branch.main.remote two &&
38 git config branch.main.merge refs/heads/one &&
39 mkdir -p .git/remotes &&
40 cat >.git/remotes/two <<-\EOF
42 Pull: refs/heads/main:refs/heads/two
43 Pull: refs/heads/one:refs/heads/one
50 test_expect_success
"fetch test" '
52 echo >file updated by origin &&
53 git commit -a -m "updated by origin" &&
56 git rev-parse --verify refs/heads/one &&
57 mine=$(git rev-parse refs/heads/one) &&
58 his=$(cd ../one && git rev-parse refs/heads/main) &&
59 test "z$mine" = "z$his"
62 test_expect_success
"fetch test for-merge" '
66 git rev-parse --verify refs/heads/two &&
67 git rev-parse --verify refs/heads/one &&
68 main_in_two=$(cd ../two && git rev-parse main) &&
69 one_in_two=$(cd ../two && git rev-parse one) &&
71 echo "$one_in_two " &&
72 echo "$main_in_two not-for-merge"
74 cut -f -2 .git/FETCH_HEAD >actual &&
75 test_cmp expected actual'
77 test_expect_success
'fetch --prune on its own works as expected' '
81 git update-ref refs/remotes/origin/extrabranch main &&
83 git fetch --prune origin &&
84 test_must_fail git rev-parse origin/extrabranch
87 test_expect_success
'fetch --prune with a branch name keeps branches' '
89 git clone . prune-branch &&
91 git update-ref refs/remotes/origin/extrabranch main &&
93 git fetch --prune origin main &&
94 git rev-parse origin/extrabranch
97 test_expect_success
'fetch --prune with a namespace keeps other namespaces' '
99 git clone . prune-namespace &&
100 cd prune-namespace &&
102 git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
103 git rev-parse origin/main
106 test_expect_success
'fetch --prune handles overlapping refspecs' '
108 git update-ref refs/pull/42/head main &&
109 git clone . prune-overlapping &&
110 cd prune-overlapping &&
111 git config --add remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
113 git fetch --prune origin &&
114 git rev-parse origin/main &&
115 git rev-parse origin/pr/42 &&
117 git config --unset-all remote.origin.fetch &&
118 git config remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
119 git config --add remote.origin.fetch refs/heads/*:refs/remotes/origin/* &&
121 git fetch --prune origin &&
122 git rev-parse origin/main &&
123 git rev-parse origin/pr/42
126 test_expect_success
'fetch --prune --tags prunes branches but not tags' '
128 git clone . prune-tags &&
130 git tag sometag main &&
131 # Create what looks like a remote-tracking branch from an earlier
132 # fetch that has since been deleted from the remote:
133 git update-ref refs/remotes/origin/fake-remote main &&
135 git fetch --prune --tags origin &&
136 git rev-parse origin/main &&
137 test_must_fail git rev-parse origin/fake-remote &&
138 git rev-parse sometag
141 test_expect_success
'fetch --prune --tags with branch does not prune other things' '
143 git clone . prune-tags-branch &&
144 cd prune-tags-branch &&
145 git tag sometag main &&
146 git update-ref refs/remotes/origin/extrabranch main &&
148 git fetch --prune --tags origin main &&
149 git rev-parse origin/extrabranch &&
150 git rev-parse sometag
153 test_expect_success
'fetch --prune --tags with refspec prunes based on refspec' '
155 git clone . prune-tags-refspec &&
156 cd prune-tags-refspec &&
157 git tag sometag main &&
158 git update-ref refs/remotes/origin/foo/otherbranch main &&
159 git update-ref refs/remotes/origin/extrabranch main &&
161 git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
162 test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
163 git rev-parse origin/extrabranch &&
164 git rev-parse sometag
167 test_expect_success REFFILES
'fetch --prune fails to delete branches' '
169 git clone . prune-fail &&
171 git update-ref refs/remotes/origin/extrabranch main &&
172 git pack-refs --all &&
173 : this will prevent --prune from locking packed-refs for deleting refs, but adding loose refs still succeeds &&
174 >.git/packed-refs.new &&
176 test_must_fail git fetch --prune origin
179 test_expect_success
'fetch --atomic works with a single branch' '
180 test_when_finished "rm -rf \"$D\"/atomic" &&
183 git clone . atomic &&
184 git branch atomic-branch &&
185 oid=$(git rev-parse atomic-branch) &&
186 echo "$oid" >expected &&
188 git -C atomic fetch --atomic origin &&
189 git -C atomic rev-parse origin/atomic-branch >actual &&
190 test_cmp expected actual &&
191 test $oid = "$(git -C atomic rev-parse --verify FETCH_HEAD)"
194 test_expect_success
'fetch --atomic works with multiple branches' '
195 test_when_finished "rm -rf \"$D\"/atomic" &&
198 git clone . atomic &&
199 git branch atomic-branch-1 &&
200 git branch atomic-branch-2 &&
201 git branch atomic-branch-3 &&
202 git rev-parse refs/heads/atomic-branch-1 refs/heads/atomic-branch-2 refs/heads/atomic-branch-3 >actual &&
204 git -C atomic fetch --atomic origin &&
205 git -C atomic rev-parse refs/remotes/origin/atomic-branch-1 refs/remotes/origin/atomic-branch-2 refs/remotes/origin/atomic-branch-3 >expected &&
206 test_cmp expected actual
209 test_expect_success
'fetch --atomic works with mixed branches and tags' '
210 test_when_finished "rm -rf \"$D\"/atomic" &&
213 git clone . atomic &&
214 git branch atomic-mixed-branch &&
215 git tag atomic-mixed-tag &&
216 git rev-parse refs/heads/atomic-mixed-branch refs/tags/atomic-mixed-tag >actual &&
218 git -C atomic fetch --tags --atomic origin &&
219 git -C atomic rev-parse refs/remotes/origin/atomic-mixed-branch refs/tags/atomic-mixed-tag >expected &&
220 test_cmp expected actual
223 test_expect_success
'fetch --atomic prunes references' '
224 test_when_finished "rm -rf \"$D\"/atomic" &&
227 git branch atomic-prune-delete &&
228 git clone . atomic &&
229 git branch --delete atomic-prune-delete &&
230 git branch atomic-prune-create &&
231 git rev-parse refs/heads/atomic-prune-create >actual &&
233 git -C atomic fetch --prune --atomic origin &&
234 test_must_fail git -C atomic rev-parse refs/remotes/origin/atomic-prune-delete &&
235 git -C atomic rev-parse refs/remotes/origin/atomic-prune-create >expected &&
236 test_cmp expected actual
239 test_expect_success
'fetch --atomic aborts with non-fast-forward update' '
240 test_when_finished "rm -rf \"$D\"/atomic" &&
243 git branch atomic-non-ff &&
244 git clone . atomic &&
245 git rev-parse HEAD >actual &&
247 git branch atomic-new-branch &&
248 parent_commit=$(git rev-parse atomic-non-ff~) &&
249 git update-ref refs/heads/atomic-non-ff $parent_commit &&
251 test_must_fail git -C atomic fetch --atomic origin refs/heads/*:refs/remotes/origin/* &&
252 test_must_fail git -C atomic rev-parse refs/remotes/origin/atomic-new-branch &&
253 git -C atomic rev-parse refs/remotes/origin/atomic-non-ff >expected &&
254 test_cmp expected actual &&
255 test_must_be_empty atomic/.git/FETCH_HEAD
258 test_expect_success
'fetch --atomic executes a single reference transaction only' '
259 test_when_finished "rm -rf \"$D\"/atomic" &&
262 git clone . atomic &&
263 git branch atomic-hooks-1 &&
264 git branch atomic-hooks-2 &&
265 head_oid=$(git rev-parse HEAD) &&
267 cat >expected <<-EOF &&
269 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1
270 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2
272 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1
273 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2
276 rm -f atomic/actual &&
277 test_hook -C atomic reference-transaction <<-\EOF &&
278 ( echo "$*" && cat ) >>actual
281 git -C atomic fetch --atomic origin &&
282 test_cmp expected atomic/actual
285 test_expect_success
'fetch --atomic aborts all reference updates if hook aborts' '
286 test_when_finished "rm -rf \"$D\"/atomic" &&
289 git clone . atomic &&
290 git branch atomic-hooks-abort-1 &&
291 git branch atomic-hooks-abort-2 &&
292 git branch atomic-hooks-abort-3 &&
293 git tag atomic-hooks-abort &&
294 head_oid=$(git rev-parse HEAD) &&
296 cat >expected <<-EOF &&
298 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-1
299 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-2
300 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-3
301 $ZERO_OID $head_oid refs/tags/atomic-hooks-abort
303 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-1
304 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-2
305 $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-3
306 $ZERO_OID $head_oid refs/tags/atomic-hooks-abort
309 rm -f atomic/actual &&
310 test_hook -C atomic/.git reference-transaction <<-\EOF &&
311 ( echo "$*" && cat ) >>actual
315 git -C atomic for-each-ref >expected-refs &&
316 test_must_fail git -C atomic fetch --tags --atomic origin &&
317 git -C atomic for-each-ref >actual-refs &&
318 test_cmp expected-refs actual-refs &&
319 test_must_be_empty atomic/.git/FETCH_HEAD
322 test_expect_success
'fetch --atomic --append appends to FETCH_HEAD' '
323 test_when_finished "rm -rf \"$D\"/atomic" &&
326 git clone . atomic &&
327 oid=$(git rev-parse HEAD) &&
329 git branch atomic-fetch-head-1 &&
330 git -C atomic fetch --atomic origin atomic-fetch-head-1 &&
331 test_line_count = 1 atomic/.git/FETCH_HEAD &&
333 git branch atomic-fetch-head-2 &&
334 git -C atomic fetch --atomic --append origin atomic-fetch-head-2 &&
335 test_line_count = 2 atomic/.git/FETCH_HEAD &&
336 cp atomic/.git/FETCH_HEAD expected &&
338 test_hook -C atomic reference-transaction <<-\EOF &&
342 git branch atomic-fetch-head-3 &&
343 test_must_fail git -C atomic fetch --atomic --append origin atomic-fetch-head-3 &&
344 test_cmp expected atomic/.git/FETCH_HEAD
347 test_expect_success
'--refmap="" ignores configured refspec' '
348 cd "$TRASH_DIRECTORY" &&
349 git clone "$D" remote-refs &&
350 git -C remote-refs rev-parse remotes/origin/main >old &&
351 git -C remote-refs update-ref refs/remotes/origin/main main~1 &&
352 git -C remote-refs rev-parse remotes/origin/main >new &&
353 git -C remote-refs fetch --refmap= origin "+refs/heads/*:refs/hidden/origin/*" &&
354 git -C remote-refs rev-parse remotes/origin/main >actual &&
355 test_cmp new actual &&
356 git -C remote-refs fetch origin &&
357 git -C remote-refs rev-parse remotes/origin/main >actual &&
361 test_expect_success
'--refmap="" and --prune' '
362 git -C remote-refs update-ref refs/remotes/origin/foo/otherbranch main &&
363 git -C remote-refs update-ref refs/hidden/foo/otherbranch main &&
364 git -C remote-refs fetch --prune --refmap="" origin +refs/heads/*:refs/hidden/* &&
365 git -C remote-refs rev-parse remotes/origin/foo/otherbranch &&
366 test_must_fail git -C remote-refs rev-parse refs/hidden/foo/otherbranch &&
367 git -C remote-refs fetch --prune origin &&
368 test_must_fail git -C remote-refs rev-parse remotes/origin/foo/otherbranch
371 test_expect_success
'fetch tags when there is no tags' '
383 test_expect_success
'fetch following tags' '
386 git tag -a -m "annotated" anno HEAD &&
387 git tag light HEAD &&
393 git fetch .. :track &&
394 git show-ref --verify refs/tags/anno &&
395 git show-ref --verify refs/tags/light
399 test_expect_success
'fetch uses remote ref names to describe new refs' '
401 git init descriptive &&
404 git config remote.o.url .. &&
405 git config remote.o.fetch "refs/heads/*:refs/crazyheads/*" &&
406 git config --add remote.o.fetch "refs/others/*:refs/heads/*" &&
409 git tag -a -m "Descriptive tag" descriptive-tag &&
410 git branch descriptive-branch &&
411 git checkout descriptive-branch &&
412 echo "Nuts" >crazy &&
414 git commit -a -m "descriptive commit" &&
415 git update-ref refs/others/crazy HEAD &&
418 git fetch o 2>actual &&
419 test_grep "new branch.* -> refs/crazyheads/descriptive-branch$" actual &&
420 test_grep "new tag.* -> descriptive-tag$" actual &&
421 test_grep "new ref.* -> crazy$" actual
426 test_expect_success
'fetch must not resolve short tag name' '
434 test_must_fail git fetch .. anno:five
438 test_expect_success
'fetch can now resolve short remote name' '
441 git update-ref refs/remotes/six/HEAD HEAD &&
450 test_expect_success
'create bundle 1' '
452 echo >file updated again by origin &&
453 git commit -a -m "tip" &&
454 git bundle create --version=3 bundle1 main^..main
457 test_expect_success
'header of bundle looks right' '
458 cat >expect <<-EOF &&
460 @object-format=$(test_oid algo)
461 -OID updated by origin
465 sed -e "s/$OID_REGEX/OID/g" -e "5q" "$D"/bundle1 >actual &&
466 test_cmp expect actual
469 test_expect_success
'create bundle 2' '
471 git bundle create bundle2 main~2..main
474 test_expect_success
'unbundle 1' '
476 git checkout -b some-branch &&
477 test_must_fail git fetch "$D/bundle1" main:main
481 test_expect_success
'bundle 1 has only 3 files ' '
483 test_bundle_object_count bundle1 3
486 test_expect_success
'unbundle 2' '
488 git fetch ../bundle2 main:main &&
489 test "tip" = "$(git log -1 --pretty=oneline main | cut -d" " -f2)"
492 test_expect_success
'bundle does not prerequisite objects' '
496 git commit -m add.file2 file2 &&
497 git bundle create bundle3 -1 HEAD &&
498 test_bundle_object_count bundle3 3
501 test_expect_success
'bundle should be able to create a full history' '
504 git tag -a -m "1.0" v1.0 main &&
505 git bundle create bundle4 v1.0
509 test_expect_success
'fetch with a non-applying branch.<name>.merge' '
510 git config branch.main.remote yeti &&
511 git config branch.main.merge refs/heads/bigfoot &&
512 git config remote.blub.url one &&
513 git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
517 # URL supplied to fetch does not match the url of the configured branch's remote
518 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
519 one_head=$(cd one && git rev-parse HEAD) &&
520 this_head=$(git rev-parse HEAD) &&
521 rm .git/FETCH_HEAD &&
523 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
524 test $this_head = "$(git rev-parse --verify HEAD)"
527 # URL supplied to fetch matches the url of the configured branch's remote and
528 # the merge spec matches the branch the remote HEAD points to
529 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [2]' '
530 one_ref=$(cd one && git symbolic-ref HEAD) &&
531 git config branch.main.remote blub &&
532 git config branch.main.merge "$one_ref" &&
533 rm .git/FETCH_HEAD &&
535 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
536 test $this_head = "$(git rev-parse --verify HEAD)"
539 # URL supplied to fetch matches the url of the configured branch's remote, but
540 # the merge spec does not match the branch the remote HEAD points to
541 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
542 git config branch.main.merge "${one_ref}_not" &&
543 rm .git/FETCH_HEAD &&
545 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
546 test $this_head = "$(git rev-parse --verify HEAD)"
549 # the strange name is: a\!'b
550 test_expect_success
'quoting of a strangely named repo' '
551 test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
552 grep "fatal: '\''a\\\\!'\''b'\''" result
555 test_expect_success
'bundle should record HEAD correctly' '
558 git bundle create bundle5 HEAD main &&
559 git bundle list-heads bundle5 >actual &&
560 for h in HEAD refs/heads/main
562 echo "$(git rev-parse --verify $h) $h" || return 1
564 test_cmp expect actual
568 test_expect_success
'mark initial state of origin/main' '
571 git tag base-origin-main refs/remotes/origin/main
575 test_expect_success
'explicit fetch should update tracking' '
578 git branch -f side &&
581 git update-ref refs/remotes/origin/main base-origin-main &&
582 o=$(git rev-parse --verify refs/remotes/origin/main) &&
583 git fetch origin main &&
584 n=$(git rev-parse --verify refs/remotes/origin/main) &&
586 test_must_fail git rev-parse --verify refs/remotes/origin/side
590 test_expect_success
'explicit pull should update tracking' '
593 git branch -f side &&
596 git update-ref refs/remotes/origin/main base-origin-main &&
597 o=$(git rev-parse --verify refs/remotes/origin/main) &&
598 git pull origin main &&
599 n=$(git rev-parse --verify refs/remotes/origin/main) &&
601 test_must_fail git rev-parse --verify refs/remotes/origin/side
605 test_expect_success
'explicit --refmap is allowed only with command-line refspec' '
609 test_must_fail git fetch --refmap="*:refs/remotes/none/*"
613 test_expect_success
'explicit --refmap option overrides remote.*.fetch' '
615 git branch -f side &&
618 git update-ref refs/remotes/origin/main base-origin-main &&
619 o=$(git rev-parse --verify refs/remotes/origin/main) &&
620 git fetch --refmap="refs/heads/*:refs/remotes/other/*" origin main &&
621 n=$(git rev-parse --verify refs/remotes/origin/main) &&
623 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
624 git rev-parse --verify refs/remotes/other/main
628 test_expect_success
'explicitly empty --refmap option disables remote.*.fetch' '
630 git branch -f side &&
633 git update-ref refs/remotes/origin/main base-origin-main &&
634 o=$(git rev-parse --verify refs/remotes/origin/main) &&
635 git fetch --refmap="" origin main &&
636 n=$(git rev-parse --verify refs/remotes/origin/main) &&
638 test_must_fail git rev-parse --verify refs/remotes/origin/side
642 test_expect_success
'configured fetch updates tracking' '
645 git branch -f side &&
648 git update-ref refs/remotes/origin/main base-origin-main &&
649 o=$(git rev-parse --verify refs/remotes/origin/main) &&
651 n=$(git rev-parse --verify refs/remotes/origin/main) &&
653 git rev-parse --verify refs/remotes/origin/side
657 test_expect_success
'non-matching refspecs do not confuse tracking update' '
659 git update-ref refs/odd/location HEAD &&
662 git update-ref refs/remotes/origin/main base-origin-main &&
663 git config --add remote.origin.fetch \
664 refs/odd/location:refs/remotes/origin/odd &&
665 o=$(git rev-parse --verify refs/remotes/origin/main) &&
666 git fetch origin main &&
667 n=$(git rev-parse --verify refs/remotes/origin/main) &&
669 test_must_fail git rev-parse --verify refs/remotes/origin/odd
673 test_expect_success
'pushing nonexistent branch by mistake should not segv' '
676 test_must_fail git push seven no:no
680 test_expect_success
'auto tag following fetches minimum' '
683 git clone .git follow &&
684 git checkout HEAD^0 &&
686 for i in 1 2 3 4 5 6 7
689 git commit -m $i -a &&
690 git tag -a -m $i excess-$i || exit 1
700 test_expect_success
'refuse to fetch into the current branch' '
702 test_must_fail git fetch . side:main
706 test_expect_success
'fetch into the current branch with --update-head-ok' '
708 git fetch --update-head-ok . side:main
712 test_expect_success
'fetch --dry-run does not touch FETCH_HEAD, but still prints what would be written' '
713 rm -f .git/FETCH_HEAD err &&
714 git fetch --dry-run . 2>err &&
715 ! test -f .git/FETCH_HEAD &&
719 test_expect_success
'--no-write-fetch-head does not touch FETCH_HEAD, and does not print what would be written' '
720 rm -f .git/FETCH_HEAD err &&
721 git fetch --no-write-fetch-head . 2>err &&
722 ! test -f .git/FETCH_HEAD &&
723 ! grep FETCH_HEAD err
726 test_expect_success
'--write-fetch-head gets defeated by --dry-run' '
727 rm -f .git/FETCH_HEAD &&
728 git fetch --dry-run --write-fetch-head . &&
729 ! test -f .git/FETCH_HEAD
732 test_expect_success
"should be able to fetch with duplicate refspecs" '
737 git config branch.main.remote three &&
738 git config remote.three.url ../three/.git &&
739 git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
740 git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
745 test_expect_success
'LHS of refspec follows ref disambiguation rules' '
746 mkdir lhs-ambiguous &&
750 test_commit -C server unwanted &&
751 test_commit -C server wanted &&
755 # Check a name coming after "refs" alphabetically ...
756 git -C server update-ref refs/heads/s wanted &&
757 git -C server update-ref refs/heads/refs/heads/s unwanted &&
758 git -C client fetch ../server +refs/heads/s:refs/heads/checkthis &&
759 git -C server rev-parse wanted >expect &&
760 git -C client rev-parse checkthis >actual &&
761 test_cmp expect actual &&
763 # ... and one before.
764 git -C server update-ref refs/heads/q wanted &&
765 git -C server update-ref refs/heads/refs/heads/q unwanted &&
766 git -C client fetch ../server +refs/heads/q:refs/heads/checkthis &&
767 git -C server rev-parse wanted >expect &&
768 git -C client rev-parse checkthis >actual &&
769 test_cmp expect actual &&
771 # Tags are preferred over branches like refs/{heads,tags}/*
772 git -C server update-ref refs/tags/t wanted &&
773 git -C server update-ref refs/heads/t unwanted &&
774 git -C client fetch ../server +t:refs/heads/checkthis &&
775 git -C server rev-parse wanted >expect &&
776 git -C client rev-parse checkthis >actual
780 test_expect_success
'fetch.writeCommitGraph' '
781 git clone three write &&
788 git -c fetch.writeCommitGraph fetch origin &&
789 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
793 test_expect_success
'fetch.writeCommitGraph with submodules' '
794 test_config_global protocol.file.allow always &&
795 git clone dups super &&
798 git submodule add "file://$TRASH_DIRECTORY/three" &&
799 git commit -m "add submodule"
801 git clone "super" super-clone &&
804 rm -rf .git/objects/info &&
805 git -c fetch.writeCommitGraph=true fetch origin &&
806 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain &&
807 git -c fetch.writeCommitGraph=true fetch --recurse-submodules origin
811 # fetches from first configured url
812 test_expect_success
'fetch from multiple configured URLs in single remote' '
814 git remote add multipleurls url1 &&
815 git remote set-url --add multipleurls url2 &&
816 git fetch multipleurls
819 # configured prune tests
821 set_config_tristate
() {
829 key
=$
(echo $1 |
sed -e 's/^remote\.origin/fetch/')
830 git_fetch_c
="$git_fetch_c -c $key=$2"
835 test_configured_prune
() {
836 test_configured_prune_type
"$@" "name"
837 test_configured_prune_type
"$@" "link"
840 test_configured_prune_type
() {
842 remote_origin_prune
=$2
844 remote_origin_prune_tags
=$4
850 if test -z "$cmdline_setup"
852 test_expect_success
'setup cmdline_setup variable for subsequent test' '
853 remote_url="file://$(git -C one config remote.origin.url)" &&
854 remote_fetch="$(git -C one config remote.origin.fetch)" &&
855 cmdline_setup="\"$remote_url\" \"$remote_fetch\""
859 if test "$mode" = 'link'
863 if test "$cmdline" = ""
865 new_cmdline
=$cmdline_setup
867 new_cmdline
=$
(perl
-e '
868 my ($cmdline, $url) = @ARGV;
869 $cmdline =~ s[origin(?!/)][quotemeta($url)]ge;
871 ' -- "$cmdline" "$remote_url")
874 if test "$fetch_prune_tags" = 'true' ||
875 test "$remote_origin_prune_tags" = 'true'
877 if ! printf '%s' "$cmdline\n" |
grep -q refs
/remotes
/origin
/
879 new_cmdline
="$new_cmdline refs/tags/*:refs/tags/*"
883 cmdline
="$new_cmdline"
886 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" '
887 # make sure a newbranch is there in . and also in one
888 git branch -f newbranch &&
892 test_unconfig fetch.prune &&
893 test_unconfig fetch.pruneTags &&
894 test_unconfig remote.origin.prune &&
895 test_unconfig remote.origin.pruneTags &&
896 git fetch '"$cmdline_setup"' &&
897 git rev-parse --verify refs/remotes/origin/newbranch &&
898 git rev-parse --verify refs/tags/newtag
902 git branch -d newbranch &&
909 set_config_tristate fetch.prune $fetch_prune &&
910 set_config_tristate fetch.pruneTags $fetch_prune_tags &&
911 set_config_tristate remote.origin.prune $remote_origin_prune &&
912 set_config_tristate remote.origin.pruneTags $remote_origin_prune_tags &&
914 if test "$mode" != "link"
918 git$git_fetch_c fetch '"$cmdline"' &&
919 case "$expected_branch" in
921 test_must_fail git rev-parse --verify refs/remotes/origin/newbranch
924 git rev-parse --verify refs/remotes/origin/newbranch
927 case "$expected_tag" in
929 test_must_fail git rev-parse --verify refs/tags/newtag
932 git rev-parse --verify refs/tags/newtag
939 # $1 config: fetch.prune
940 # $2 config: remote.<name>.prune
941 # $3 config: fetch.pruneTags
942 # $4 config: remote.<name>.pruneTags
943 # $5 expect: branch to be pruned?
944 # $6 expect: tag to be pruned?
945 # $7 git-fetch $cmdline:
947 # $1 $2 $3 $4 $5 $6 $7
948 test_configured_prune
unset unset unset unset kept kept
""
949 test_configured_prune
unset unset unset unset kept kept
"--no-prune"
950 test_configured_prune
unset unset unset unset pruned kept
"--prune"
951 test_configured_prune
unset unset unset unset kept pruned \
952 "--prune origin refs/tags/*:refs/tags/*"
953 test_configured_prune
unset unset unset unset pruned pruned \
954 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
956 test_configured_prune false
unset unset unset kept kept
""
957 test_configured_prune false
unset unset unset kept kept
"--no-prune"
958 test_configured_prune false
unset unset unset pruned kept
"--prune"
960 test_configured_prune true
unset unset unset pruned kept
""
961 test_configured_prune true
unset unset unset pruned kept
"--prune"
962 test_configured_prune true
unset unset unset kept kept
"--no-prune"
964 test_configured_prune
unset false
unset unset kept kept
""
965 test_configured_prune
unset false
unset unset kept kept
"--no-prune"
966 test_configured_prune
unset false
unset unset pruned kept
"--prune"
968 test_configured_prune false false
unset unset kept kept
""
969 test_configured_prune false false
unset unset kept kept
"--no-prune"
970 test_configured_prune false false
unset unset pruned kept
"--prune"
971 test_configured_prune false false
unset unset kept pruned \
972 "--prune origin refs/tags/*:refs/tags/*"
973 test_configured_prune false false
unset unset pruned pruned \
974 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
976 test_configured_prune true false
unset unset kept kept
""
977 test_configured_prune true false
unset unset pruned kept
"--prune"
978 test_configured_prune true false
unset unset kept kept
"--no-prune"
980 test_configured_prune
unset true
unset unset pruned kept
""
981 test_configured_prune
unset true
unset unset kept kept
"--no-prune"
982 test_configured_prune
unset true
unset unset pruned kept
"--prune"
984 test_configured_prune false true
unset unset pruned kept
""
985 test_configured_prune false true
unset unset kept kept
"--no-prune"
986 test_configured_prune false true
unset unset pruned kept
"--prune"
988 test_configured_prune true true
unset unset pruned kept
""
989 test_configured_prune true true
unset unset pruned kept
"--prune"
990 test_configured_prune true true
unset unset kept kept
"--no-prune"
991 test_configured_prune true true
unset unset kept pruned \
992 "--prune origin refs/tags/*:refs/tags/*"
993 test_configured_prune true true
unset unset pruned pruned \
994 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
996 # --prune-tags on its own does nothing, needs --prune as well, same
997 # for fetch.pruneTags without fetch.prune
998 test_configured_prune
unset unset unset unset kept kept
"--prune-tags"
999 test_configured_prune
unset unset true
unset kept kept
""
1000 test_configured_prune
unset unset unset true kept kept
""
1002 # These will prune the tags
1003 test_configured_prune
unset unset unset unset pruned pruned
"--prune --prune-tags"
1004 test_configured_prune true
unset true
unset pruned pruned
""
1005 test_configured_prune
unset true
unset true pruned pruned
""
1007 # remote.<name>.pruneTags overrides fetch.pruneTags, just like
1008 # remote.<name>.prune overrides fetch.prune if set.
1009 test_configured_prune true
unset true
unset pruned pruned
""
1010 test_configured_prune false true false true pruned pruned
""
1011 test_configured_prune true false true false kept kept
""
1013 # When --prune-tags is supplied it's ignored if an explicit refspec is
1014 # given, same for the configuration options.
1015 test_configured_prune
unset unset unset unset pruned kept \
1016 "--prune --prune-tags origin +refs/heads/*:refs/remotes/origin/*"
1017 test_configured_prune
unset unset true
unset pruned kept \
1018 "--prune origin +refs/heads/*:refs/remotes/origin/*"
1019 test_configured_prune
unset unset unset true pruned kept \
1020 "--prune origin +refs/heads/*:refs/remotes/origin/*"
1022 # Pruning that also takes place if a file:// url replaces a named
1023 # remote. However, because there's no implicit
1024 # +refs/heads/*:refs/remotes/origin/* refspec and supplying it on the
1025 # command-line negates --prune-tags, the branches will not be pruned.
1026 test_configured_prune_type
unset unset unset unset kept kept
"origin --prune-tags" "name"
1027 test_configured_prune_type
unset unset unset unset kept kept
"origin --prune-tags" "link"
1028 test_configured_prune_type
unset unset unset unset pruned pruned
"origin --prune --prune-tags" "name"
1029 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "link"
1030 test_configured_prune_type
unset unset unset unset pruned pruned
"--prune --prune-tags origin" "name"
1031 test_configured_prune_type
unset unset unset unset kept pruned
"--prune --prune-tags origin" "link"
1032 test_configured_prune_type
unset unset true
unset pruned pruned
"--prune origin" "name"
1033 test_configured_prune_type
unset unset true
unset kept pruned
"--prune origin" "link"
1034 test_configured_prune_type
unset unset unset true pruned pruned
"--prune origin" "name"
1035 test_configured_prune_type
unset unset unset true kept pruned
"--prune origin" "link"
1036 test_configured_prune_type true
unset true
unset pruned pruned
"origin" "name"
1037 test_configured_prune_type true
unset true
unset kept pruned
"origin" "link"
1038 test_configured_prune_type
unset true true
unset pruned pruned
"origin" "name"
1039 test_configured_prune_type
unset true true
unset kept pruned
"origin" "link"
1040 test_configured_prune_type
unset true
unset true pruned pruned
"origin" "name"
1041 test_configured_prune_type
unset true
unset true kept pruned
"origin" "link"
1043 # When all remote.origin.fetch settings are deleted a --prune
1044 # --prune-tags still implicitly supplies refs/tags/*:refs/tags/* so
1045 # tags, but not tracking branches, will be deleted.
1046 test_expect_success
'remove remote.origin.fetch "one"' '
1049 git config --unset-all remote.origin.fetch
1052 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "name"
1053 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "link"
1055 test_expect_success
'all boundary commits are excluded' '
1057 test_commit oneside &&
1058 git checkout HEAD^ &&
1059 test_commit otherside &&
1060 git checkout main &&
1062 git merge otherside &&
1063 ad=$(git log --no-walk --format=%ad HEAD) &&
1064 git bundle create twoside-boundary.bdl main --since="$ad" &&
1065 test_bundle_object_count --thin twoside-boundary.bdl 3
1068 test_expect_success
'fetch --prune prints the remotes url' '
1069 git branch goodbye &&
1070 git clone . only-prunes &&
1071 git branch -D goodbye &&
1074 git fetch --prune origin 2>&1 | head -n1 >../actual
1076 echo "From ${D}/." >expect &&
1077 test_cmp expect actual
1080 test_expect_success
'branchname D/F conflict resolved by --prune' '
1081 git branch dir/file &&
1082 git clone . prune-df-conflict &&
1083 git branch -D dir/file &&
1086 cd prune-df-conflict &&
1087 git fetch --prune &&
1088 git rev-parse origin/dir >../actual
1090 git rev-parse dir >expect &&
1091 test_cmp expect actual
1094 test_expect_success
'branchname D/F conflict rejected with targeted error message' '
1095 git clone . df-conflict-error &&
1096 git branch dir_conflict &&
1098 cd df-conflict-error &&
1099 git update-ref refs/remotes/origin/dir_conflict/file HEAD &&
1100 test_must_fail git fetch 2>err &&
1101 test_grep "error: some local refs could not be updated; try running" err &&
1102 test_grep " ${SQ}git remote prune origin${SQ} to remove any old, conflicting branches" err &&
1103 git pack-refs --all &&
1104 test_must_fail git fetch 2>err-packed &&
1105 test_grep "error: some local refs could not be updated; try running" err-packed &&
1106 test_grep " ${SQ}git remote prune origin${SQ} to remove any old, conflicting branches" err-packed
1110 test_expect_success
'fetching a one-level ref works' '
1111 test_commit extra &&
1112 git reset --hard HEAD^ &&
1113 git update-ref refs/foo extra &&
1114 git init one-level &&
1117 git fetch .. HEAD refs/foo
1121 test_expect_success
'fetching with auto-gc does not lock up' '
1122 write_script askyesno <<-\EOF &&
1126 git clone "file://$D" auto-gc &&
1127 test_commit test2 &&
1130 git config fetch.unpackLimit 1 &&
1131 git config gc.autoPackLimit 1 &&
1132 git config gc.autoDetach false &&
1133 GIT_ASK_YESNO="$D/askyesno" git fetch --verbose >fetch.out 2>&1 &&
1134 test_grep "Auto packing the repository" fetch.out &&
1135 ! grep "Should I try again" fetch.out
1139 for section
in fetch transfer
1141 test_expect_success
"$section.hideRefs affects connectivity check" '
1142 GIT_TRACE="$PWD"/trace git -c $section.hideRefs=refs -c \
1143 $section.hideRefs="!refs/tags/" fetch &&
1144 grep "git rev-list .*--exclude-hidden=fetch" trace
1148 test_expect_success
'prepare source branch' '
1149 echo one >onebranch &&
1150 git checkout --orphan onebranch &&
1151 git rm --cached -r . &&
1152 git add onebranch &&
1153 git commit -m onebranch &&
1154 git rev-list --objects onebranch -- >actual &&
1155 # 3 objects should be created, at least ...
1156 test 3 -le $(wc -l <actual)
1159 validate_store_type
() {
1160 git
-C dest count-objects
-v >actual
&&
1161 case "$store_type" in
1163 grep "^count: 0$" actual
;;
1165 grep "^packs: 0$" actual
;;
1167 echo "store_type is $store_type"
1173 test_unpack_limit
() {
1176 case "$store_type" in
1177 packed
) fetch_limit
=1 transfer_limit
=10000 ;;
1178 loose
) fetch_limit
=10000 transfer_limit
=1 ;;
1181 test_expect_success
"fetch trumps transfer limit" '
1183 git --bare init dest &&
1184 git -C dest config fetch.unpacklimit $fetch_limit &&
1185 git -C dest config transfer.unpacklimit $transfer_limit &&
1186 git -C dest fetch .. onebranch &&
1191 test_unpack_limit packed
1192 test_unpack_limit loose
1194 setup_negotiation_tip
() {
1197 USE_PROTOCOL_V2
="$3"
1199 rm -rf "$SERVER" client trace
&&
1200 git init
-b main
"$SERVER" &&
1201 test_commit
-C "$SERVER" alpha_1
&&
1202 test_commit
-C "$SERVER" alpha_2
&&
1203 git
-C "$SERVER" checkout
--orphan beta
&&
1204 test_commit
-C "$SERVER" beta_1
&&
1205 test_commit
-C "$SERVER" beta_2
&&
1207 git clone
"$URL" client
&&
1209 if test "$USE_PROTOCOL_V2" -eq 1
1211 git
-C "$SERVER" config protocol.version
2 &&
1212 git
-C client config protocol.version
2
1215 test_commit
-C "$SERVER" beta_s
&&
1216 git
-C "$SERVER" checkout main
&&
1217 test_commit
-C "$SERVER" alpha_s
&&
1218 git
-C "$SERVER" tag
-d alpha_1 alpha_2 beta_1 beta_2
1221 check_negotiation_tip
() {
1222 # Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2
1223 ALPHA_1
=$
(git
-C client rev-parse alpha_1
) &&
1224 grep "fetch> have $ALPHA_1" trace
&&
1225 BETA_1
=$
(git
-C client rev-parse beta_1
) &&
1226 grep "fetch> have $BETA_1" trace
&&
1227 ALPHA_2
=$
(git
-C client rev-parse alpha_2
) &&
1228 ! grep "fetch> have $ALPHA_2" trace
&&
1229 BETA_2
=$
(git
-C client rev-parse beta_2
) &&
1230 ! grep "fetch> have $BETA_2" trace
1233 test_expect_success
'--negotiation-tip limits "have" lines sent' '
1234 setup_negotiation_tip server server 0 &&
1235 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1236 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1237 origin alpha_s beta_s &&
1238 check_negotiation_tip
1241 test_expect_success
'--negotiation-tip understands globs' '
1242 setup_negotiation_tip server server 0 &&
1243 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1244 --negotiation-tip=*_1 \
1245 origin alpha_s beta_s &&
1246 check_negotiation_tip
1249 test_expect_success
'--negotiation-tip understands abbreviated SHA-1' '
1250 setup_negotiation_tip server server 0 &&
1251 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1252 --negotiation-tip=$(git -C client rev-parse --short alpha_1) \
1253 --negotiation-tip=$(git -C client rev-parse --short beta_1) \
1254 origin alpha_s beta_s &&
1255 check_negotiation_tip
1258 test_expect_success
'--negotiation-tip rejects missing OIDs' '
1259 setup_negotiation_tip server server 0 &&
1260 test_must_fail git -C client fetch \
1261 --negotiation-tip=alpha_1 \
1262 --negotiation-tip=$(test_oid zero) \
1263 origin alpha_s beta_s 2>err &&
1264 cat >fatal-expect <<-EOF &&
1265 fatal: the object $(test_oid zero) does not exist
1267 grep fatal: err >fatal-actual &&
1268 test_cmp fatal-expect fatal-actual
1271 test_expect_success SYMLINKS
'clone does not get confused by a D/F conflict' '
1272 git init df-conflict &&
1278 git commit -m symlink &&
1282 write_script a/hooks/post-checkout <<-EOF &&
1284 echo whoopsie >"$TRASH_DIRECTORY"/whoops
1286 git add a/hooks/post-checkout &&
1288 git commit -m post-checkout
1290 git clone df-conflict clone 2>err &&
1291 test_grep ! WHOOPS err &&
1292 test_path_is_missing whoops
1295 .
"$TEST_DIRECTORY"/lib-httpd.sh
1298 test_expect_success
'--negotiation-tip limits "have" lines sent with HTTP protocol v2' '
1299 setup_negotiation_tip "$HTTPD_DOCUMENT_ROOT_PATH/server" \
1300 "$HTTPD_URL/smart/server" 1 &&
1301 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1302 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1303 origin alpha_s beta_s &&
1304 check_negotiation_tip
1307 # DO NOT add non-httpd-specific tests here, because the last part of this
1308 # test script is only executed when httpd is available and enabled.