t / t5505-remote.shon commit t9700: do not close STDERR (a749c0b)
   1#!/bin/sh
   2
   3test_description='git remote porcelain-ish'
   4
   5. ./test-lib.sh
   6
   7setup_repository () {
   8        mkdir "$1" && (
   9        cd "$1" &&
  10        git init &&
  11        >file &&
  12        git add file &&
  13        test_tick &&
  14        git commit -m "Initial" &&
  15        git checkout -b side &&
  16        >elif &&
  17        git add elif &&
  18        test_tick &&
  19        git commit -m "Second" &&
  20        git checkout master
  21        )
  22}
  23
  24tokens_match () {
  25        echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect &&
  26        echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual &&
  27        test_cmp expect actual
  28}
  29
  30check_remote_track () {
  31        actual=$(git remote show "$1" | sed -ne 's|^    \(.*\) tracked$|\1|p')
  32        shift &&
  33        tokens_match "$*" "$actual"
  34}
  35
  36check_tracking_branch () {
  37        f="" &&
  38        r=$(git for-each-ref "--format=%(refname)" |
  39                sed -ne "s|^refs/remotes/$1/||p") &&
  40        shift &&
  41        tokens_match "$*" "$r"
  42}
  43
  44test_expect_success setup '
  45
  46        setup_repository one &&
  47        setup_repository two &&
  48        (
  49                cd two && git branch another
  50        ) &&
  51        git clone one test
  52
  53'
  54
  55test_expect_success C_LOCALE_OUTPUT 'remote information for the origin' '
  56(
  57        cd test &&
  58        tokens_match origin "$(git remote)" &&
  59        check_remote_track origin master side &&
  60        check_tracking_branch origin HEAD master side
  61)
  62'
  63
  64test_expect_success 'add another remote' '
  65(
  66        cd test &&
  67        git remote add -f second ../two &&
  68        tokens_match "origin second" "$(git remote)" &&
  69        check_tracking_branch second master side another &&
  70        git for-each-ref "--format=%(refname)" refs/remotes |
  71        sed -e "/^refs\/remotes\/origin\//d" \
  72            -e "/^refs\/remotes\/second\//d" >actual &&
  73        >expect &&
  74        test_cmp expect actual
  75)
  76'
  77
  78test_expect_success C_LOCALE_OUTPUT 'check remote tracking' '
  79(
  80        cd test &&
  81        check_remote_track origin master side &&
  82        check_remote_track second master side another
  83)
  84'
  85
  86test_expect_success 'remote forces tracking branches' '
  87(
  88        cd test &&
  89        case `git config remote.second.fetch` in
  90        +*) true ;;
  91         *) false ;;
  92        esac
  93)
  94'
  95
  96test_expect_success 'remove remote' '
  97(
  98        cd test &&
  99        git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
 100        git remote rm second
 101)
 102'
 103
 104test_expect_success C_LOCALE_OUTPUT 'remove remote' '
 105(
 106        cd test &&
 107        tokens_match origin "$(git remote)" &&
 108        check_remote_track origin master side &&
 109        git for-each-ref "--format=%(refname)" refs/remotes |
 110        sed -e "/^refs\/remotes\/origin\//d" >actual &&
 111        >expect &&
 112        test_cmp expect actual
 113)
 114'
 115
 116test_expect_success 'remove remote protects local branches' '
 117(
 118        cd test &&
 119        { cat >expect1 <<EOF
 120Note: A branch outside the refs/remotes/ hierarchy was not removed;
 121to delete it, use:
 122  git branch -d master
 123EOF
 124        } &&
 125        { cat >expect2 <<EOF
 126Note: Some branches outside the refs/remotes/ hierarchy were not removed;
 127to delete them, use:
 128  git branch -d foobranch
 129  git branch -d master
 130EOF
 131        } &&
 132        git tag footag &&
 133        git config --add remote.oops.fetch "+refs/*:refs/*" &&
 134        git remote remove oops 2>actual1 &&
 135        git branch foobranch &&
 136        git config --add remote.oops.fetch "+refs/*:refs/*" &&
 137        git remote rm oops 2>actual2 &&
 138        git branch -d foobranch &&
 139        git tag -d footag &&
 140        test_i18ncmp expect1 actual1 &&
 141        test_i18ncmp expect2 actual2
 142)
 143'
 144
 145cat > test/expect << EOF
 146* remote origin
 147  Fetch URL: $(pwd)/one
 148  Push  URL: $(pwd)/one
 149  HEAD branch: master
 150  Remote branches:
 151    master new (next fetch will store in remotes/origin)
 152    side   tracked
 153  Local branches configured for 'git pull':
 154    ahead    merges with remote master
 155    master   merges with remote master
 156    octopus  merges with remote topic-a
 157                and with remote topic-b
 158                and with remote topic-c
 159    rebase  rebases onto remote master
 160  Local refs configured for 'git push':
 161    master pushes to master   (local out of date)
 162    master pushes to upstream (create)
 163* remote two
 164  Fetch URL: ../two
 165  Push  URL: ../three
 166  HEAD branch (remote HEAD is ambiguous, may be one of the following):
 167    another
 168    master
 169  Local refs configured for 'git push':
 170    ahead  forces to master  (fast-forwardable)
 171    master pushes to another (up to date)
 172EOF
 173
 174test_expect_success 'show' '
 175        (cd test &&
 176         git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream &&
 177         git fetch &&
 178         git checkout -b ahead origin/master &&
 179         echo 1 >> file &&
 180         test_tick &&
 181         git commit -m update file &&
 182         git checkout master &&
 183         git branch --track octopus origin/master &&
 184         git branch --track rebase origin/master &&
 185         git branch -d -r origin/master &&
 186         git config --add remote.two.url ../two &&
 187         git config --add remote.two.pushurl ../three &&
 188         git config branch.rebase.rebase true &&
 189         git config branch.octopus.merge "topic-a topic-b topic-c" &&
 190         (cd ../one &&
 191          echo 1 > file &&
 192          test_tick &&
 193          git commit -m update file) &&
 194         git config --add remote.origin.push : &&
 195         git config --add remote.origin.push refs/heads/master:refs/heads/upstream &&
 196         git config --add remote.origin.push +refs/tags/lastbackup &&
 197         git config --add remote.two.push +refs/heads/ahead:refs/heads/master &&
 198         git config --add remote.two.push refs/heads/master:refs/heads/another &&
 199         git remote show origin two > output &&
 200         git branch -d rebase octopus &&
 201         test_i18ncmp expect output)
 202'
 203
 204cat > test/expect << EOF
 205* remote origin
 206  Fetch URL: $(pwd)/one
 207  Push  URL: $(pwd)/one
 208  HEAD branch: (not queried)
 209  Remote branches: (status not queried)
 210    master
 211    side
 212  Local branches configured for 'git pull':
 213    ahead  merges with remote master
 214    master merges with remote master
 215  Local refs configured for 'git push' (status not queried):
 216    (matching)           pushes to (matching)
 217    refs/heads/master    pushes to refs/heads/upstream
 218    refs/tags/lastbackup forces to refs/tags/lastbackup
 219EOF
 220
 221test_expect_success 'show -n' '
 222        (mv one one.unreachable &&
 223         cd test &&
 224         git remote show -n origin > output &&
 225         mv ../one.unreachable ../one &&
 226         test_i18ncmp expect output)
 227'
 228
 229test_expect_success 'prune' '
 230        (cd one &&
 231         git branch -m side side2) &&
 232        (cd test &&
 233         git fetch origin &&
 234         git remote prune origin &&
 235         git rev-parse refs/remotes/origin/side2 &&
 236         test_must_fail git rev-parse refs/remotes/origin/side)
 237'
 238
 239test_expect_success 'set-head --delete' '
 240        (cd test &&
 241         git symbolic-ref refs/remotes/origin/HEAD &&
 242         git remote set-head --delete origin &&
 243         test_must_fail git symbolic-ref refs/remotes/origin/HEAD)
 244'
 245
 246test_expect_success 'set-head --auto' '
 247        (cd test &&
 248         git remote set-head --auto origin &&
 249         echo refs/remotes/origin/master >expect &&
 250         git symbolic-ref refs/remotes/origin/HEAD >output &&
 251         test_cmp expect output
 252        )
 253'
 254
 255cat >test/expect <<EOF
 256error: Multiple remote HEAD branches. Please choose one explicitly with:
 257  git remote set-head two another
 258  git remote set-head two master
 259EOF
 260
 261test_expect_success 'set-head --auto fails w/multiple HEADs' '
 262        (cd test &&
 263         test_must_fail git remote set-head --auto two >output 2>&1 &&
 264        test_i18ncmp expect output)
 265'
 266
 267cat >test/expect <<EOF
 268refs/remotes/origin/side2
 269EOF
 270
 271test_expect_success 'set-head explicit' '
 272        (cd test &&
 273         git remote set-head origin side2 &&
 274         git symbolic-ref refs/remotes/origin/HEAD >output &&
 275         git remote set-head origin master &&
 276         test_cmp expect output)
 277'
 278
 279cat > test/expect << EOF
 280Pruning origin
 281URL: $(pwd)/one
 282 * [would prune] origin/side2
 283EOF
 284
 285test_expect_success 'prune --dry-run' '
 286        (cd one &&
 287         git branch -m side2 side) &&
 288        (cd test &&
 289         git remote prune --dry-run origin > output &&
 290         git rev-parse refs/remotes/origin/side2 &&
 291         test_must_fail git rev-parse refs/remotes/origin/side &&
 292        (cd ../one &&
 293         git branch -m side side2) &&
 294         test_i18ncmp expect output)
 295'
 296
 297test_expect_success 'add --mirror && prune' '
 298        (mkdir mirror &&
 299         cd mirror &&
 300         git init --bare &&
 301         git remote add --mirror -f origin ../one) &&
 302        (cd one &&
 303         git branch -m side2 side) &&
 304        (cd mirror &&
 305         git rev-parse --verify refs/heads/side2 &&
 306         test_must_fail git rev-parse --verify refs/heads/side &&
 307         git fetch origin &&
 308         git remote prune origin &&
 309         test_must_fail git rev-parse --verify refs/heads/side2 &&
 310         git rev-parse --verify refs/heads/side)
 311'
 312
 313test_expect_success 'add --mirror=fetch' '
 314        mkdir mirror-fetch &&
 315        git init mirror-fetch/parent &&
 316        (cd mirror-fetch/parent &&
 317         test_commit one) &&
 318        git init --bare mirror-fetch/child &&
 319        (cd mirror-fetch/child &&
 320         git remote add --mirror=fetch -f parent ../parent)
 321'
 322
 323test_expect_success 'fetch mirrors act as mirrors during fetch' '
 324        (cd mirror-fetch/parent &&
 325         git branch new &&
 326         git branch -m master renamed
 327        ) &&
 328        (cd mirror-fetch/child &&
 329         git fetch parent &&
 330         git rev-parse --verify refs/heads/new &&
 331         git rev-parse --verify refs/heads/renamed
 332        )
 333'
 334
 335test_expect_success 'fetch mirrors can prune' '
 336        (cd mirror-fetch/child &&
 337         git remote prune parent &&
 338         test_must_fail git rev-parse --verify refs/heads/master
 339        )
 340'
 341
 342test_expect_success 'fetch mirrors do not act as mirrors during push' '
 343        (cd mirror-fetch/parent &&
 344         git checkout HEAD^0
 345        ) &&
 346        (cd mirror-fetch/child &&
 347         git branch -m renamed renamed2 &&
 348         git push parent
 349        ) &&
 350        (cd mirror-fetch/parent &&
 351         git rev-parse --verify renamed &&
 352         test_must_fail git rev-parse --verify refs/heads/renamed2
 353        )
 354'
 355
 356test_expect_success 'add fetch mirror with specific branches' '
 357        git init --bare mirror-fetch/track &&
 358        (cd mirror-fetch/track &&
 359         git remote add --mirror=fetch -t heads/new parent ../parent
 360        )
 361'
 362
 363test_expect_success 'fetch mirror respects specific branches' '
 364        (cd mirror-fetch/track &&
 365         git fetch parent &&
 366         git rev-parse --verify refs/heads/new &&
 367         test_must_fail git rev-parse --verify refs/heads/renamed
 368        )
 369'
 370
 371test_expect_success 'add --mirror=push' '
 372        mkdir mirror-push &&
 373        git init --bare mirror-push/public &&
 374        git init mirror-push/private &&
 375        (cd mirror-push/private &&
 376         test_commit one &&
 377         git remote add --mirror=push public ../public
 378        )
 379'
 380
 381test_expect_success 'push mirrors act as mirrors during push' '
 382        (cd mirror-push/private &&
 383         git branch new &&
 384         git branch -m master renamed &&
 385         git push public
 386        ) &&
 387        (cd mirror-push/private &&
 388         git rev-parse --verify refs/heads/new &&
 389         git rev-parse --verify refs/heads/renamed &&
 390         test_must_fail git rev-parse --verify refs/heads/master
 391        )
 392'
 393
 394test_expect_success 'push mirrors do not act as mirrors during fetch' '
 395        (cd mirror-push/public &&
 396         git branch -m renamed renamed2 &&
 397         git symbolic-ref HEAD refs/heads/renamed2
 398        ) &&
 399        (cd mirror-push/private &&
 400         git fetch public &&
 401         git rev-parse --verify refs/heads/renamed &&
 402         test_must_fail git rev-parse --verify refs/heads/renamed2
 403        )
 404'
 405
 406test_expect_success 'push mirrors do not allow you to specify refs' '
 407        git init mirror-push/track &&
 408        (cd mirror-push/track &&
 409         test_must_fail git remote add --mirror=push -t new public ../public
 410        )
 411'
 412
 413test_expect_success 'add alt && prune' '
 414        (mkdir alttst &&
 415         cd alttst &&
 416         git init &&
 417         git remote add -f origin ../one &&
 418         git config remote.alt.url ../one &&
 419         git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
 420        (cd one &&
 421         git branch -m side side2) &&
 422        (cd alttst &&
 423         git rev-parse --verify refs/remotes/origin/side &&
 424         test_must_fail git rev-parse --verify refs/remotes/origin/side2 &&
 425         git fetch alt &&
 426         git remote prune alt &&
 427         test_must_fail git rev-parse --verify refs/remotes/origin/side &&
 428         git rev-parse --verify refs/remotes/origin/side2)
 429'
 430
 431cat >test/expect <<\EOF
 432some-tag
 433EOF
 434
 435test_expect_success 'add with reachable tags (default)' '
 436        (cd one &&
 437         >foobar &&
 438         git add foobar &&
 439         git commit -m "Foobar" &&
 440         git tag -a -m "Foobar tag" foobar-tag &&
 441         git reset --hard HEAD~1 &&
 442         git tag -a -m "Some tag" some-tag) &&
 443        (mkdir add-tags &&
 444         cd add-tags &&
 445         git init &&
 446         git remote add -f origin ../one &&
 447         git tag -l some-tag >../test/output &&
 448         git tag -l foobar-tag >>../test/output &&
 449         test_must_fail git config remote.origin.tagopt) &&
 450        test_cmp test/expect test/output
 451'
 452
 453cat >test/expect <<\EOF
 454some-tag
 455foobar-tag
 456--tags
 457EOF
 458
 459test_expect_success 'add --tags' '
 460        (rm -rf add-tags &&
 461         mkdir add-tags &&
 462         cd add-tags &&
 463         git init &&
 464         git remote add -f --tags origin ../one &&
 465         git tag -l some-tag >../test/output &&
 466         git tag -l foobar-tag >>../test/output &&
 467         git config remote.origin.tagopt >>../test/output) &&
 468        test_cmp test/expect test/output
 469'
 470
 471cat >test/expect <<\EOF
 472--no-tags
 473EOF
 474
 475test_expect_success 'add --no-tags' '
 476        (rm -rf add-tags &&
 477         mkdir add-no-tags &&
 478         cd add-no-tags &&
 479         git init &&
 480         git remote add -f --no-tags origin ../one &&
 481         git tag -l some-tag >../test/output &&
 482         git tag -l foobar-tag >../test/output &&
 483         git config remote.origin.tagopt >>../test/output) &&
 484        (cd one &&
 485         git tag -d some-tag foobar-tag) &&
 486        test_cmp test/expect test/output
 487'
 488
 489test_expect_success 'reject --no-no-tags' '
 490        (cd add-no-tags &&
 491         test_must_fail git remote add -f --no-no-tags neworigin ../one)
 492'
 493
 494cat > one/expect << EOF
 495  apis/master
 496  apis/side
 497  drosophila/another
 498  drosophila/master
 499  drosophila/side
 500EOF
 501
 502test_expect_success 'update' '
 503
 504        (cd one &&
 505         git remote add drosophila ../two &&
 506         git remote add apis ../mirror &&
 507         git remote update &&
 508         git branch -r > output &&
 509         test_cmp expect output)
 510
 511'
 512
 513cat > one/expect << EOF
 514  drosophila/another
 515  drosophila/master
 516  drosophila/side
 517  manduca/master
 518  manduca/side
 519  megaloprepus/master
 520  megaloprepus/side
 521EOF
 522
 523test_expect_success 'update with arguments' '
 524
 525        (cd one &&
 526         for b in $(git branch -r)
 527         do
 528                git branch -r -d $b || break
 529         done &&
 530         git remote add manduca ../mirror &&
 531         git remote add megaloprepus ../mirror &&
 532         git config remotes.phobaeticus "drosophila megaloprepus" &&
 533         git config remotes.titanus manduca &&
 534         git remote update phobaeticus titanus &&
 535         git branch -r > output &&
 536         test_cmp expect output)
 537
 538'
 539
 540test_expect_success 'update --prune' '
 541
 542        (cd one &&
 543         git branch -m side2 side3) &&
 544        (cd test &&
 545         git remote update --prune &&
 546         (cd ../one && git branch -m side3 side2) &&
 547         git rev-parse refs/remotes/origin/side3 &&
 548         test_must_fail git rev-parse refs/remotes/origin/side2)
 549'
 550
 551cat > one/expect << EOF
 552  apis/master
 553  apis/side
 554  manduca/master
 555  manduca/side
 556  megaloprepus/master
 557  megaloprepus/side
 558EOF
 559
 560test_expect_success 'update default' '
 561
 562        (cd one &&
 563         for b in $(git branch -r)
 564         do
 565                git branch -r -d $b || break
 566         done &&
 567         git config remote.drosophila.skipDefaultUpdate true &&
 568         git remote update default &&
 569         git branch -r > output &&
 570         test_cmp expect output)
 571
 572'
 573
 574cat > one/expect << EOF
 575  drosophila/another
 576  drosophila/master
 577  drosophila/side
 578EOF
 579
 580test_expect_success 'update default (overridden, with funny whitespace)' '
 581
 582        (cd one &&
 583         for b in $(git branch -r)
 584         do
 585                git branch -r -d $b || break
 586         done &&
 587         git config remotes.default "$(printf "\t drosophila  \n")" &&
 588         git remote update default &&
 589         git branch -r > output &&
 590         test_cmp expect output)
 591
 592'
 593
 594test_expect_success 'update (with remotes.default defined)' '
 595
 596        (cd one &&
 597         for b in $(git branch -r)
 598         do
 599                git branch -r -d $b || break
 600         done &&
 601         git config remotes.default "drosophila" &&
 602         git remote update &&
 603         git branch -r > output &&
 604         test_cmp expect output)
 605
 606'
 607
 608test_expect_success '"remote show" does not show symbolic refs' '
 609
 610        git clone one three &&
 611        (cd three &&
 612         git remote show origin > output &&
 613         ! grep "^ *HEAD$" < output &&
 614         ! grep -i stale < output)
 615
 616'
 617
 618test_expect_success 'reject adding remote with an invalid name' '
 619
 620        test_must_fail git remote add some:url desired-name
 621
 622'
 623
 624# The first three test if the tracking branches are properly renamed,
 625# the last two ones check if the config is updated.
 626
 627test_expect_success 'rename a remote' '
 628
 629        git clone one four &&
 630        (cd four &&
 631         git remote rename origin upstream &&
 632         rmdir .git/refs/remotes/origin &&
 633         test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" &&
 634         test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" &&
 635         test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" &&
 636         test "$(git config branch.master.remote)" = "upstream")
 637
 638'
 639
 640test_expect_success 'rename does not update a non-default fetch refspec' '
 641
 642        git clone one four.one &&
 643        (cd four.one &&
 644         git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* &&
 645         git remote rename origin upstream &&
 646         test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" &&
 647         git rev-parse -q origin/master)
 648
 649'
 650
 651test_expect_success 'rename a remote with name part of fetch spec' '
 652
 653        git clone one four.two &&
 654        (cd four.two &&
 655         git remote rename origin remote &&
 656         git remote rename remote upstream &&
 657         test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*")
 658
 659'
 660
 661test_expect_success 'rename a remote with name prefix of other remote' '
 662
 663        git clone one four.three &&
 664        (cd four.three &&
 665         git remote add o git://example.com/repo.git &&
 666         git remote rename o upstream &&
 667         test "$(git rev-parse origin/master)" = "$(git rev-parse master)")
 668
 669'
 670
 671cat > remotes_origin << EOF
 672URL: $(pwd)/one
 673Push: refs/heads/master:refs/heads/upstream
 674Pull: refs/heads/master:refs/heads/origin
 675EOF
 676
 677test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' '
 678        git clone one five &&
 679        origin_url=$(pwd)/one &&
 680        (cd five &&
 681         git remote remove origin &&
 682         mkdir -p .git/remotes &&
 683         cat ../remotes_origin > .git/remotes/origin &&
 684         git remote rename origin origin &&
 685         ! test -f .git/remotes/origin &&
 686         test "$(git config remote.origin.url)" = "$origin_url" &&
 687         test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" &&
 688         test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
 689'
 690
 691test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' '
 692        git clone one six &&
 693        origin_url=$(pwd)/one &&
 694        (cd six &&
 695         git remote rm origin &&
 696         echo "$origin_url" > .git/branches/origin &&
 697         git remote rename origin origin &&
 698         ! test -f .git/branches/origin &&
 699         test "$(git config remote.origin.url)" = "$origin_url" &&
 700         test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin")
 701'
 702
 703test_expect_success 'remote prune to cause a dangling symref' '
 704        git clone one seven &&
 705        (
 706                cd one &&
 707                git checkout side2 &&
 708                git branch -D master
 709        ) &&
 710        (
 711                cd seven &&
 712                git remote prune origin
 713        ) >err 2>&1 &&
 714        test_i18ngrep "has become dangling" err &&
 715
 716        : And the dangling symref will not cause other annoying errors &&
 717        (
 718                cd seven &&
 719                git branch -a
 720        ) 2>err &&
 721        ! grep "points nowhere" err &&
 722        (
 723                cd seven &&
 724                test_must_fail git branch nomore origin
 725        ) 2>err &&
 726        grep "dangling symref" err
 727'
 728
 729test_expect_success 'show empty remote' '
 730
 731        test_create_repo empty &&
 732        git clone empty empty-clone &&
 733        (
 734                cd empty-clone &&
 735                git remote show origin
 736        )
 737'
 738
 739test_expect_success 'remote set-branches requires a remote' '
 740        test_must_fail git remote set-branches &&
 741        test_must_fail git remote set-branches --add
 742'
 743
 744test_expect_success 'remote set-branches' '
 745        echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial &&
 746        sort <<-\EOF >expect.add &&
 747        +refs/heads/*:refs/remotes/scratch/*
 748        +refs/heads/other:refs/remotes/scratch/other
 749        EOF
 750        sort <<-\EOF >expect.replace &&
 751        +refs/heads/maint:refs/remotes/scratch/maint
 752        +refs/heads/master:refs/remotes/scratch/master
 753        +refs/heads/next:refs/remotes/scratch/next
 754        EOF
 755        sort <<-\EOF >expect.add-two &&
 756        +refs/heads/maint:refs/remotes/scratch/maint
 757        +refs/heads/master:refs/remotes/scratch/master
 758        +refs/heads/next:refs/remotes/scratch/next
 759        +refs/heads/pu:refs/remotes/scratch/pu
 760        +refs/heads/t/topic:refs/remotes/scratch/t/topic
 761        EOF
 762        sort <<-\EOF >expect.setup-ffonly &&
 763        refs/heads/master:refs/remotes/scratch/master
 764        +refs/heads/next:refs/remotes/scratch/next
 765        EOF
 766        sort <<-\EOF >expect.respect-ffonly &&
 767        refs/heads/master:refs/remotes/scratch/master
 768        +refs/heads/next:refs/remotes/scratch/next
 769        +refs/heads/pu:refs/remotes/scratch/pu
 770        EOF
 771
 772        git clone .git/ setbranches &&
 773        (
 774                cd setbranches &&
 775                git remote rename origin scratch &&
 776                git config --get-all remote.scratch.fetch >config-result &&
 777                sort <config-result >../actual.initial &&
 778
 779                git remote set-branches scratch --add other &&
 780                git config --get-all remote.scratch.fetch >config-result &&
 781                sort <config-result >../actual.add &&
 782
 783                git remote set-branches scratch maint master next &&
 784                git config --get-all remote.scratch.fetch >config-result &&
 785                sort <config-result >../actual.replace &&
 786
 787                git remote set-branches --add scratch pu t/topic &&
 788                git config --get-all remote.scratch.fetch >config-result &&
 789                sort <config-result >../actual.add-two &&
 790
 791                git config --unset-all remote.scratch.fetch &&
 792                git config remote.scratch.fetch \
 793                        refs/heads/master:refs/remotes/scratch/master &&
 794                git config --add remote.scratch.fetch \
 795                        +refs/heads/next:refs/remotes/scratch/next &&
 796                git config --get-all remote.scratch.fetch >config-result &&
 797                sort <config-result >../actual.setup-ffonly &&
 798
 799                git remote set-branches --add scratch pu &&
 800                git config --get-all remote.scratch.fetch >config-result &&
 801                sort <config-result >../actual.respect-ffonly
 802        ) &&
 803        test_cmp expect.initial actual.initial &&
 804        test_cmp expect.add actual.add &&
 805        test_cmp expect.replace actual.replace &&
 806        test_cmp expect.add-two actual.add-two &&
 807        test_cmp expect.setup-ffonly actual.setup-ffonly &&
 808        test_cmp expect.respect-ffonly actual.respect-ffonly
 809'
 810
 811test_expect_success 'remote set-branches with --mirror' '
 812        echo "+refs/*:refs/*" >expect.initial &&
 813        echo "+refs/heads/master:refs/heads/master" >expect.replace &&
 814        git clone --mirror .git/ setbranches-mirror &&
 815        (
 816                cd setbranches-mirror &&
 817                git remote rename origin scratch &&
 818                git config --get-all remote.scratch.fetch >../actual.initial &&
 819
 820                git remote set-branches scratch heads/master &&
 821                git config --get-all remote.scratch.fetch >../actual.replace
 822        ) &&
 823        test_cmp expect.initial actual.initial &&
 824        test_cmp expect.replace actual.replace
 825'
 826
 827test_expect_success 'new remote' '
 828        git remote add someremote foo &&
 829        echo foo >expect &&
 830        git config --get-all remote.someremote.url >actual &&
 831        cmp expect actual
 832'
 833
 834test_expect_success 'remote set-url bar' '
 835        git remote set-url someremote bar &&
 836        echo bar >expect &&
 837        git config --get-all remote.someremote.url >actual &&
 838        cmp expect actual
 839'
 840
 841test_expect_success 'remote set-url baz bar' '
 842        git remote set-url someremote baz bar &&
 843        echo baz >expect &&
 844        git config --get-all remote.someremote.url >actual &&
 845        cmp expect actual
 846'
 847
 848test_expect_success 'remote set-url zot bar' '
 849        test_must_fail git remote set-url someremote zot bar &&
 850        echo baz >expect &&
 851        git config --get-all remote.someremote.url >actual &&
 852        cmp expect actual
 853'
 854
 855test_expect_success 'remote set-url --push zot baz' '
 856        test_must_fail git remote set-url --push someremote zot baz &&
 857        echo "YYY" >expect &&
 858        echo baz >>expect &&
 859        test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 860        echo "YYY" >>actual &&
 861        git config --get-all remote.someremote.url >>actual &&
 862        cmp expect actual
 863'
 864
 865test_expect_success 'remote set-url --push zot' '
 866        git remote set-url --push someremote zot &&
 867        echo zot >expect &&
 868        echo "YYY" >>expect &&
 869        echo baz >>expect &&
 870        git config --get-all remote.someremote.pushurl >actual &&
 871        echo "YYY" >>actual &&
 872        git config --get-all remote.someremote.url >>actual &&
 873        cmp expect actual
 874'
 875
 876test_expect_success 'remote set-url --push qux zot' '
 877        git remote set-url --push someremote qux zot &&
 878        echo qux >expect &&
 879        echo "YYY" >>expect &&
 880        echo baz >>expect &&
 881        git config --get-all remote.someremote.pushurl >actual &&
 882        echo "YYY" >>actual &&
 883        git config --get-all remote.someremote.url >>actual &&
 884        cmp expect actual
 885'
 886
 887test_expect_success 'remote set-url --push foo qu+x' '
 888        git remote set-url --push someremote foo qu+x &&
 889        echo foo >expect &&
 890        echo "YYY" >>expect &&
 891        echo baz >>expect &&
 892        git config --get-all remote.someremote.pushurl >actual &&
 893        echo "YYY" >>actual &&
 894        git config --get-all remote.someremote.url >>actual &&
 895        cmp expect actual
 896'
 897
 898test_expect_success 'remote set-url --push --add aaa' '
 899        git remote set-url --push --add someremote aaa &&
 900        echo foo >expect &&
 901        echo aaa >>expect &&
 902        echo "YYY" >>expect &&
 903        echo baz >>expect &&
 904        git config --get-all remote.someremote.pushurl >actual &&
 905        echo "YYY" >>actual &&
 906        git config --get-all remote.someremote.url >>actual &&
 907        cmp expect actual
 908'
 909
 910test_expect_success 'remote set-url --push bar aaa' '
 911        git remote set-url --push someremote bar aaa &&
 912        echo foo >expect &&
 913        echo bar >>expect &&
 914        echo "YYY" >>expect &&
 915        echo baz >>expect &&
 916        git config --get-all remote.someremote.pushurl >actual &&
 917        echo "YYY" >>actual &&
 918        git config --get-all remote.someremote.url >>actual &&
 919        cmp expect actual
 920'
 921
 922test_expect_success 'remote set-url --push --delete bar' '
 923        git remote set-url --push --delete someremote bar &&
 924        echo foo >expect &&
 925        echo "YYY" >>expect &&
 926        echo baz >>expect &&
 927        git config --get-all remote.someremote.pushurl >actual &&
 928        echo "YYY" >>actual &&
 929        git config --get-all remote.someremote.url >>actual &&
 930        cmp expect actual
 931'
 932
 933test_expect_success 'remote set-url --push --delete foo' '
 934        git remote set-url --push --delete someremote foo &&
 935        echo "YYY" >expect &&
 936        echo baz >>expect &&
 937        test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 938        echo "YYY" >>actual &&
 939        git config --get-all remote.someremote.url >>actual &&
 940        cmp expect actual
 941'
 942
 943test_expect_success 'remote set-url --add bbb' '
 944        git remote set-url --add someremote bbb &&
 945        echo "YYY" >expect &&
 946        echo baz >>expect &&
 947        echo bbb >>expect &&
 948        test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 949        echo "YYY" >>actual &&
 950        git config --get-all remote.someremote.url >>actual &&
 951        cmp expect actual
 952'
 953
 954test_expect_success 'remote set-url --delete .*' '
 955        test_must_fail git remote set-url --delete someremote .\* &&
 956        echo "YYY" >expect &&
 957        echo baz >>expect &&
 958        echo bbb >>expect &&
 959        test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 960        echo "YYY" >>actual &&
 961        git config --get-all remote.someremote.url >>actual &&
 962        cmp expect actual
 963'
 964
 965test_expect_success 'remote set-url --delete bbb' '
 966        git remote set-url --delete someremote bbb &&
 967        echo "YYY" >expect &&
 968        echo baz >>expect &&
 969        test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 970        echo "YYY" >>actual &&
 971        git config --get-all remote.someremote.url >>actual &&
 972        cmp expect actual
 973'
 974
 975test_expect_success 'remote set-url --delete baz' '
 976        test_must_fail git remote set-url --delete someremote baz &&
 977        echo "YYY" >expect &&
 978        echo baz >>expect &&
 979        test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 980        echo "YYY" >>actual &&
 981        git config --get-all remote.someremote.url >>actual &&
 982        cmp expect actual
 983'
 984
 985test_expect_success 'remote set-url --add ccc' '
 986        git remote set-url --add someremote ccc &&
 987        echo "YYY" >expect &&
 988        echo baz >>expect &&
 989        echo ccc >>expect &&
 990        test_must_fail git config --get-all remote.someremote.pushurl >actual &&
 991        echo "YYY" >>actual &&
 992        git config --get-all remote.someremote.url >>actual &&
 993        cmp expect actual
 994'
 995
 996test_expect_success 'remote set-url --delete baz' '
 997        git remote set-url --delete someremote baz &&
 998        echo "YYY" >expect &&
 999        echo ccc >>expect &&
1000        test_must_fail git config --get-all remote.someremote.pushurl >actual &&
1001        echo "YYY" >>actual &&
1002        git config --get-all remote.someremote.url >>actual &&
1003        cmp expect actual
1004'
1005
1006test_done