2 # Copyright (c) 2006, Junio C Hamano.
4 test_description
='Per branch config variables affects "git fetch".
12 test_bundle_object_count
() {
13 git verify-pack
-v "$1" >verify.out
&&
14 test "$2" = $
(grep "^$OID_REGEX " verify.out |
wc -l)
17 convert_bundle_to_pack
() {
18 while read x
&& test -n "$x"
25 test_expect_success setup
'
26 echo >file original &&
28 git commit -a -m original'
30 test_expect_success
"clone and setup child repos" '
34 echo >file updated by one &&
35 git commit -a -m "updated by one"
40 git config branch.master.remote one &&
41 git config remote.one.url ../one/.git/ &&
42 git config remote.one.fetch refs/heads/master:refs/heads/one
47 git config branch.master.remote two &&
48 git config branch.master.merge refs/heads/one &&
49 mkdir -p .git/remotes &&
51 echo "URL: ../two/.git/"
52 echo "Pull: refs/heads/master:refs/heads/two"
53 echo "Pull: refs/heads/one:refs/heads/one"
60 test_expect_success
"fetch test" '
62 echo >file updated by origin &&
63 git commit -a -m "updated by origin" &&
66 git rev-parse --verify refs/heads/one &&
67 mine=$(git rev-parse refs/heads/one) &&
68 his=$(cd ../one && git rev-parse refs/heads/master) &&
69 test "z$mine" = "z$his"
72 test_expect_success
"fetch test for-merge" '
76 git rev-parse --verify refs/heads/two &&
77 git rev-parse --verify refs/heads/one &&
78 master_in_two=$(cd ../two && git rev-parse master) &&
79 one_in_two=$(cd ../two && git rev-parse one) &&
82 echo "$master_in_two not-for-merge"
84 cut -f -2 .git/FETCH_HEAD >actual &&
85 test_cmp expected actual'
87 test_expect_success
'fetch --prune on its own works as expected' '
91 git update-ref refs/remotes/origin/extrabranch master &&
93 git fetch --prune origin &&
94 test_must_fail git rev-parse origin/extrabranch
97 test_expect_success
'fetch --prune with a branch name keeps branches' '
99 git clone . prune-branch &&
101 git update-ref refs/remotes/origin/extrabranch master &&
103 git fetch --prune origin master &&
104 git rev-parse origin/extrabranch
107 test_expect_success
'fetch --prune with a namespace keeps other namespaces' '
109 git clone . prune-namespace &&
110 cd prune-namespace &&
112 git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
113 git rev-parse origin/master
116 test_expect_success
'fetch --prune handles overlapping refspecs' '
118 git update-ref refs/pull/42/head master &&
119 git clone . prune-overlapping &&
120 cd prune-overlapping &&
121 git config --add remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
123 git fetch --prune origin &&
124 git rev-parse origin/master &&
125 git rev-parse origin/pr/42 &&
127 git config --unset-all remote.origin.fetch &&
128 git config remote.origin.fetch refs/pull/*/head:refs/remotes/origin/pr/* &&
129 git config --add remote.origin.fetch refs/heads/*:refs/remotes/origin/* &&
131 git fetch --prune origin &&
132 git rev-parse origin/master &&
133 git rev-parse origin/pr/42
136 test_expect_success
'fetch --prune --tags prunes branches but not tags' '
138 git clone . prune-tags &&
140 git tag sometag master &&
141 # Create what looks like a remote-tracking branch from an earlier
142 # fetch that has since been deleted from the remote:
143 git update-ref refs/remotes/origin/fake-remote master &&
145 git fetch --prune --tags origin &&
146 git rev-parse origin/master &&
147 test_must_fail git rev-parse origin/fake-remote &&
148 git rev-parse sometag
151 test_expect_success
'fetch --prune --tags with branch does not prune other things' '
153 git clone . prune-tags-branch &&
154 cd prune-tags-branch &&
155 git tag sometag master &&
156 git update-ref refs/remotes/origin/extrabranch master &&
158 git fetch --prune --tags origin master &&
159 git rev-parse origin/extrabranch &&
160 git rev-parse sometag
163 test_expect_success
'fetch --prune --tags with refspec prunes based on refspec' '
165 git clone . prune-tags-refspec &&
166 cd prune-tags-refspec &&
167 git tag sometag master &&
168 git update-ref refs/remotes/origin/foo/otherbranch master &&
169 git update-ref refs/remotes/origin/extrabranch master &&
171 git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* &&
172 test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch &&
173 git rev-parse origin/extrabranch &&
174 git rev-parse sometag
177 test_expect_success
'--refmap="" ignores configured refspec' '
178 cd "$TRASH_DIRECTORY" &&
179 git clone "$D" remote-refs &&
180 git -C remote-refs rev-parse remotes/origin/master >old &&
181 git -C remote-refs update-ref refs/remotes/origin/master master~1 &&
182 git -C remote-refs rev-parse remotes/origin/master >new &&
183 git -C remote-refs fetch --refmap= origin "+refs/heads/*:refs/hidden/origin/*" &&
184 git -C remote-refs rev-parse remotes/origin/master >actual &&
185 test_cmp new actual &&
186 git -C remote-refs fetch origin &&
187 git -C remote-refs rev-parse remotes/origin/master >actual &&
191 test_expect_success
'--refmap="" and --prune' '
192 git -C remote-refs update-ref refs/remotes/origin/foo/otherbranch master &&
193 git -C remote-refs update-ref refs/hidden/foo/otherbranch master &&
194 git -C remote-refs fetch --prune --refmap="" origin +refs/heads/*:refs/hidden/* &&
195 git -C remote-refs rev-parse remotes/origin/foo/otherbranch &&
196 test_must_fail git -C remote-refs rev-parse refs/hidden/foo/otherbranch &&
197 git -C remote-refs fetch --prune origin &&
198 test_must_fail git -C remote-refs rev-parse remotes/origin/foo/otherbranch
201 test_expect_success
'fetch tags when there is no tags' '
213 test_expect_success
'fetch following tags' '
216 git tag -a -m "annotated" anno HEAD &&
217 git tag light HEAD &&
223 git fetch .. :track &&
224 git show-ref --verify refs/tags/anno &&
225 git show-ref --verify refs/tags/light
229 test_expect_success
'fetch uses remote ref names to describe new refs' '
231 git init descriptive &&
234 git config remote.o.url .. &&
235 git config remote.o.fetch "refs/heads/*:refs/crazyheads/*" &&
236 git config --add remote.o.fetch "refs/others/*:refs/heads/*" &&
239 git tag -a -m "Descriptive tag" descriptive-tag &&
240 git branch descriptive-branch &&
241 git checkout descriptive-branch &&
242 echo "Nuts" >crazy &&
244 git commit -a -m "descriptive commit" &&
245 git update-ref refs/others/crazy HEAD &&
248 git fetch o 2>actual &&
249 test_i18ngrep "new branch.* -> refs/crazyheads/descriptive-branch$" actual &&
250 test_i18ngrep "new tag.* -> descriptive-tag$" actual &&
251 test_i18ngrep "new ref.* -> crazy$" actual
256 test_expect_success
'fetch must not resolve short tag name' '
264 test_must_fail git fetch .. anno:five
268 test_expect_success
'fetch can now resolve short remote name' '
271 git update-ref refs/remotes/six/HEAD HEAD &&
280 test_expect_success
'create bundle 1' '
282 echo >file updated again by origin &&
283 git commit -a -m "tip" &&
284 git bundle create --version=3 bundle1 master^..master
287 test_expect_success
'header of bundle looks right' '
288 cat >expect <<-EOF &&
290 @object-format=$(test_oid algo)
291 -OID updated by origin
292 OID refs/heads/master
295 sed -e "s/$OID_REGEX/OID/g" -e "5q" "$D"/bundle1 >actual &&
296 test_cmp expect actual
299 test_expect_success
'create bundle 2' '
301 git bundle create bundle2 master~2..master
304 test_expect_success
'unbundle 1' '
306 git checkout -b some-branch &&
307 test_must_fail git fetch "$D/bundle1" master:master
311 test_expect_success
'bundle 1 has only 3 files ' '
313 convert_bundle_to_pack <bundle1 >bundle.pack &&
314 git index-pack bundle.pack &&
315 test_bundle_object_count bundle.pack 3
318 test_expect_success
'unbundle 2' '
320 git fetch ../bundle2 master:master &&
321 test "tip" = "$(git log -1 --pretty=oneline master | cut -d" " -f2)"
324 test_expect_success
'bundle does not prerequisite objects' '
328 git commit -m add.file2 file2 &&
329 git bundle create bundle3 -1 HEAD &&
330 convert_bundle_to_pack <bundle3 >bundle.pack &&
331 git index-pack bundle.pack &&
332 test_bundle_object_count bundle.pack 3
335 test_expect_success
'bundle should be able to create a full history' '
338 git tag -a -m "1.0" v1.0 master &&
339 git bundle create bundle4 v1.0
343 test_expect_success
'fetch with a non-applying branch.<name>.merge' '
344 git config branch.master.remote yeti &&
345 git config branch.master.merge refs/heads/bigfoot &&
346 git config remote.blub.url one &&
347 git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
351 # URL supplied to fetch does not match the url of the configured branch's remote
352 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
353 one_head=$(cd one && git rev-parse HEAD) &&
354 this_head=$(git rev-parse HEAD) &&
355 git update-ref -d FETCH_HEAD &&
357 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
358 test $this_head = "$(git rev-parse --verify HEAD)"
361 # URL supplied to fetch matches the url of the configured branch's remote and
362 # the merge spec matches the branch the remote HEAD points to
363 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [2]' '
364 one_ref=$(cd one && git symbolic-ref HEAD) &&
365 git config branch.master.remote blub &&
366 git config branch.master.merge "$one_ref" &&
367 git update-ref -d FETCH_HEAD &&
369 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
370 test $this_head = "$(git rev-parse --verify HEAD)"
373 # URL supplied to fetch matches the url of the configured branch's remote, but
374 # the merge spec does not match the branch the remote HEAD points to
375 test_expect_success
'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
376 git config branch.master.merge "${one_ref}_not" &&
377 git update-ref -d FETCH_HEAD &&
379 test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
380 test $this_head = "$(git rev-parse --verify HEAD)"
383 # the strange name is: a\!'b
384 test_expect_success
'quoting of a strangely named repo' '
385 test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
386 grep "fatal: '\''a\\\\!'\''b'\''" result
389 test_expect_success
'bundle should record HEAD correctly' '
392 git bundle create bundle5 HEAD master &&
393 git bundle list-heads bundle5 >actual &&
394 for h in HEAD refs/heads/master
396 echo "$(git rev-parse --verify $h) $h"
398 test_cmp expect actual
402 test_expect_success
'mark initial state of origin/master' '
405 git tag base-origin-master refs/remotes/origin/master
409 test_expect_success
'explicit fetch should update tracking' '
412 git branch -f side &&
415 git update-ref refs/remotes/origin/master base-origin-master &&
416 o=$(git rev-parse --verify refs/remotes/origin/master) &&
417 git fetch origin master &&
418 n=$(git rev-parse --verify refs/remotes/origin/master) &&
420 test_must_fail git rev-parse --verify refs/remotes/origin/side
424 test_expect_success
'explicit pull should update tracking' '
427 git branch -f side &&
430 git update-ref refs/remotes/origin/master base-origin-master &&
431 o=$(git rev-parse --verify refs/remotes/origin/master) &&
432 git pull origin master &&
433 n=$(git rev-parse --verify refs/remotes/origin/master) &&
435 test_must_fail git rev-parse --verify refs/remotes/origin/side
439 test_expect_success
'explicit --refmap is allowed only with command-line refspec' '
443 test_must_fail git fetch --refmap="*:refs/remotes/none/*"
447 test_expect_success
'explicit --refmap option overrides remote.*.fetch' '
449 git branch -f side &&
452 git update-ref refs/remotes/origin/master base-origin-master &&
453 o=$(git rev-parse --verify refs/remotes/origin/master) &&
454 git fetch --refmap="refs/heads/*:refs/remotes/other/*" origin master &&
455 n=$(git rev-parse --verify refs/remotes/origin/master) &&
457 test_must_fail git rev-parse --verify refs/remotes/origin/side &&
458 git rev-parse --verify refs/remotes/other/master
462 test_expect_success
'explicitly empty --refmap option disables remote.*.fetch' '
464 git branch -f side &&
467 git update-ref refs/remotes/origin/master base-origin-master &&
468 o=$(git rev-parse --verify refs/remotes/origin/master) &&
469 git fetch --refmap="" origin master &&
470 n=$(git rev-parse --verify refs/remotes/origin/master) &&
472 test_must_fail git rev-parse --verify refs/remotes/origin/side
476 test_expect_success
'configured fetch updates tracking' '
479 git branch -f side &&
482 git update-ref refs/remotes/origin/master base-origin-master &&
483 o=$(git rev-parse --verify refs/remotes/origin/master) &&
485 n=$(git rev-parse --verify refs/remotes/origin/master) &&
487 git rev-parse --verify refs/remotes/origin/side
491 test_expect_success
'non-matching refspecs do not confuse tracking update' '
493 git update-ref refs/odd/location HEAD &&
496 git update-ref refs/remotes/origin/master base-origin-master &&
497 git config --add remote.origin.fetch \
498 refs/odd/location:refs/remotes/origin/odd &&
499 o=$(git rev-parse --verify refs/remotes/origin/master) &&
500 git fetch origin master &&
501 n=$(git rev-parse --verify refs/remotes/origin/master) &&
503 test_must_fail git rev-parse --verify refs/remotes/origin/odd
507 test_expect_success
'pushing nonexistent branch by mistake should not segv' '
510 test_must_fail git push seven no:no
514 test_expect_success
'auto tag following fetches minimum' '
517 git clone .git follow &&
518 git checkout HEAD^0 &&
520 for i in 1 2 3 4 5 6 7
523 git commit -m $i -a &&
524 git tag -a -m $i excess-$i || exit 1
527 git checkout master &&
534 test_expect_success
'refuse to fetch into the current branch' '
536 test_must_fail git fetch . side:master
540 test_expect_success
'fetch into the current branch with --update-head-ok' '
542 git fetch --update-head-ok . side:master
546 test_expect_success
'fetch --dry-run does not touch FETCH_HEAD, but still prints what would be written' '
547 rm -f .git/FETCH_HEAD err &&
548 git fetch --dry-run . 2>err &&
549 ! test -f .git/FETCH_HEAD &&
553 test_expect_success
'--no-write-fetch-head does not touch FETCH_HEAD, and does not print what would be written' '
554 rm -f .git/FETCH_HEAD err &&
555 git fetch --no-write-fetch-head . 2>err &&
556 ! test -f .git/FETCH_HEAD &&
557 ! grep FETCH_HEAD err
560 test_expect_success
'--write-fetch-head gets defeated by --dry-run' '
561 rm -f .git/FETCH_HEAD &&
562 git fetch --dry-run --write-fetch-head . &&
563 ! test -f .git/FETCH_HEAD
566 test_expect_success
"should be able to fetch with duplicate refspecs" '
571 git config branch.master.remote three &&
572 git config remote.three.url ../three/.git &&
573 git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
574 git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
579 test_expect_success
'LHS of refspec follows ref disambiguation rules' '
580 mkdir lhs-ambiguous &&
584 test_commit -C server unwanted &&
585 test_commit -C server wanted &&
589 # Check a name coming after "refs" alphabetically ...
590 git -C server update-ref refs/heads/s wanted &&
591 git -C server update-ref refs/heads/refs/heads/s unwanted &&
592 git -C client fetch ../server +refs/heads/s:refs/heads/checkthis &&
593 git -C server rev-parse wanted >expect &&
594 git -C client rev-parse checkthis >actual &&
595 test_cmp expect actual &&
597 # ... and one before.
598 git -C server update-ref refs/heads/q wanted &&
599 git -C server update-ref refs/heads/refs/heads/q unwanted &&
600 git -C client fetch ../server +refs/heads/q:refs/heads/checkthis &&
601 git -C server rev-parse wanted >expect &&
602 git -C client rev-parse checkthis >actual &&
603 test_cmp expect actual &&
605 # Tags are preferred over branches like refs/{heads,tags}/*
606 git -C server update-ref refs/tags/t wanted &&
607 git -C server update-ref refs/heads/t unwanted &&
608 git -C client fetch ../server +t:refs/heads/checkthis &&
609 git -C server rev-parse wanted >expect &&
610 git -C client rev-parse checkthis >actual
614 test_expect_success
'fetch.writeCommitGraph' '
615 git clone three write &&
622 git -c fetch.writeCommitGraph fetch origin &&
623 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
627 test_expect_success
'fetch.writeCommitGraph with submodules' '
628 git clone dups super &&
631 git submodule add "file://$TRASH_DIRECTORY/three" &&
632 git commit -m "add submodule"
634 git clone "super" super-clone &&
637 rm -rf .git/objects/info &&
638 git -c fetch.writeCommitGraph=true fetch origin &&
639 test_path_is_file .git/objects/info/commit-graphs/commit-graph-chain
643 # configured prune tests
645 set_config_tristate
() {
653 key
=$
(echo $1 |
sed -e 's/^remote\.origin/fetch/')
654 git_fetch_c
="$git_fetch_c -c $key=$2"
659 test_configured_prune
() {
660 test_configured_prune_type
"$@" "name"
661 test_configured_prune_type
"$@" "link"
664 test_configured_prune_type
() {
666 remote_origin_prune
=$2
668 remote_origin_prune_tags
=$4
674 if test -z "$cmdline_setup"
676 test_expect_success
'setup cmdline_setup variable for subsequent test' '
677 remote_url="file://$(git -C one config remote.origin.url)" &&
678 remote_fetch="$(git -C one config remote.origin.fetch)" &&
679 cmdline_setup="\"$remote_url\" \"$remote_fetch\""
683 if test "$mode" = 'link'
687 if test "$cmdline" = ""
689 new_cmdline
=$cmdline_setup
691 new_cmdline
=$
(printf "%s" "$cmdline" | perl
-pe 's[origin(?!/)]["'"$remote_url"'"]g')
694 if test "$fetch_prune_tags" = 'true' ||
695 test "$remote_origin_prune_tags" = 'true'
697 if ! printf '%s' "$cmdline\n" |
grep -q refs
/remotes
/origin
/
699 new_cmdline
="$new_cmdline refs/tags/*:refs/tags/*"
703 cmdline
="$new_cmdline"
706 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" '
707 # make sure a newbranch is there in . and also in one
708 git branch -f newbranch &&
712 test_unconfig fetch.prune &&
713 test_unconfig fetch.pruneTags &&
714 test_unconfig remote.origin.prune &&
715 test_unconfig remote.origin.pruneTags &&
716 git fetch '"$cmdline_setup"' &&
717 git rev-parse --verify refs/remotes/origin/newbranch &&
718 git rev-parse --verify refs/tags/newtag
722 git branch -d newbranch &&
729 set_config_tristate fetch.prune $fetch_prune &&
730 set_config_tristate fetch.pruneTags $fetch_prune_tags &&
731 set_config_tristate remote.origin.prune $remote_origin_prune &&
732 set_config_tristate remote.origin.pruneTags $remote_origin_prune_tags &&
734 if test "$mode" != "link"
738 git$git_fetch_c fetch '"$cmdline"' &&
739 case "$expected_branch" in
741 test_must_fail git rev-parse --verify refs/remotes/origin/newbranch
744 git rev-parse --verify refs/remotes/origin/newbranch
747 case "$expected_tag" in
749 test_must_fail git rev-parse --verify refs/tags/newtag
752 git rev-parse --verify refs/tags/newtag
759 # $1 config: fetch.prune
760 # $2 config: remote.<name>.prune
761 # $3 config: fetch.pruneTags
762 # $4 config: remote.<name>.pruneTags
763 # $5 expect: branch to be pruned?
764 # $6 expect: tag to be pruned?
765 # $7 git-fetch $cmdline:
767 # $1 $2 $3 $4 $5 $6 $7
768 test_configured_prune
unset unset unset unset kept kept
""
769 test_configured_prune
unset unset unset unset kept kept
"--no-prune"
770 test_configured_prune
unset unset unset unset pruned kept
"--prune"
771 test_configured_prune
unset unset unset unset kept pruned \
772 "--prune origin refs/tags/*:refs/tags/*"
773 test_configured_prune
unset unset unset unset pruned pruned \
774 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
776 test_configured_prune false
unset unset unset kept kept
""
777 test_configured_prune false
unset unset unset kept kept
"--no-prune"
778 test_configured_prune false
unset unset unset pruned kept
"--prune"
780 test_configured_prune true
unset unset unset pruned kept
""
781 test_configured_prune true
unset unset unset pruned kept
"--prune"
782 test_configured_prune true
unset unset unset kept kept
"--no-prune"
784 test_configured_prune
unset false
unset unset kept kept
""
785 test_configured_prune
unset false
unset unset kept kept
"--no-prune"
786 test_configured_prune
unset false
unset unset pruned kept
"--prune"
788 test_configured_prune false false
unset unset kept kept
""
789 test_configured_prune false false
unset unset kept kept
"--no-prune"
790 test_configured_prune false false
unset unset pruned kept
"--prune"
791 test_configured_prune false false
unset unset kept pruned \
792 "--prune origin refs/tags/*:refs/tags/*"
793 test_configured_prune false false
unset unset pruned pruned \
794 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
796 test_configured_prune true false
unset unset kept kept
""
797 test_configured_prune true false
unset unset pruned kept
"--prune"
798 test_configured_prune true false
unset unset kept kept
"--no-prune"
800 test_configured_prune
unset true
unset unset pruned kept
""
801 test_configured_prune
unset true
unset unset kept kept
"--no-prune"
802 test_configured_prune
unset true
unset unset pruned kept
"--prune"
804 test_configured_prune false true
unset unset pruned kept
""
805 test_configured_prune false true
unset unset kept kept
"--no-prune"
806 test_configured_prune false true
unset unset pruned kept
"--prune"
808 test_configured_prune true true
unset unset pruned kept
""
809 test_configured_prune true true
unset unset pruned kept
"--prune"
810 test_configured_prune true true
unset unset kept kept
"--no-prune"
811 test_configured_prune true true
unset unset kept pruned \
812 "--prune origin refs/tags/*:refs/tags/*"
813 test_configured_prune true true
unset unset pruned pruned \
814 "--prune origin refs/tags/*:refs/tags/* +refs/heads/*:refs/remotes/origin/*"
816 # --prune-tags on its own does nothing, needs --prune as well, same
817 # for fetch.pruneTags without fetch.prune
818 test_configured_prune
unset unset unset unset kept kept
"--prune-tags"
819 test_configured_prune
unset unset true
unset kept kept
""
820 test_configured_prune
unset unset unset true kept kept
""
822 # These will prune the tags
823 test_configured_prune
unset unset unset unset pruned pruned
"--prune --prune-tags"
824 test_configured_prune true
unset true
unset pruned pruned
""
825 test_configured_prune
unset true
unset true pruned pruned
""
827 # remote.<name>.pruneTags overrides fetch.pruneTags, just like
828 # remote.<name>.prune overrides fetch.prune if set.
829 test_configured_prune true
unset true
unset pruned pruned
""
830 test_configured_prune false true false true pruned pruned
""
831 test_configured_prune true false true false kept kept
""
833 # When --prune-tags is supplied it's ignored if an explicit refspec is
834 # given, same for the configuration options.
835 test_configured_prune
unset unset unset unset pruned kept \
836 "--prune --prune-tags origin +refs/heads/*:refs/remotes/origin/*"
837 test_configured_prune
unset unset true
unset pruned kept \
838 "--prune origin +refs/heads/*:refs/remotes/origin/*"
839 test_configured_prune
unset unset unset true pruned kept \
840 "--prune origin +refs/heads/*:refs/remotes/origin/*"
842 # Pruning that also takes place if a file:// url replaces a named
843 # remote. However, because there's no implicit
844 # +refs/heads/*:refs/remotes/origin/* refspec and supplying it on the
845 # command-line negates --prune-tags, the branches will not be pruned.
846 test_configured_prune_type
unset unset unset unset kept kept
"origin --prune-tags" "name"
847 test_configured_prune_type
unset unset unset unset kept kept
"origin --prune-tags" "link"
848 test_configured_prune_type
unset unset unset unset pruned pruned
"origin --prune --prune-tags" "name"
849 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "link"
850 test_configured_prune_type
unset unset unset unset pruned pruned
"--prune --prune-tags origin" "name"
851 test_configured_prune_type
unset unset unset unset kept pruned
"--prune --prune-tags origin" "link"
852 test_configured_prune_type
unset unset true
unset pruned pruned
"--prune origin" "name"
853 test_configured_prune_type
unset unset true
unset kept pruned
"--prune origin" "link"
854 test_configured_prune_type
unset unset unset true pruned pruned
"--prune origin" "name"
855 test_configured_prune_type
unset unset unset true kept pruned
"--prune origin" "link"
856 test_configured_prune_type true
unset true
unset pruned pruned
"origin" "name"
857 test_configured_prune_type true
unset true
unset kept pruned
"origin" "link"
858 test_configured_prune_type
unset true true
unset pruned pruned
"origin" "name"
859 test_configured_prune_type
unset true true
unset kept pruned
"origin" "link"
860 test_configured_prune_type
unset true
unset true pruned pruned
"origin" "name"
861 test_configured_prune_type
unset true
unset true kept pruned
"origin" "link"
863 # When all remote.origin.fetch settings are deleted a --prune
864 # --prune-tags still implicitly supplies refs/tags/*:refs/tags/* so
865 # tags, but not tracking branches, will be deleted.
866 test_expect_success
'remove remote.origin.fetch "one"' '
869 git config --unset-all remote.origin.fetch
872 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "name"
873 test_configured_prune_type
unset unset unset unset kept pruned
"origin --prune --prune-tags" "link"
875 test_expect_success
'all boundary commits are excluded' '
877 test_commit oneside &&
878 git checkout HEAD^ &&
879 test_commit otherside &&
880 git checkout master &&
882 git merge otherside &&
883 ad=$(git log --no-walk --format=%ad HEAD) &&
884 git bundle create twoside-boundary.bdl master --since="$ad" &&
885 convert_bundle_to_pack <twoside-boundary.bdl >twoside-boundary.pack &&
886 pack=$(git index-pack --fix-thin --stdin <twoside-boundary.pack) &&
887 test_bundle_object_count .git/objects/pack/pack-${pack##pack }.pack 3
890 test_expect_success
'fetch --prune prints the remotes url' '
891 git branch goodbye &&
892 git clone . only-prunes &&
893 git branch -D goodbye &&
896 git fetch --prune origin 2>&1 | head -n1 >../actual
898 echo "From ${D}/." >expect &&
899 test_i18ncmp expect actual
902 test_expect_success
'branchname D/F conflict resolved by --prune' '
903 git branch dir/file &&
904 git clone . prune-df-conflict &&
905 git branch -D dir/file &&
908 cd prune-df-conflict &&
910 git rev-parse origin/dir >../actual
912 git rev-parse dir >expect &&
913 test_cmp expect actual
916 test_expect_success
'fetching a one-level ref works' '
918 git reset --hard HEAD^ &&
919 git update-ref refs/foo extra &&
920 git init one-level &&
923 git fetch .. HEAD refs/foo
927 test_expect_success
'fetching with auto-gc does not lock up' '
928 write_script askyesno <<-\EOF &&
932 git clone "file://$D" auto-gc &&
936 git config fetch.unpackLimit 1 &&
937 git config gc.autoPackLimit 1 &&
938 git config gc.autoDetach false &&
939 GIT_ASK_YESNO="$D/askyesno" git fetch --verbose >fetch.out 2>&1 &&
940 test_i18ngrep "Auto packing the repository" fetch.out &&
941 ! grep "Should I try again" fetch.out
945 test_expect_success PREPARE_FOR_MAIN_BRANCH
,C_LOCALE_OUTPUT
'fetch aligned output' '
946 git clone . full-output &&
947 test_commit looooooooooooong-tag &&
950 git -c fetch.output=full fetch origin >actual 2>&1 &&
951 grep -e "->" actual | cut -c 22- >../actual
953 cat >expect <<-\EOF &&
955 looooooooooooong-tag -> looooooooooooong-tag
957 test_cmp expect actual
960 test_expect_success PREPARE_FOR_MAIN_BRANCH
,C_LOCALE_OUTPUT
'fetch compact output' '
961 git clone . compact &&
962 test_commit extraaa &&
965 git -c fetch.output=compact fetch origin >actual 2>&1 &&
966 grep -e "->" actual | cut -c 22- >../actual
968 cat >expect <<-\EOF &&
972 test_cmp expect actual
975 test_expect_success
'--no-show-forced-updates' '
976 mkdir forced-updates &&
983 git clone forced-updates forced-update-clone &&
984 git clone forced-updates no-forced-update-clone &&
985 git -C forced-updates reset --hard HEAD~1 &&
987 cd forced-update-clone &&
988 git fetch --show-forced-updates origin 2>output &&
989 test_i18ngrep "(forced update)" output
992 cd no-forced-update-clone &&
993 git fetch --no-show-forced-updates origin 2>output &&
994 test_i18ngrep ! "(forced update)" output
998 setup_negotiation_tip
() {
1001 USE_PROTOCOL_V2
="$3"
1003 rm -rf "$SERVER" client trace
&&
1004 git init
"$SERVER" &&
1005 test_commit
-C "$SERVER" alpha_1
&&
1006 test_commit
-C "$SERVER" alpha_2
&&
1007 git
-C "$SERVER" checkout
--orphan beta
&&
1008 test_commit
-C "$SERVER" beta_1
&&
1009 test_commit
-C "$SERVER" beta_2
&&
1011 git clone
"$URL" client
&&
1013 if test "$USE_PROTOCOL_V2" -eq 1
1015 git
-C "$SERVER" config protocol.version
2 &&
1016 git
-C client config protocol.version
2
1019 test_commit
-C "$SERVER" beta_s
&&
1020 git
-C "$SERVER" checkout master
&&
1021 test_commit
-C "$SERVER" alpha_s
&&
1022 git
-C "$SERVER" tag
-d alpha_1 alpha_2 beta_1 beta_2
1025 check_negotiation_tip
() {
1026 # Ensure that {alpha,beta}_1 are sent as "have", but not {alpha_beta}_2
1027 ALPHA_1
=$
(git
-C client rev-parse alpha_1
) &&
1028 grep "fetch> have $ALPHA_1" trace
&&
1029 BETA_1
=$
(git
-C client rev-parse beta_1
) &&
1030 grep "fetch> have $BETA_1" trace
&&
1031 ALPHA_2
=$
(git
-C client rev-parse alpha_2
) &&
1032 ! grep "fetch> have $ALPHA_2" trace
&&
1033 BETA_2
=$
(git
-C client rev-parse beta_2
) &&
1034 ! grep "fetch> have $BETA_2" trace
1037 test_expect_success
'--negotiation-tip limits "have" lines sent' '
1038 setup_negotiation_tip server server 0 &&
1039 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1040 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1041 origin alpha_s beta_s &&
1042 check_negotiation_tip
1045 test_expect_success
'--negotiation-tip understands globs' '
1046 setup_negotiation_tip server server 0 &&
1047 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1048 --negotiation-tip=*_1 \
1049 origin alpha_s beta_s &&
1050 check_negotiation_tip
1053 test_expect_success
'--negotiation-tip understands abbreviated SHA-1' '
1054 setup_negotiation_tip server server 0 &&
1055 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1056 --negotiation-tip=$(git -C client rev-parse --short alpha_1) \
1057 --negotiation-tip=$(git -C client rev-parse --short beta_1) \
1058 origin alpha_s beta_s &&
1059 check_negotiation_tip
1062 .
"$TEST_DIRECTORY"/lib-httpd.sh
1065 test_expect_success
'--negotiation-tip limits "have" lines sent with HTTP protocol v2' '
1066 setup_negotiation_tip "$HTTPD_DOCUMENT_ROOT_PATH/server" \
1067 "$HTTPD_URL/smart/server" 1 &&
1068 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1069 --negotiation-tip=alpha_1 --negotiation-tip=beta_1 \
1070 origin alpha_s beta_s &&
1071 check_negotiation_tip
1074 # DO NOT add non-httpd-specific tests here, because the last part of this
1075 # test script is only executed when httpd is available and enabled.