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