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