fetch tests: fetch <url> <spec> as well as fetch [<remote>]

When a remote URL is supplied on the command-line the internals of the fetch are different, in particular the code in get_ref_map(). An earlier version of the subsequent fetch.pruneTags patch hid a segfault because the difference wasn't tested for. Now all the tests are run as both of the variants of: git fetch git -c [...] fetch $(git config remote.origin.url) $(git config remote.origin.fetch) I'm using -c because while the [fetch] config just set by set_config_tristate will be picked up, the remote.origin.* config won't override it as intended. Work around that and turn this into a purely command-line test by always setting the variables on the command-line, and translate any setting of remote.origin.X into fetch.X. The reason for choosing the names "name" and "link" as opposed to e.g. "named" and "url" is because they're the same length, which makes the test output easier to read as it will be aligned. Due to shellscript quoting madness it's not worthwhile to do all of this within a test_expect_success, but do the parts that can easily be done there, including the one-time setting of variables that don't change between runs to be used by subsequent runs in the 'prune_type setup' test. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 9, 2018 at 20:32 UTC e1790f9245f120940be9333b09015e04a8e73127
1 file changed +40 -4
t/t5510-fetch.sh
+40 -4
@@ -548,18 +548,49 @@ set_config_tristate () {
548 ;;
549 *)
550 git config "$1" "$2"
551 + key=$(echo $1 | sed -e 's/^remote\.origin/fetch/')
552 + git_fetch_c="$git_fetch_c -c $key=$2"
553 ;;
554 esac
555 }
556
557 test_configured_prune () {
558 + test_configured_prune_type "$@" "name"
559 + test_configured_prune_type "$@" "link"
560 +}
561 +
562 +test_configured_prune_type () {
563 fetch_prune=$1
564 remote_origin_prune=$2
565 expected_branch=$3
566 expected_tag=$4
567 cmdline=$5
561 -
562 - test_expect_success "prune fetch.prune=$1 remote.origin.prune=$2${5:+ $5}; branch:$3 tag:$4" '
568 + mode=$6
569 +
570 + if test -z "$cmdline_setup"
571 + then
572 + test_expect_success 'setup cmdline_setup variable for subsequent test' '
573 + remote_url="file://$(git -C one config remote.origin.url)" &&
574 + remote_fetch="$(git -C one config remote.origin.fetch)" &&
575 + cmdline_setup="\"$remote_url\" \"$remote_fetch\""
576 + '
577 + fi
578 +
579 + if test "$mode" = 'link'
580 + then
581 + new_cmdline=""
582 +
583 + if test "$cmdline" = ""
584 + then
585 + new_cmdline=$cmdline_setup
586 + else
587 + new_cmdline=$(printf "%s" "$cmdline" | perl -pe 's[origin(?!/)]["'"$remote_url"'"]g')
588 + fi
589 +
590 + cmdline="$new_cmdline"
591 + fi
592 +
593 + test_expect_success "$mode prune fetch.prune=$1 remote.origin.prune=$2${5:+ $5}; branch:$3 tag:$4" '
594 # make sure a newbranch is there in . and also in one
595 git branch -f newbranch &&
596 git tag -f newtag &&
@@ -567,7 +598,7 @@ test_configured_prune () {
598 cd one &&
599 test_unconfig fetch.prune &&
600 test_unconfig remote.origin.prune &&
570 - git fetch &&
601 + git fetch '"$cmdline_setup"' &&
602 git rev-parse --verify refs/remotes/origin/newbranch &&
603 git rev-parse --verify refs/tags/newtag
604 ) &&
@@ -579,10 +610,15 @@ test_configured_prune () {
610 # then test
611 (
612 cd one &&
613 + git_fetch_c="" &&
614 set_config_tristate fetch.prune $fetch_prune &&
615 set_config_tristate remote.origin.prune $remote_origin_prune &&
616
585 - git fetch '"$cmdline"' &&
617 + if test "$mode" != "link"
618 + then
619 + git_fetch_c=""
620 + fi &&
621 + git$git_fetch_c fetch '"$cmdline"' &&
622 case "$expected_branch" in
623 pruned)
624 test_must_fail git rev-parse --verify refs/remotes/origin/newbranch