t / t3200-branch.shon commit branch: add a --copy (-c) option to go with --move (-m) (52d59cc)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Amos Waterland
   4#
   5
   6test_description='git branch assorted tests'
   7
   8. ./test-lib.sh
   9
  10test_expect_success 'prepare a trivial repository' '
  11        echo Hello >A &&
  12        git update-index --add A &&
  13        git commit -m "Initial commit." &&
  14        echo World >>A &&
  15        git update-index --add A &&
  16        git commit -m "Second commit." &&
  17        HEAD=$(git rev-parse --verify HEAD)
  18'
  19
  20test_expect_success 'git branch --help should not have created a bogus branch' '
  21        test_might_fail git branch --man --help </dev/null >/dev/null 2>&1 &&
  22        test_path_is_missing .git/refs/heads/--help
  23'
  24
  25test_expect_success 'branch -h in broken repository' '
  26        mkdir broken &&
  27        (
  28                cd broken &&
  29                git init &&
  30                >.git/refs/heads/master &&
  31                test_expect_code 129 git branch -h >usage 2>&1
  32        ) &&
  33        test_i18ngrep "[Uu]sage" broken/usage
  34'
  35
  36test_expect_success 'git branch abc should create a branch' '
  37        git branch abc && test_path_is_file .git/refs/heads/abc
  38'
  39
  40test_expect_success 'git branch a/b/c should create a branch' '
  41        git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
  42'
  43
  44test_expect_success 'git branch HEAD should fail' '
  45        test_must_fail git branch HEAD
  46'
  47
  48cat >expect <<EOF
  49$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
  50EOF
  51test_expect_success 'git branch -l d/e/f should create a branch and a log' '
  52        GIT_COMMITTER_DATE="2005-05-26 23:30" \
  53        git branch -l d/e/f &&
  54        test_path_is_file .git/refs/heads/d/e/f &&
  55        test_path_is_file .git/logs/refs/heads/d/e/f &&
  56        test_cmp expect .git/logs/refs/heads/d/e/f
  57'
  58
  59test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
  60        git branch -d d/e/f &&
  61        test_path_is_missing .git/refs/heads/d/e/f &&
  62        test_must_fail git reflog exists refs/heads/d/e/f
  63'
  64
  65test_expect_success 'git branch j/k should work after branch j has been deleted' '
  66        git branch j &&
  67        git branch -d j &&
  68        git branch j/k
  69'
  70
  71test_expect_success 'git branch l should work after branch l/m has been deleted' '
  72        git branch l/m &&
  73        git branch -d l/m &&
  74        git branch l
  75'
  76
  77test_expect_success 'git branch -m dumps usage' '
  78        test_expect_code 128 git branch -m 2>err &&
  79        test_i18ngrep "branch name required" err
  80'
  81
  82test_expect_success 'git branch -m m broken_symref should work' '
  83        test_when_finished "git branch -D broken_symref" &&
  84        git branch -l m &&
  85        git symbolic-ref refs/heads/broken_symref refs/heads/i_am_broken &&
  86        git branch -m m broken_symref &&
  87        git reflog exists refs/heads/broken_symref &&
  88        test_must_fail git reflog exists refs/heads/i_am_broken
  89'
  90
  91test_expect_success 'git branch -m m m/m should work' '
  92        git branch -l m &&
  93        git branch -m m m/m &&
  94        git reflog exists refs/heads/m/m
  95'
  96
  97test_expect_success 'git branch -m n/n n should work' '
  98        git branch -l n/n &&
  99        git branch -m n/n n &&
 100        git reflog exists refs/heads/n
 101'
 102
 103test_expect_success 'git branch -m o/o o should fail when o/p exists' '
 104        git branch o/o &&
 105        git branch o/p &&
 106        test_must_fail git branch -m o/o o
 107'
 108
 109test_expect_success 'git branch -m o/q o/p should fail when o/p exists' '
 110        git branch o/q &&
 111        test_must_fail git branch -m o/q o/p
 112'
 113
 114test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
 115        git branch -M o/q o/p
 116'
 117
 118test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
 119        git branch o/q &&
 120        git branch -m -f o/q o/p
 121'
 122
 123test_expect_success 'git branch -m q r/q should fail when r exists' '
 124        git branch q &&
 125        git branch r &&
 126        test_must_fail git branch -m q r/q
 127'
 128
 129test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
 130        git branch bar &&
 131        git checkout -b foo &&
 132        test_must_fail git branch -M bar foo
 133'
 134
 135test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
 136        git checkout -b baz &&
 137        git branch bam &&
 138        git branch -M baz bam &&
 139        test $(git rev-parse --abbrev-ref HEAD) = bam
 140'
 141
 142test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' '
 143        msg="Branch: renamed refs/heads/baz to refs/heads/bam" &&
 144        grep " 0\{40\}.*$msg$" .git/logs/HEAD &&
 145        grep "^0\{40\}.*$msg$" .git/logs/HEAD
 146'
 147
 148test_expect_success 'git branch -M baz bam should succeed when baz is checked out as linked working tree' '
 149        git checkout master &&
 150        git worktree add -b baz bazdir &&
 151        git worktree add -f bazdir2 baz &&
 152        git branch -M baz bam &&
 153        test $(git -C bazdir rev-parse --abbrev-ref HEAD) = bam &&
 154        test $(git -C bazdir2 rev-parse --abbrev-ref HEAD) = bam
 155'
 156
 157test_expect_success 'git branch -M baz bam should succeed within a worktree in which baz is checked out' '
 158        git checkout -b baz &&
 159        git worktree add -f bazdir3 baz &&
 160        (
 161                cd bazdir3 &&
 162                git branch -M baz bam &&
 163                test $(git rev-parse --abbrev-ref HEAD) = bam
 164        ) &&
 165        test $(git rev-parse --abbrev-ref HEAD) = bam
 166'
 167
 168test_expect_success 'git branch -M master should work when master is checked out' '
 169        git checkout master &&
 170        git branch -M master
 171'
 172
 173test_expect_success 'git branch -M master master should work when master is checked out' '
 174        git checkout master &&
 175        git branch -M master master
 176'
 177
 178test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
 179        git checkout master &&
 180        git branch master2 &&
 181        git branch -M master2 master2
 182'
 183
 184test_expect_success 'git branch -v -d t should work' '
 185        git branch t &&
 186        test_path_is_file .git/refs/heads/t &&
 187        git branch -v -d t &&
 188        test_path_is_missing .git/refs/heads/t
 189'
 190
 191test_expect_success 'git branch -v -m t s should work' '
 192        git branch t &&
 193        test_path_is_file .git/refs/heads/t &&
 194        git branch -v -m t s &&
 195        test_path_is_missing .git/refs/heads/t &&
 196        test_path_is_file .git/refs/heads/s &&
 197        git branch -d s
 198'
 199
 200test_expect_success 'git branch -m -d t s should fail' '
 201        git branch t &&
 202        test_path_is_file .git/refs/heads/t &&
 203        test_must_fail git branch -m -d t s &&
 204        git branch -d t &&
 205        test_path_is_missing .git/refs/heads/t
 206'
 207
 208test_expect_success 'git branch --list -d t should fail' '
 209        git branch t &&
 210        test_path_is_file .git/refs/heads/t &&
 211        test_must_fail git branch --list -d t &&
 212        git branch -d t &&
 213        test_path_is_missing .git/refs/heads/t
 214'
 215
 216test_expect_success 'git branch --list -v with --abbrev' '
 217        test_when_finished "git branch -D t" &&
 218        git branch t &&
 219        git branch -v --list t >actual.default &&
 220        git branch -v --list --abbrev t >actual.abbrev &&
 221        test_cmp actual.default actual.abbrev &&
 222
 223        git branch -v --list --no-abbrev t >actual.noabbrev &&
 224        git branch -v --list --abbrev=0 t >actual.0abbrev &&
 225        test_cmp actual.noabbrev actual.0abbrev &&
 226
 227        git branch -v --list --abbrev=36 t >actual.36abbrev &&
 228        # how many hexdigits are used?
 229        read name objdefault rest <actual.abbrev &&
 230        read name obj36 rest <actual.36abbrev &&
 231        objfull=$(git rev-parse --verify t) &&
 232
 233        # are we really getting abbreviations?
 234        test "$obj36" != "$objdefault" &&
 235        expr "$obj36" : "$objdefault" >/dev/null &&
 236        test "$objfull" != "$obj36" &&
 237        expr "$objfull" : "$obj36" >/dev/null
 238
 239'
 240
 241test_expect_success 'git branch --column' '
 242        COLUMNS=81 git branch --column=column >actual &&
 243        cat >expected <<\EOF &&
 244  a/b/c     bam       foo       l       * master    n         o/p       r
 245  abc       bar       j/k       m/m       master2   o/o       q
 246EOF
 247        test_cmp expected actual
 248'
 249
 250test_expect_success 'git branch --column with an extremely long branch name' '
 251        long=this/is/a/part/of/long/branch/name &&
 252        long=z$long/$long/$long/$long &&
 253        test_when_finished "git branch -d $long" &&
 254        git branch $long &&
 255        COLUMNS=80 git branch --column=column >actual &&
 256        cat >expected <<EOF &&
 257  a/b/c
 258  abc
 259  bam
 260  bar
 261  foo
 262  j/k
 263  l
 264  m/m
 265* master
 266  master2
 267  n
 268  o/o
 269  o/p
 270  q
 271  r
 272  $long
 273EOF
 274        test_cmp expected actual
 275'
 276
 277test_expect_success 'git branch with column.*' '
 278        git config column.ui column &&
 279        git config column.branch "dense" &&
 280        COLUMNS=80 git branch >actual &&
 281        git config --unset column.branch &&
 282        git config --unset column.ui &&
 283        cat >expected <<\EOF &&
 284  a/b/c   bam   foo   l   * master    n     o/p   r
 285  abc     bar   j/k   m/m   master2   o/o   q
 286EOF
 287        test_cmp expected actual
 288'
 289
 290test_expect_success 'git branch --column -v should fail' '
 291        test_must_fail git branch --column -v
 292'
 293
 294test_expect_success 'git branch -v with column.ui ignored' '
 295        git config column.ui column &&
 296        COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
 297        git config --unset column.ui &&
 298        cat >expected <<\EOF &&
 299  a/b/c
 300  abc
 301  bam
 302  bar
 303  foo
 304  j/k
 305  l
 306  m/m
 307* master
 308  master2
 309  n
 310  o/o
 311  o/p
 312  q
 313  r
 314EOF
 315        test_cmp expected actual
 316'
 317
 318mv .git/config .git/config-saved
 319
 320test_expect_success 'git branch -m q q2 without config should succeed' '
 321        git branch -m q q2 &&
 322        git branch -m q2 q
 323'
 324
 325mv .git/config-saved .git/config
 326
 327git config branch.s/s.dummy Hello
 328
 329test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
 330        git branch -l s/s &&
 331        git reflog exists refs/heads/s/s &&
 332        git branch -l s/t &&
 333        git reflog exists refs/heads/s/t &&
 334        git branch -d s/t &&
 335        git branch -m s/s s &&
 336        git reflog exists refs/heads/s
 337'
 338
 339test_expect_success 'config information was renamed, too' '
 340        test $(git config branch.s.dummy) = Hello &&
 341        test_must_fail git config branch.s/s.dummy
 342'
 343
 344test_expect_success 'git branch -m correctly renames multiple config sections' '
 345        test_when_finished "git checkout master" &&
 346        git checkout -b source master &&
 347
 348        # Assert that a config file with multiple config sections has
 349        # those sections preserved...
 350        cat >expect <<-\EOF &&
 351        branch.dest.key1=value1
 352        some.gar.b=age
 353        branch.dest.key2=value2
 354        EOF
 355        cat >config.branch <<\EOF &&
 356;; Note the lack of -\EOF above & mixed indenting here. This is
 357;; intentional, we are also testing that the formatting of copied
 358;; sections is preserved.
 359
 360;; Comment for source. Tabs
 361[branch "source"]
 362        ;; Comment for the source value
 363        key1 = value1
 364;; Comment for some.gar. Spaces
 365[some "gar"]
 366    ;; Comment for the some.gar value
 367    b = age
 368;; Comment for source, again. Mixed tabs/spaces.
 369[branch "source"]
 370    ;; Comment for the source value, again
 371        key2 = value2
 372EOF
 373        cat config.branch >>.git/config &&
 374        git branch -m source dest &&
 375        git config -f .git/config -l | grep -F -e source -e dest -e some.gar >actual &&
 376        test_cmp expect actual &&
 377
 378        # ...and that the comments for those sections are also
 379        # preserved.
 380        cat config.branch | sed "s/\"source\"/\"dest\"/" >expect &&
 381        sed -n -e "/Note the lack/,\$p" .git/config >actual &&
 382        test_cmp expect actual
 383'
 384
 385test_expect_success 'git branch -c dumps usage' '
 386        test_expect_code 128 git branch -c 2>err &&
 387        test_i18ngrep "branch name required" err
 388'
 389
 390test_expect_success 'git branch --copy dumps usage' '
 391        test_expect_code 128 git branch --copy 2>err &&
 392        test_i18ngrep "branch name required" err
 393'
 394
 395test_expect_success 'git branch -c d e should work' '
 396        git branch -l d &&
 397        git reflog exists refs/heads/d &&
 398        git config branch.d.dummy Hello &&
 399        git branch -c d e &&
 400        git reflog exists refs/heads/d &&
 401        git reflog exists refs/heads/e &&
 402        echo Hello >expect &&
 403        git config branch.e.dummy >actual &&
 404        test_cmp expect actual &&
 405        echo Hello >expect &&
 406        git config branch.d.dummy >actual &&
 407        test_cmp expect actual
 408'
 409
 410test_expect_success 'git branch --copy is a synonym for -c' '
 411        git branch -l copy &&
 412        git reflog exists refs/heads/copy &&
 413        git config branch.copy.dummy Hello &&
 414        git branch --copy copy copy-to &&
 415        git reflog exists refs/heads/copy &&
 416        git reflog exists refs/heads/copy-to &&
 417        echo Hello >expect &&
 418        git config branch.copy.dummy >actual &&
 419        test_cmp expect actual &&
 420        echo Hello >expect &&
 421        git config branch.copy-to.dummy >actual &&
 422        test_cmp expect actual
 423'
 424
 425test_expect_success 'git branch -c ee ef should copy and checkout branch ef' '
 426        git checkout -b ee &&
 427        git reflog exists refs/heads/ee &&
 428        git config branch.ee.dummy Hello &&
 429        git branch -c ee ef &&
 430        git reflog exists refs/heads/ee &&
 431        git reflog exists refs/heads/ef &&
 432        test $(git config branch.ee.dummy) = Hello &&
 433        test $(git config branch.ef.dummy) = Hello &&
 434        test $(git rev-parse --abbrev-ref HEAD) = ef
 435'
 436
 437test_expect_success 'git branch -c f/f g/g should work' '
 438        git branch -l f/f &&
 439        git reflog exists refs/heads/f/f &&
 440        git config branch.f/f.dummy Hello &&
 441        git branch -c f/f g/g &&
 442        git reflog exists refs/heads/f/f &&
 443        git reflog exists refs/heads/g/g &&
 444        test $(git config branch.f/f.dummy) = Hello &&
 445        test $(git config branch.g/g.dummy) = Hello
 446'
 447
 448test_expect_success 'git branch -c m2 m2 should work' '
 449        git branch -l m2 &&
 450        git reflog exists refs/heads/m2 &&
 451        git config branch.m2.dummy Hello &&
 452        git branch -c m2 m2 &&
 453        git reflog exists refs/heads/m2 &&
 454        test $(git config branch.m2.dummy) = Hello
 455'
 456
 457test_expect_success 'git branch -c zz zz/zz should fail' '
 458        git branch -l zz &&
 459        git reflog exists refs/heads/zz &&
 460        test_must_fail git branch -c zz zz/zz
 461'
 462
 463test_expect_success 'git branch -c b/b b should fail' '
 464        git branch -l b/b &&
 465        test_must_fail git branch -c b/b b
 466'
 467
 468test_expect_success 'git branch -C o/q o/p should work when o/p exists' '
 469        git branch -l o/q &&
 470        git reflog exists refs/heads/o/q &&
 471        git reflog exists refs/heads/o/p &&
 472        git branch -C o/q o/p
 473'
 474
 475test_expect_success 'git branch -c -f o/q o/p should work when o/p exists' '
 476        git reflog exists refs/heads/o/q &&
 477        git reflog exists refs/heads/o/p &&
 478        git branch -c -f o/q o/p
 479'
 480
 481test_expect_success 'git branch -c qq rr/qq should fail when r exists' '
 482        git branch qq &&
 483        git branch rr &&
 484        test_must_fail git branch -c qq rr/qq
 485'
 486
 487test_expect_success 'git branch -C b1 b2 should fail when b2 is checked out' '
 488        git branch b1 &&
 489        git checkout -b b2 &&
 490        test_must_fail git branch -C b1 b2
 491'
 492
 493test_expect_success 'git branch -C c1 c2 should succeed when c1 is checked out' '
 494        git checkout -b c1 &&
 495        git branch c2 &&
 496        git branch -C c1 c2 &&
 497        test $(git rev-parse --abbrev-ref HEAD) = c2
 498'
 499
 500test_expect_success 'git branch -C c1 c2 should add entries to .git/logs/HEAD' '
 501        msg="Branch: copied refs/heads/c1 to refs/heads/c2" &&
 502        grep "$msg$" .git/logs/HEAD
 503'
 504
 505test_expect_success 'git branch -C master should work when master is checked out' '
 506        git checkout master &&
 507        git branch -C master
 508'
 509
 510test_expect_success 'git branch -C master master should work when master is checked out' '
 511        git checkout master &&
 512        git branch -C master master
 513'
 514
 515test_expect_success 'git branch -C master5 master5 should work when master is checked out' '
 516        git checkout master &&
 517        git branch master5 &&
 518        git branch -C master5 master5
 519'
 520
 521test_expect_success 'git branch -C ab cd should overwrite existing config for cd' '
 522        git branch -l cd &&
 523        git reflog exists refs/heads/cd &&
 524        git config branch.cd.dummy CD &&
 525        git branch -l ab &&
 526        git reflog exists refs/heads/ab &&
 527        git config branch.ab.dummy AB &&
 528        git branch -C ab cd &&
 529        git reflog exists refs/heads/ab &&
 530        git reflog exists refs/heads/cd &&
 531        test $(git config branch.ab.dummy) = AB &&
 532        test $(git config branch.cd.dummy) = AB
 533'
 534
 535test_expect_success 'git branch -c correctly copies multiple config sections' '
 536        FOO=1 &&
 537        export FOO &&
 538        test_when_finished "git checkout master" &&
 539        git checkout -b source2 master &&
 540
 541        # Assert that a config file with multiple config sections has
 542        # those sections preserved...
 543        cat >expect <<-\EOF &&
 544        branch.source2.key1=value1
 545        branch.dest2.key1=value1
 546        more.gar.b=age
 547        branch.source2.key2=value2
 548        branch.dest2.key2=value2
 549        EOF
 550        cat >config.branch <<\EOF &&
 551;; Note the lack of -\EOF above & mixed indenting here. This is
 552;; intentional, we are also testing that the formatting of copied
 553;; sections is preserved.
 554
 555;; Comment for source2. Tabs
 556[branch "source2"]
 557        ;; Comment for the source2 value
 558        key1 = value1
 559;; Comment for more.gar. Spaces
 560[more "gar"]
 561    ;; Comment for the more.gar value
 562    b = age
 563;; Comment for source2, again. Mixed tabs/spaces.
 564[branch "source2"]
 565    ;; Comment for the source2 value, again
 566        key2 = value2
 567EOF
 568        cat config.branch >>.git/config &&
 569        git branch -c source2 dest2 &&
 570        git config -f .git/config -l | grep -F -e source2 -e dest2 -e more.gar >actual &&
 571        test_cmp expect actual &&
 572
 573        # ...and that the comments and formatting for those sections
 574        # is also preserved.
 575        cat >expect <<\EOF &&
 576;; Comment for source2. Tabs
 577[branch "source2"]
 578        ;; Comment for the source2 value
 579        key1 = value1
 580;; Comment for more.gar. Spaces
 581[branch "dest2"]
 582        ;; Comment for the source2 value
 583        key1 = value1
 584;; Comment for more.gar. Spaces
 585[more "gar"]
 586    ;; Comment for the more.gar value
 587    b = age
 588;; Comment for source2, again. Mixed tabs/spaces.
 589[branch "source2"]
 590    ;; Comment for the source2 value, again
 591        key2 = value2
 592[branch "dest2"]
 593    ;; Comment for the source2 value, again
 594        key2 = value2
 595EOF
 596        sed -n -e "/Comment for source2/,\$p" .git/config >actual &&
 597        test_cmp expect actual
 598'
 599
 600test_expect_success 'deleting a symref' '
 601        git branch target &&
 602        git symbolic-ref refs/heads/symref refs/heads/target &&
 603        echo "Deleted branch symref (was refs/heads/target)." >expect &&
 604        git branch -d symref >actual &&
 605        test_path_is_file .git/refs/heads/target &&
 606        test_path_is_missing .git/refs/heads/symref &&
 607        test_i18ncmp expect actual
 608'
 609
 610test_expect_success 'deleting a dangling symref' '
 611        git symbolic-ref refs/heads/dangling-symref nowhere &&
 612        test_path_is_file .git/refs/heads/dangling-symref &&
 613        echo "Deleted branch dangling-symref (was nowhere)." >expect &&
 614        git branch -d dangling-symref >actual &&
 615        test_path_is_missing .git/refs/heads/dangling-symref &&
 616        test_i18ncmp expect actual
 617'
 618
 619test_expect_success 'deleting a self-referential symref' '
 620        git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
 621        test_path_is_file .git/refs/heads/self-reference &&
 622        echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
 623        git branch -d self-reference >actual &&
 624        test_path_is_missing .git/refs/heads/self-reference &&
 625        test_i18ncmp expect actual
 626'
 627
 628test_expect_success 'renaming a symref is not allowed' '
 629        git symbolic-ref refs/heads/master2 refs/heads/master &&
 630        test_must_fail git branch -m master2 master3 &&
 631        git symbolic-ref refs/heads/master2 &&
 632        test_path_is_file .git/refs/heads/master &&
 633        test_path_is_missing .git/refs/heads/master3
 634'
 635
 636test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
 637        git branch -l u &&
 638        mv .git/logs/refs/heads/u real-u &&
 639        ln -s real-u .git/logs/refs/heads/u &&
 640        test_must_fail git branch -m u v
 641'
 642
 643test_expect_success 'test tracking setup via --track' '
 644        git config remote.local.url . &&
 645        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 646        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 647        git branch --track my1 local/master &&
 648        test $(git config branch.my1.remote) = local &&
 649        test $(git config branch.my1.merge) = refs/heads/master
 650'
 651
 652test_expect_success 'test tracking setup (non-wildcard, matching)' '
 653        git config remote.local.url . &&
 654        git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
 655        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 656        git branch --track my4 local/master &&
 657        test $(git config branch.my4.remote) = local &&
 658        test $(git config branch.my4.merge) = refs/heads/master
 659'
 660
 661test_expect_success 'tracking setup fails on non-matching refspec' '
 662        git config remote.local.url . &&
 663        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 664        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 665        git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
 666        test_must_fail git branch --track my5 local/master &&
 667        test_must_fail git config branch.my5.remote &&
 668        test_must_fail git config branch.my5.merge
 669'
 670
 671test_expect_success 'test tracking setup via config' '
 672        git config branch.autosetupmerge true &&
 673        git config remote.local.url . &&
 674        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 675        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 676        git branch my3 local/master &&
 677        test $(git config branch.my3.remote) = local &&
 678        test $(git config branch.my3.merge) = refs/heads/master
 679'
 680
 681test_expect_success 'test overriding tracking setup via --no-track' '
 682        git config branch.autosetupmerge true &&
 683        git config remote.local.url . &&
 684        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 685        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 686        git branch --no-track my2 local/master &&
 687        git config branch.autosetupmerge false &&
 688        ! test "$(git config branch.my2.remote)" = local &&
 689        ! test "$(git config branch.my2.merge)" = refs/heads/master
 690'
 691
 692test_expect_success 'no tracking without .fetch entries' '
 693        git config branch.autosetupmerge true &&
 694        git branch my6 s &&
 695        git config branch.autosetupmerge false &&
 696        test -z "$(git config branch.my6.remote)" &&
 697        test -z "$(git config branch.my6.merge)"
 698'
 699
 700test_expect_success 'test tracking setup via --track but deeper' '
 701        git config remote.local.url . &&
 702        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 703        (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
 704        git branch --track my7 local/o/o &&
 705        test "$(git config branch.my7.remote)" = local &&
 706        test "$(git config branch.my7.merge)" = refs/heads/o/o
 707'
 708
 709test_expect_success 'test deleting branch deletes branch config' '
 710        git branch -d my7 &&
 711        test -z "$(git config branch.my7.remote)" &&
 712        test -z "$(git config branch.my7.merge)"
 713'
 714
 715test_expect_success 'test deleting branch without config' '
 716        git branch my7 s &&
 717        sha1=$(git rev-parse my7 | cut -c 1-7) &&
 718        echo "Deleted branch my7 (was $sha1)." >expect &&
 719        git branch -d my7 >actual 2>&1 &&
 720        test_i18ncmp expect actual
 721'
 722
 723test_expect_success 'deleting currently checked out branch fails' '
 724        git worktree add -b my7 my7 &&
 725        test_must_fail git -C my7 branch -d my7 &&
 726        test_must_fail git branch -d my7
 727'
 728
 729test_expect_success 'test --track without .fetch entries' '
 730        git branch --track my8 &&
 731        test "$(git config branch.my8.remote)" &&
 732        test "$(git config branch.my8.merge)"
 733'
 734
 735test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
 736        git config branch.autosetupmerge always &&
 737        git branch my9 HEAD^ &&
 738        git config branch.autosetupmerge false
 739'
 740
 741test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
 742        test_must_fail git branch --track my10 HEAD^
 743'
 744
 745test_expect_success 'branch from tag w/--track causes failure' '
 746        git tag foobar &&
 747        test_must_fail git branch --track my11 foobar
 748'
 749
 750test_expect_success '--set-upstream-to fails on multiple branches' '
 751        test_must_fail git branch --set-upstream-to master a b c
 752'
 753
 754test_expect_success '--set-upstream-to fails on detached HEAD' '
 755        git checkout HEAD^{} &&
 756        test_must_fail git branch --set-upstream-to master &&
 757        git checkout -
 758'
 759
 760test_expect_success '--set-upstream-to fails on a missing dst branch' '
 761        test_must_fail git branch --set-upstream-to master does-not-exist
 762'
 763
 764test_expect_success '--set-upstream-to fails on a missing src branch' '
 765        test_must_fail git branch --set-upstream-to does-not-exist master
 766'
 767
 768test_expect_success '--set-upstream-to fails on a non-ref' '
 769        test_must_fail git branch --set-upstream-to HEAD^{}
 770'
 771
 772test_expect_success '--set-upstream-to fails on locked config' '
 773        test_when_finished "rm -f .git/config.lock" &&
 774        >.git/config.lock &&
 775        git branch locked &&
 776        test_must_fail git branch --set-upstream-to locked
 777'
 778
 779test_expect_success 'use --set-upstream-to modify HEAD' '
 780        test_config branch.master.remote foo &&
 781        test_config branch.master.merge foo &&
 782        git branch my12 &&
 783        git branch --set-upstream-to my12 &&
 784        test "$(git config branch.master.remote)" = "." &&
 785        test "$(git config branch.master.merge)" = "refs/heads/my12"
 786'
 787
 788test_expect_success 'use --set-upstream-to modify a particular branch' '
 789        git branch my13 &&
 790        git branch --set-upstream-to master my13 &&
 791        test "$(git config branch.my13.remote)" = "." &&
 792        test "$(git config branch.my13.merge)" = "refs/heads/master"
 793'
 794
 795test_expect_success '--unset-upstream should fail if given a non-existent branch' '
 796        test_must_fail git branch --unset-upstream i-dont-exist
 797'
 798
 799test_expect_success '--unset-upstream should fail if config is locked' '
 800        test_when_finished "rm -f .git/config.lock" &&
 801        git branch --set-upstream-to locked &&
 802        >.git/config.lock &&
 803        test_must_fail git branch --unset-upstream
 804'
 805
 806test_expect_success 'test --unset-upstream on HEAD' '
 807        git branch my14 &&
 808        test_config branch.master.remote foo &&
 809        test_config branch.master.merge foo &&
 810        git branch --set-upstream-to my14 &&
 811        git branch --unset-upstream &&
 812        test_must_fail git config branch.master.remote &&
 813        test_must_fail git config branch.master.merge &&
 814        # fail for a branch without upstream set
 815        test_must_fail git branch --unset-upstream
 816'
 817
 818test_expect_success '--unset-upstream should fail on multiple branches' '
 819        test_must_fail git branch --unset-upstream a b c
 820'
 821
 822test_expect_success '--unset-upstream should fail on detached HEAD' '
 823        git checkout HEAD^{} &&
 824        test_must_fail git branch --unset-upstream &&
 825        git checkout -
 826'
 827
 828test_expect_success 'test --unset-upstream on a particular branch' '
 829        git branch my15 &&
 830        git branch --set-upstream-to master my14 &&
 831        git branch --unset-upstream my14 &&
 832        test_must_fail git config branch.my14.remote &&
 833        test_must_fail git config branch.my14.merge
 834'
 835
 836test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
 837        git update-ref refs/remotes/origin/master HEAD &&
 838        git branch --set-upstream origin/master 2>actual &&
 839        test_when_finished git update-ref -d refs/remotes/origin/master &&
 840        test_when_finished git branch -d origin/master &&
 841        cat >expected <<EOF &&
 842The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
 843
 844If you wanted to make '"'master'"' track '"'origin/master'"', do this:
 845
 846    git branch -d origin/master
 847    git branch --set-upstream-to origin/master
 848EOF
 849        test_i18ncmp expected actual
 850'
 851
 852test_expect_success '--set-upstream with two args only shows the deprecation message' '
 853        git branch --set-upstream master my13 2>actual &&
 854        test_when_finished git branch --unset-upstream master &&
 855        cat >expected <<EOF &&
 856The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
 857EOF
 858        test_i18ncmp expected actual
 859'
 860
 861test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
 862        git branch --set-upstream my13 2>actual &&
 863        test_when_finished git branch --unset-upstream my13 &&
 864        cat >expected <<EOF &&
 865The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
 866EOF
 867        test_i18ncmp expected actual
 868'
 869
 870test_expect_success '--set-upstream-to notices an error to set branch as own upstream' '
 871        git branch --set-upstream-to refs/heads/my13 my13 2>actual &&
 872        cat >expected <<-\EOF &&
 873        warning: Not setting branch my13 as its own upstream.
 874        EOF
 875        test_expect_code 1 git config branch.my13.remote &&
 876        test_expect_code 1 git config branch.my13.merge &&
 877        test_i18ncmp expected actual
 878'
 879
 880# Keep this test last, as it changes the current branch
 881cat >expect <<EOF
 882$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
 883EOF
 884test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
 885        GIT_COMMITTER_DATE="2005-05-26 23:30" \
 886        git checkout -b g/h/i -l master &&
 887        test_path_is_file .git/refs/heads/g/h/i &&
 888        test_path_is_file .git/logs/refs/heads/g/h/i &&
 889        test_cmp expect .git/logs/refs/heads/g/h/i
 890'
 891
 892test_expect_success 'checkout -b makes reflog by default' '
 893        git checkout master &&
 894        git config --unset core.logAllRefUpdates &&
 895        git checkout -b alpha &&
 896        git rev-parse --verify alpha@{0}
 897'
 898
 899test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
 900        git checkout master &&
 901        git config core.logAllRefUpdates false &&
 902        git checkout -b beta &&
 903        test_must_fail git rev-parse --verify beta@{0}
 904'
 905
 906test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
 907        git checkout master &&
 908        git checkout -lb gamma &&
 909        git config --unset core.logAllRefUpdates &&
 910        git rev-parse --verify gamma@{0}
 911'
 912
 913test_expect_success 'avoid ambiguous track' '
 914        git config branch.autosetupmerge true &&
 915        git config remote.ambi1.url lalala &&
 916        git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
 917        git config remote.ambi2.url lilili &&
 918        git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
 919        test_must_fail git branch all1 master &&
 920        test -z "$(git config branch.all1.merge)"
 921'
 922
 923test_expect_success 'autosetuprebase local on a tracked local branch' '
 924        git config remote.local.url . &&
 925        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 926        git config branch.autosetuprebase local &&
 927        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 928        git branch mybase &&
 929        git branch --track myr1 mybase &&
 930        test "$(git config branch.myr1.remote)" = . &&
 931        test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
 932        test "$(git config branch.myr1.rebase)" = true
 933'
 934
 935test_expect_success 'autosetuprebase always on a tracked local branch' '
 936        git config remote.local.url . &&
 937        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 938        git config branch.autosetuprebase always &&
 939        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 940        git branch mybase2 &&
 941        git branch --track myr2 mybase &&
 942        test "$(git config branch.myr2.remote)" = . &&
 943        test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
 944        test "$(git config branch.myr2.rebase)" = true
 945'
 946
 947test_expect_success 'autosetuprebase remote on a tracked local branch' '
 948        git config remote.local.url . &&
 949        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 950        git config branch.autosetuprebase remote &&
 951        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 952        git branch mybase3 &&
 953        git branch --track myr3 mybase2 &&
 954        test "$(git config branch.myr3.remote)" = . &&
 955        test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
 956        ! test "$(git config branch.myr3.rebase)" = true
 957'
 958
 959test_expect_success 'autosetuprebase never on a tracked local branch' '
 960        git config remote.local.url . &&
 961        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 962        git config branch.autosetuprebase never &&
 963        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 964        git branch mybase4 &&
 965        git branch --track myr4 mybase2 &&
 966        test "$(git config branch.myr4.remote)" = . &&
 967        test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
 968        ! test "$(git config branch.myr4.rebase)" = true
 969'
 970
 971test_expect_success 'autosetuprebase local on a tracked remote branch' '
 972        git config remote.local.url . &&
 973        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 974        git config branch.autosetuprebase local &&
 975        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 976        git branch --track myr5 local/master &&
 977        test "$(git config branch.myr5.remote)" = local &&
 978        test "$(git config branch.myr5.merge)" = refs/heads/master &&
 979        ! test "$(git config branch.myr5.rebase)" = true
 980'
 981
 982test_expect_success 'autosetuprebase never on a tracked remote branch' '
 983        git config remote.local.url . &&
 984        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 985        git config branch.autosetuprebase never &&
 986        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 987        git branch --track myr6 local/master &&
 988        test "$(git config branch.myr6.remote)" = local &&
 989        test "$(git config branch.myr6.merge)" = refs/heads/master &&
 990        ! test "$(git config branch.myr6.rebase)" = true
 991'
 992
 993test_expect_success 'autosetuprebase remote on a tracked remote branch' '
 994        git config remote.local.url . &&
 995        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 996        git config branch.autosetuprebase remote &&
 997        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 998        git branch --track myr7 local/master &&
 999        test "$(git config branch.myr7.remote)" = local &&
1000        test "$(git config branch.myr7.merge)" = refs/heads/master &&
1001        test "$(git config branch.myr7.rebase)" = true
1002'
1003
1004test_expect_success 'autosetuprebase always on a tracked remote branch' '
1005        git config remote.local.url . &&
1006        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1007        git config branch.autosetuprebase remote &&
1008        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1009        git branch --track myr8 local/master &&
1010        test "$(git config branch.myr8.remote)" = local &&
1011        test "$(git config branch.myr8.merge)" = refs/heads/master &&
1012        test "$(git config branch.myr8.rebase)" = true
1013'
1014
1015test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
1016        git config --unset branch.autosetuprebase &&
1017        git config remote.local.url . &&
1018        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1019        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1020        git branch --track myr9 local/master &&
1021        test "$(git config branch.myr9.remote)" = local &&
1022        test "$(git config branch.myr9.merge)" = refs/heads/master &&
1023        test "z$(git config branch.myr9.rebase)" = z
1024'
1025
1026test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
1027        git config remote.local.url . &&
1028        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1029        (git show-ref -q refs/remotes/local/o || git fetch local) &&
1030        git branch mybase10 &&
1031        git branch --track myr10 mybase2 &&
1032        test "$(git config branch.myr10.remote)" = . &&
1033        test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
1034        test "z$(git config branch.myr10.rebase)" = z
1035'
1036
1037test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
1038        git config remote.local.url . &&
1039        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1040        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1041        git branch --no-track myr11 mybase2 &&
1042        test "z$(git config branch.myr11.remote)" = z &&
1043        test "z$(git config branch.myr11.merge)" = z &&
1044        test "z$(git config branch.myr11.rebase)" = z
1045'
1046
1047test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
1048        git config remote.local.url . &&
1049        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1050        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1051        git branch --no-track myr12 local/master &&
1052        test "z$(git config branch.myr12.remote)" = z &&
1053        test "z$(git config branch.myr12.merge)" = z &&
1054        test "z$(git config branch.myr12.rebase)" = z
1055'
1056
1057test_expect_success 'autosetuprebase never on an untracked local branch' '
1058        git config branch.autosetuprebase never &&
1059        git config remote.local.url . &&
1060        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1061        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1062        git branch --no-track myr13 mybase2 &&
1063        test "z$(git config branch.myr13.remote)" = z &&
1064        test "z$(git config branch.myr13.merge)" = z &&
1065        test "z$(git config branch.myr13.rebase)" = z
1066'
1067
1068test_expect_success 'autosetuprebase local on an untracked local branch' '
1069        git config branch.autosetuprebase local &&
1070        git config remote.local.url . &&
1071        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1072        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1073        git branch --no-track myr14 mybase2 &&
1074        test "z$(git config branch.myr14.remote)" = z &&
1075        test "z$(git config branch.myr14.merge)" = z &&
1076        test "z$(git config branch.myr14.rebase)" = z
1077'
1078
1079test_expect_success 'autosetuprebase remote on an untracked local branch' '
1080        git config branch.autosetuprebase remote &&
1081        git config remote.local.url . &&
1082        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1083        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1084        git branch --no-track myr15 mybase2 &&
1085        test "z$(git config branch.myr15.remote)" = z &&
1086        test "z$(git config branch.myr15.merge)" = z &&
1087        test "z$(git config branch.myr15.rebase)" = z
1088'
1089
1090test_expect_success 'autosetuprebase always on an untracked local branch' '
1091        git config branch.autosetuprebase always &&
1092        git config remote.local.url . &&
1093        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1094        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1095        git branch --no-track myr16 mybase2 &&
1096        test "z$(git config branch.myr16.remote)" = z &&
1097        test "z$(git config branch.myr16.merge)" = z &&
1098        test "z$(git config branch.myr16.rebase)" = z
1099'
1100
1101test_expect_success 'autosetuprebase never on an untracked remote branch' '
1102        git config branch.autosetuprebase never &&
1103        git config remote.local.url . &&
1104        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1105        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1106        git branch --no-track myr17 local/master &&
1107        test "z$(git config branch.myr17.remote)" = z &&
1108        test "z$(git config branch.myr17.merge)" = z &&
1109        test "z$(git config branch.myr17.rebase)" = z
1110'
1111
1112test_expect_success 'autosetuprebase local on an untracked remote branch' '
1113        git config branch.autosetuprebase local &&
1114        git config remote.local.url . &&
1115        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1116        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1117        git branch --no-track myr18 local/master &&
1118        test "z$(git config branch.myr18.remote)" = z &&
1119        test "z$(git config branch.myr18.merge)" = z &&
1120        test "z$(git config branch.myr18.rebase)" = z
1121'
1122
1123test_expect_success 'autosetuprebase remote on an untracked remote branch' '
1124        git config branch.autosetuprebase remote &&
1125        git config remote.local.url . &&
1126        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1127        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1128        git branch --no-track myr19 local/master &&
1129        test "z$(git config branch.myr19.remote)" = z &&
1130        test "z$(git config branch.myr19.merge)" = z &&
1131        test "z$(git config branch.myr19.rebase)" = z
1132'
1133
1134test_expect_success 'autosetuprebase always on an untracked remote branch' '
1135        git config branch.autosetuprebase always &&
1136        git config remote.local.url . &&
1137        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
1138        (git show-ref -q refs/remotes/local/master || git fetch local) &&
1139        git branch --no-track myr20 local/master &&
1140        test "z$(git config branch.myr20.remote)" = z &&
1141        test "z$(git config branch.myr20.merge)" = z &&
1142        test "z$(git config branch.myr20.rebase)" = z
1143'
1144
1145test_expect_success 'autosetuprebase always on detached HEAD' '
1146        git config branch.autosetupmerge always &&
1147        test_when_finished git checkout master &&
1148        git checkout HEAD^0 &&
1149        git branch my11 &&
1150        test -z "$(git config branch.my11.remote)" &&
1151        test -z "$(git config branch.my11.merge)"
1152'
1153
1154test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
1155        git config branch.autosetuprebase garbage &&
1156        test_must_fail git branch
1157'
1158
1159test_expect_success 'detect misconfigured autosetuprebase (no value)' '
1160        git config --unset branch.autosetuprebase &&
1161        echo "[branch] autosetuprebase" >>.git/config &&
1162        test_must_fail git branch &&
1163        git config --unset branch.autosetuprebase
1164'
1165
1166test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
1167        git checkout my9 &&
1168        git config --unset branch.my8.merge &&
1169        test_must_fail git branch -d my8
1170'
1171
1172test_expect_success 'attempt to delete a branch merged to its base' '
1173        # we are on my9 which is the initial commit; traditionally
1174        # we would not have allowed deleting my8 that is not merged
1175        # to my9, but it is set to track master that already has my8
1176        git config branch.my8.merge refs/heads/master &&
1177        git branch -d my8
1178'
1179
1180test_expect_success 'attempt to delete a branch merged to its base' '
1181        git checkout master &&
1182        echo Third >>A &&
1183        git commit -m "Third commit" A &&
1184        git branch -t my10 my9 &&
1185        git branch -f my10 HEAD^ &&
1186        # we are on master which is at the third commit, and my10
1187        # is behind us, so traditionally we would have allowed deleting
1188        # it; but my10 is set to track my9 that is further behind.
1189        test_must_fail git branch -d my10
1190'
1191
1192test_expect_success 'use set-upstream on the current branch' '
1193        git checkout master &&
1194        git --bare init myupstream.git &&
1195        git push myupstream.git master:refs/heads/frotz &&
1196        git remote add origin myupstream.git &&
1197        git fetch &&
1198        git branch --set-upstream master origin/frotz &&
1199
1200        test "z$(git config branch.master.remote)" = "zorigin" &&
1201        test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
1202
1203'
1204
1205test_expect_success 'use --edit-description' '
1206        write_script editor <<-\EOF &&
1207                echo "New contents" >"$1"
1208        EOF
1209        EDITOR=./editor git branch --edit-description &&
1210                write_script editor <<-\EOF &&
1211                git stripspace -s <"$1" >"EDITOR_OUTPUT"
1212        EOF
1213        EDITOR=./editor git branch --edit-description &&
1214        echo "New contents" >expect &&
1215        test_cmp EDITOR_OUTPUT expect
1216'
1217
1218test_expect_success 'detect typo in branch name when using --edit-description' '
1219        write_script editor <<-\EOF &&
1220                echo "New contents" >"$1"
1221        EOF
1222        test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch
1223'
1224
1225test_expect_success 'refuse --edit-description on unborn branch for now' '
1226        write_script editor <<-\EOF &&
1227                echo "New contents" >"$1"
1228        EOF
1229        git checkout --orphan unborn &&
1230        test_must_fail env EDITOR=./editor git branch --edit-description
1231'
1232
1233test_expect_success '--merged catches invalid object names' '
1234        test_must_fail git branch --merged 0000000000000000000000000000000000000000
1235'
1236
1237test_expect_success '--merged is incompatible with --no-merged' '
1238        test_must_fail git branch --merged HEAD --no-merged HEAD
1239'
1240
1241test_expect_success 'tracking with unexpected .fetch refspec' '
1242        rm -rf a b c d &&
1243        git init a &&
1244        (
1245                cd a &&
1246                test_commit a
1247        ) &&
1248        git init b &&
1249        (
1250                cd b &&
1251                test_commit b
1252        ) &&
1253        git init c &&
1254        (
1255                cd c &&
1256                test_commit c &&
1257                git remote add a ../a &&
1258                git remote add b ../b &&
1259                git fetch --all
1260        ) &&
1261        git init d &&
1262        (
1263                cd d &&
1264                git remote add c ../c &&
1265                git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
1266                git fetch c &&
1267                git branch --track local/a/master remotes/a/master &&
1268                test "$(git config branch.local/a/master.remote)" = "c" &&
1269                test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
1270                git rev-parse --verify a >expect &&
1271                git rev-parse --verify local/a/master >actual &&
1272                test_cmp expect actual
1273        )
1274'
1275
1276test_done