t / t3200-branch.shon commit Merge branch 'rs/zip-compresssed-size-with-export-subst' (e9bebbb)
   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 \
  11    'prepare a trivial repository' \
  12    'echo Hello > A &&
  13     git update-index --add A &&
  14     git commit -m "Initial commit." &&
  15     echo World >> A &&
  16     git update-index --add A &&
  17     git commit -m "Second commit." &&
  18     HEAD=$(git rev-parse --verify HEAD)'
  19
  20test_expect_success \
  21    'git branch --help should not have created a bogus branch' '
  22     test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null &&
  23     test_path_is_missing .git/refs/heads/--help
  24'
  25
  26test_expect_success 'branch -h in broken repository' '
  27        mkdir broken &&
  28        (
  29                cd broken &&
  30                git init &&
  31                >.git/refs/heads/master &&
  32                test_expect_code 129 git branch -h >usage 2>&1
  33        ) &&
  34        test_i18ngrep "[Uu]sage" broken/usage
  35'
  36
  37test_expect_success \
  38    'git branch abc should create a branch' \
  39    'git branch abc && test_path_is_file .git/refs/heads/abc'
  40
  41test_expect_success \
  42    'git branch a/b/c should create a branch' \
  43    'git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c'
  44
  45test_expect_success \
  46    'git branch HEAD should fail' \
  47    'test_must_fail git branch HEAD'
  48
  49cat >expect <<EOF
  50$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
  51EOF
  52test_expect_success \
  53    'git branch -l d/e/f should create a branch and a log' \
  54        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
  55     git branch -l d/e/f &&
  56         test_path_is_file .git/refs/heads/d/e/f &&
  57         test_path_is_file .git/logs/refs/heads/d/e/f &&
  58         test_cmp expect .git/logs/refs/heads/d/e/f'
  59
  60test_expect_success \
  61    'git branch -d d/e/f should delete a branch and a log' \
  62        'git branch -d d/e/f &&
  63         test_path_is_missing .git/refs/heads/d/e/f &&
  64         test_path_is_missing .git/logs/refs/heads/d/e/f'
  65
  66test_expect_success \
  67    'git branch j/k should work after branch j has been deleted' \
  68       'git branch j &&
  69        git branch -d j &&
  70        git branch j/k'
  71
  72test_expect_success \
  73    'git branch l should work after branch l/m has been deleted' \
  74       'git branch l/m &&
  75        git branch -d l/m &&
  76        git branch l'
  77
  78test_expect_success \
  79    'git branch -m dumps usage' \
  80       'test_expect_code 128 git branch -m 2>err &&
  81        test_i18ngrep "too many branches for a rename operation" err'
  82
  83test_expect_success \
  84    'git branch -m m m/m should work' \
  85       'git branch -l m &&
  86        git branch -m m m/m &&
  87        test_path_is_file .git/logs/refs/heads/m/m'
  88
  89test_expect_success \
  90    'git branch -m n/n n should work' \
  91       'git branch -l n/n &&
  92        git branch -m n/n n &&
  93        test_path_is_file .git/logs/refs/heads/n'
  94
  95test_expect_success 'git branch -m o/o o should fail when o/p exists' '
  96        git branch o/o &&
  97        git branch o/p &&
  98        test_must_fail git branch -m o/o o
  99'
 100
 101test_expect_success 'git branch -m q r/q should fail when r exists' '
 102        git branch q &&
 103        git branch r &&
 104        test_must_fail git branch -m q r/q
 105'
 106
 107test_expect_success 'git branch -M foo bar should fail when bar is checked out' '
 108        git branch bar &&
 109        git checkout -b foo &&
 110        test_must_fail git branch -M bar foo
 111'
 112
 113test_expect_success 'git branch -M baz bam should succeed when baz is checked out' '
 114        git checkout -b baz &&
 115        git branch bam &&
 116        git branch -M baz bam
 117'
 118
 119test_expect_success 'git branch -M master should work when master is checked out' '
 120        git checkout master &&
 121        git branch -M master
 122'
 123
 124test_expect_success 'git branch -M master master should work when master is checked out' '
 125        git checkout master &&
 126        git branch -M master master
 127'
 128
 129test_expect_success 'git branch -M master2 master2 should work when master is checked out' '
 130        git checkout master &&
 131        git branch master2 &&
 132        git branch -M master2 master2
 133'
 134
 135test_expect_success 'git branch -v -d t should work' '
 136        git branch t &&
 137        test_path_is_file .git/refs/heads/t &&
 138        git branch -v -d t &&
 139        test_path_is_missing .git/refs/heads/t
 140'
 141
 142test_expect_success 'git branch -v -m t s should work' '
 143        git branch t &&
 144        test_path_is_file .git/refs/heads/t &&
 145        git branch -v -m t s &&
 146        test_path_is_missing .git/refs/heads/t &&
 147        test_path_is_file .git/refs/heads/s &&
 148        git branch -d s
 149'
 150
 151test_expect_success 'git branch -m -d t s should fail' '
 152        git branch t &&
 153        test_path_is_file .git/refs/heads/t &&
 154        test_must_fail git branch -m -d t s &&
 155        git branch -d t &&
 156        test_path_is_missing .git/refs/heads/t
 157'
 158
 159test_expect_success 'git branch --list -d t should fail' '
 160        git branch t &&
 161        test_path_is_file .git/refs/heads/t &&
 162        test_must_fail git branch --list -d t &&
 163        git branch -d t &&
 164        test_path_is_missing .git/refs/heads/t
 165'
 166
 167test_expect_success 'git branch --column' '
 168        COLUMNS=81 git branch --column=column >actual &&
 169        cat >expected <<\EOF &&
 170  a/b/c     bam       foo       l       * master    n         o/p       r
 171  abc       bar       j/k       m/m       master2   o/o       q
 172EOF
 173        test_cmp expected actual
 174'
 175
 176test_expect_success 'git branch --column with an extremely long branch name' '
 177        long=this/is/a/part/of/long/branch/name &&
 178        long=z$long/$long/$long/$long &&
 179        test_when_finished "git branch -d $long" &&
 180        git branch $long &&
 181        COLUMNS=80 git branch --column=column >actual &&
 182        cat >expected <<EOF &&
 183  a/b/c
 184  abc
 185  bam
 186  bar
 187  foo
 188  j/k
 189  l
 190  m/m
 191* master
 192  master2
 193  n
 194  o/o
 195  o/p
 196  q
 197  r
 198  $long
 199EOF
 200        test_cmp expected actual
 201'
 202
 203test_expect_success 'git branch with column.*' '
 204        git config column.ui column &&
 205        git config column.branch "dense" &&
 206        COLUMNS=80 git branch >actual &&
 207        git config --unset column.branch &&
 208        git config --unset column.ui &&
 209        cat >expected <<\EOF &&
 210  a/b/c   bam   foo   l   * master    n     o/p   r
 211  abc     bar   j/k   m/m   master2   o/o   q
 212EOF
 213        test_cmp expected actual
 214'
 215
 216test_expect_success 'git branch --column -v should fail' '
 217        test_must_fail git branch --column -v
 218'
 219
 220test_expect_success 'git branch -v with column.ui ignored' '
 221        git config column.ui column &&
 222        COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual &&
 223        git config --unset column.ui &&
 224        cat >expected <<\EOF &&
 225  a/b/c
 226  abc
 227  bam
 228  bar
 229  foo
 230  j/k
 231  l
 232  m/m
 233* master
 234  master2
 235  n
 236  o/o
 237  o/p
 238  q
 239  r
 240EOF
 241        test_cmp expected actual
 242'
 243
 244mv .git/config .git/config-saved
 245
 246test_expect_success 'git branch -m q q2 without config should succeed' '
 247        git branch -m q q2 &&
 248        git branch -m q2 q
 249'
 250
 251mv .git/config-saved .git/config
 252
 253git config branch.s/s.dummy Hello
 254
 255test_expect_success \
 256    'git branch -m s/s s should work when s/t is deleted' \
 257       'git branch -l s/s &&
 258        test_path_is_file .git/logs/refs/heads/s/s &&
 259        git branch -l s/t &&
 260        test_path_is_file .git/logs/refs/heads/s/t &&
 261        git branch -d s/t &&
 262        git branch -m s/s s &&
 263        test_path_is_file .git/logs/refs/heads/s'
 264
 265test_expect_success 'config information was renamed, too' \
 266        "test $(git config branch.s.dummy) = Hello &&
 267         test_must_fail git config branch.s/s/dummy"
 268
 269test_expect_success 'deleting a symref' '
 270        git branch target &&
 271        git symbolic-ref refs/heads/symref refs/heads/target &&
 272        echo "Deleted branch symref (was refs/heads/target)." >expect &&
 273        git branch -d symref >actual &&
 274        test_path_is_file .git/refs/heads/target &&
 275        test_path_is_missing .git/refs/heads/symref &&
 276        test_i18ncmp expect actual
 277'
 278
 279test_expect_success 'deleting a dangling symref' '
 280        git symbolic-ref refs/heads/dangling-symref nowhere &&
 281        test_path_is_file .git/refs/heads/dangling-symref &&
 282        echo "Deleted branch dangling-symref (was nowhere)." >expect &&
 283        git branch -d dangling-symref >actual &&
 284        test_path_is_missing .git/refs/heads/dangling-symref &&
 285        test_i18ncmp expect actual
 286'
 287
 288test_expect_success 'renaming a symref is not allowed' \
 289'
 290        git symbolic-ref refs/heads/master2 refs/heads/master &&
 291        test_must_fail git branch -m master2 master3 &&
 292        git symbolic-ref refs/heads/master2 &&
 293        test_path_is_file .git/refs/heads/master &&
 294        test_path_is_missing .git/refs/heads/master3
 295'
 296
 297test_expect_success SYMLINKS \
 298    'git branch -m u v should fail when the reflog for u is a symlink' '
 299     git branch -l u &&
 300     mv .git/logs/refs/heads/u real-u &&
 301     ln -s real-u .git/logs/refs/heads/u &&
 302     test_must_fail git branch -m u v
 303'
 304
 305test_expect_success 'test tracking setup via --track' \
 306    'git config remote.local.url . &&
 307     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 308     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 309     git branch --track my1 local/master &&
 310     test $(git config branch.my1.remote) = local &&
 311     test $(git config branch.my1.merge) = refs/heads/master'
 312
 313test_expect_success 'test tracking setup (non-wildcard, matching)' \
 314    'git config remote.local.url . &&
 315     git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
 316     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 317     git branch --track my4 local/master &&
 318     test $(git config branch.my4.remote) = local &&
 319     test $(git config branch.my4.merge) = refs/heads/master'
 320
 321test_expect_success 'test tracking setup (non-wildcard, not matching)' \
 322    'git config remote.local.url . &&
 323     git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
 324     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 325     git branch --track my5 local/master &&
 326     ! test "$(git config branch.my5.remote)" = local &&
 327     ! test "$(git config branch.my5.merge)" = refs/heads/master'
 328
 329test_expect_success 'test tracking setup via config' \
 330    'git config branch.autosetupmerge true &&
 331     git config remote.local.url . &&
 332     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 333     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 334     git branch my3 local/master &&
 335     test $(git config branch.my3.remote) = local &&
 336     test $(git config branch.my3.merge) = refs/heads/master'
 337
 338test_expect_success 'test overriding tracking setup via --no-track' \
 339    'git config branch.autosetupmerge true &&
 340     git config remote.local.url . &&
 341     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 342     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 343     git branch --no-track my2 local/master &&
 344     git config branch.autosetupmerge false &&
 345     ! test "$(git config branch.my2.remote)" = local &&
 346     ! test "$(git config branch.my2.merge)" = refs/heads/master'
 347
 348test_expect_success 'no tracking without .fetch entries' \
 349    'git config branch.autosetupmerge true &&
 350     git branch my6 s &&
 351     git config branch.automsetupmerge false &&
 352     test -z "$(git config branch.my6.remote)" &&
 353     test -z "$(git config branch.my6.merge)"'
 354
 355test_expect_success 'test tracking setup via --track but deeper' \
 356    'git config remote.local.url . &&
 357     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 358     (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
 359     git branch --track my7 local/o/o &&
 360     test "$(git config branch.my7.remote)" = local &&
 361     test "$(git config branch.my7.merge)" = refs/heads/o/o'
 362
 363test_expect_success 'test deleting branch deletes branch config' \
 364    'git branch -d my7 &&
 365     test -z "$(git config branch.my7.remote)" &&
 366     test -z "$(git config branch.my7.merge)"'
 367
 368test_expect_success 'test deleting branch without config' \
 369    'git branch my7 s &&
 370     sha1=$(git rev-parse my7 | cut -c 1-7) &&
 371     echo "Deleted branch my7 (was $sha1)." >expect &&
 372     git branch -d my7 >actual 2>&1 &&
 373     test_i18ncmp expect actual'
 374
 375test_expect_success 'test --track without .fetch entries' \
 376    'git branch --track my8 &&
 377     test "$(git config branch.my8.remote)" &&
 378     test "$(git config branch.my8.merge)"'
 379
 380test_expect_success \
 381    'branch from non-branch HEAD w/autosetupmerge=always' \
 382    'git config branch.autosetupmerge always &&
 383     git branch my9 HEAD^ &&
 384     git config branch.autosetupmerge false'
 385
 386test_expect_success \
 387    'branch from non-branch HEAD w/--track causes failure' \
 388    'test_must_fail git branch --track my10 HEAD^'
 389
 390test_expect_success \
 391    'branch from tag w/--track causes failure' \
 392    'git tag foobar &&
 393     test_must_fail git branch --track my11 foobar'
 394
 395test_expect_success '--set-upstream-to fails on multiple branches' \
 396    'test_must_fail git branch --set-upstream-to master a b c'
 397
 398test_expect_success '--set-upstream-to fails on detached HEAD' \
 399    'git checkout HEAD^{} &&
 400     test_must_fail git branch --set-upstream-to master &&
 401     git checkout -'
 402
 403test_expect_success 'use --set-upstream-to modify HEAD' \
 404    'test_config branch.master.remote foo &&
 405     test_config branch.master.merge foo &&
 406     git branch my12
 407     git branch --set-upstream-to my12 &&
 408     test "$(git config branch.master.remote)" = "." &&
 409     test "$(git config branch.master.merge)" = "refs/heads/my12"'
 410
 411test_expect_success 'use --set-upstream-to modify a particular branch' \
 412    'git branch my13
 413     git branch --set-upstream-to master my13 &&
 414     test "$(git config branch.my13.remote)" = "." &&
 415     test "$(git config branch.my13.merge)" = "refs/heads/master"'
 416
 417test_expect_success '--unset-upstream should fail if given a non-existent branch' \
 418    'test_must_fail git branch --unset-upstream i-dont-exist'
 419
 420test_expect_success 'test --unset-upstream on HEAD' \
 421    'git branch my14
 422     test_config branch.master.remote foo &&
 423     test_config branch.master.merge foo &&
 424     git branch --set-upstream-to my14 &&
 425     git branch --unset-upstream &&
 426     test_must_fail git config branch.master.remote &&
 427     test_must_fail git config branch.master.merge &&
 428     # fail for a branch without upstream set
 429     test_must_fail git branch --unset-upstream
 430'
 431
 432test_expect_success '--unset-upstream should fail on multiple branches' \
 433    'test_must_fail git branch --unset-upstream a b c'
 434
 435test_expect_success '--unset-upstream should fail on detached HEAD' \
 436    'git checkout HEAD^{} &&
 437     test_must_fail git branch --unset-upstream &&
 438     git checkout -
 439'
 440
 441test_expect_success 'test --unset-upstream on a particular branch' \
 442    'git branch my15
 443     git branch --set-upstream-to master my14 &&
 444     git branch --unset-upstream my14 &&
 445     test_must_fail git config branch.my14.remote &&
 446     test_must_fail git config branch.my14.merge'
 447
 448test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' \
 449    'git update-ref refs/remotes/origin/master HEAD &&
 450     git branch --set-upstream origin/master 2>actual &&
 451     test_when_finished git update-ref -d refs/remotes/origin/master &&
 452     test_when_finished git branch -d origin/master &&
 453     cat >expected <<EOF &&
 454The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
 455
 456If you wanted to make '"'master'"' track '"'origin/master'"', do this:
 457
 458    git branch -d origin/master
 459    git branch --set-upstream-to origin/master
 460EOF
 461     test_cmp expected actual
 462'
 463
 464test_expect_success '--set-upstream with two args only shows the deprecation message' \
 465    'git branch --set-upstream master my13 2>actual &&
 466     test_when_finished git branch --unset-upstream master &&
 467     cat >expected <<EOF &&
 468The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
 469EOF
 470     test_cmp expected actual
 471'
 472
 473test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' \
 474    'git branch --set-upstream my13 2>actual &&
 475     test_when_finished git branch --unset-upstream my13 &&
 476     cat >expected <<EOF &&
 477The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
 478EOF
 479     test_cmp expected actual
 480'
 481
 482# Keep this test last, as it changes the current branch
 483cat >expect <<EOF
 484$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
 485EOF
 486test_expect_success \
 487    'git checkout -b g/h/i -l should create a branch and a log' \
 488        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
 489     git checkout -b g/h/i -l master &&
 490         test_path_is_file .git/refs/heads/g/h/i &&
 491         test_path_is_file .git/logs/refs/heads/g/h/i &&
 492         test_cmp expect .git/logs/refs/heads/g/h/i'
 493
 494test_expect_success 'checkout -b makes reflog by default' '
 495        git checkout master &&
 496        git config --unset core.logAllRefUpdates &&
 497        git checkout -b alpha &&
 498        git rev-parse --verify alpha@{0}
 499'
 500
 501test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
 502        git checkout master &&
 503        git config core.logAllRefUpdates false &&
 504        git checkout -b beta &&
 505        test_must_fail git rev-parse --verify beta@{0}
 506'
 507
 508test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
 509        git checkout master &&
 510        git checkout -lb gamma &&
 511        git config --unset core.logAllRefUpdates &&
 512        git rev-parse --verify gamma@{0}
 513'
 514
 515test_expect_success 'avoid ambiguous track' '
 516        git config branch.autosetupmerge true &&
 517        git config remote.ambi1.url lalala &&
 518        git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
 519        git config remote.ambi2.url lilili &&
 520        git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
 521        git branch all1 master &&
 522        test -z "$(git config branch.all1.merge)"
 523'
 524
 525test_expect_success 'autosetuprebase local on a tracked local branch' '
 526        git config remote.local.url . &&
 527        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 528        git config branch.autosetuprebase local &&
 529        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 530        git branch mybase &&
 531        git branch --track myr1 mybase &&
 532        test "$(git config branch.myr1.remote)" = . &&
 533        test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
 534        test "$(git config branch.myr1.rebase)" = true
 535'
 536
 537test_expect_success 'autosetuprebase always on a tracked local branch' '
 538        git config remote.local.url . &&
 539        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 540        git config branch.autosetuprebase always &&
 541        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 542        git branch mybase2 &&
 543        git branch --track myr2 mybase &&
 544        test "$(git config branch.myr2.remote)" = . &&
 545        test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
 546        test "$(git config branch.myr2.rebase)" = true
 547'
 548
 549test_expect_success 'autosetuprebase remote on a tracked local branch' '
 550        git config remote.local.url . &&
 551        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 552        git config branch.autosetuprebase remote &&
 553        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 554        git branch mybase3 &&
 555        git branch --track myr3 mybase2 &&
 556        test "$(git config branch.myr3.remote)" = . &&
 557        test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
 558        ! test "$(git config branch.myr3.rebase)" = true
 559'
 560
 561test_expect_success 'autosetuprebase never on a tracked local branch' '
 562        git config remote.local.url . &&
 563        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 564        git config branch.autosetuprebase never &&
 565        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 566        git branch mybase4 &&
 567        git branch --track myr4 mybase2 &&
 568        test "$(git config branch.myr4.remote)" = . &&
 569        test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
 570        ! test "$(git config branch.myr4.rebase)" = true
 571'
 572
 573test_expect_success 'autosetuprebase local on a tracked remote branch' '
 574        git config remote.local.url . &&
 575        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 576        git config branch.autosetuprebase local &&
 577        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 578        git branch --track myr5 local/master &&
 579        test "$(git config branch.myr5.remote)" = local &&
 580        test "$(git config branch.myr5.merge)" = refs/heads/master &&
 581        ! test "$(git config branch.myr5.rebase)" = true
 582'
 583
 584test_expect_success 'autosetuprebase never on a tracked remote branch' '
 585        git config remote.local.url . &&
 586        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 587        git config branch.autosetuprebase never &&
 588        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 589        git branch --track myr6 local/master &&
 590        test "$(git config branch.myr6.remote)" = local &&
 591        test "$(git config branch.myr6.merge)" = refs/heads/master &&
 592        ! test "$(git config branch.myr6.rebase)" = true
 593'
 594
 595test_expect_success 'autosetuprebase remote on a tracked remote branch' '
 596        git config remote.local.url . &&
 597        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 598        git config branch.autosetuprebase remote &&
 599        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 600        git branch --track myr7 local/master &&
 601        test "$(git config branch.myr7.remote)" = local &&
 602        test "$(git config branch.myr7.merge)" = refs/heads/master &&
 603        test "$(git config branch.myr7.rebase)" = true
 604'
 605
 606test_expect_success 'autosetuprebase always on a tracked remote branch' '
 607        git config remote.local.url . &&
 608        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 609        git config branch.autosetuprebase remote &&
 610        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 611        git branch --track myr8 local/master &&
 612        test "$(git config branch.myr8.remote)" = local &&
 613        test "$(git config branch.myr8.merge)" = refs/heads/master &&
 614        test "$(git config branch.myr8.rebase)" = true
 615'
 616
 617test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
 618        git config --unset branch.autosetuprebase &&
 619        git config remote.local.url . &&
 620        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 621        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 622        git branch --track myr9 local/master &&
 623        test "$(git config branch.myr9.remote)" = local &&
 624        test "$(git config branch.myr9.merge)" = refs/heads/master &&
 625        test "z$(git config branch.myr9.rebase)" = z
 626'
 627
 628test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
 629        git config remote.local.url . &&
 630        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 631        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 632        git branch mybase10 &&
 633        git branch --track myr10 mybase2 &&
 634        test "$(git config branch.myr10.remote)" = . &&
 635        test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
 636        test "z$(git config branch.myr10.rebase)" = z
 637'
 638
 639test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
 640        git config remote.local.url . &&
 641        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 642        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 643        git branch --no-track myr11 mybase2 &&
 644        test "z$(git config branch.myr11.remote)" = z &&
 645        test "z$(git config branch.myr11.merge)" = z &&
 646        test "z$(git config branch.myr11.rebase)" = z
 647'
 648
 649test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
 650        git config remote.local.url . &&
 651        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 652        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 653        git branch --no-track myr12 local/master &&
 654        test "z$(git config branch.myr12.remote)" = z &&
 655        test "z$(git config branch.myr12.merge)" = z &&
 656        test "z$(git config branch.myr12.rebase)" = z
 657'
 658
 659test_expect_success 'autosetuprebase never on an untracked local branch' '
 660        git config branch.autosetuprebase never &&
 661        git config remote.local.url . &&
 662        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 663        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 664        git branch --no-track myr13 mybase2 &&
 665        test "z$(git config branch.myr13.remote)" = z &&
 666        test "z$(git config branch.myr13.merge)" = z &&
 667        test "z$(git config branch.myr13.rebase)" = z
 668'
 669
 670test_expect_success 'autosetuprebase local on an untracked local branch' '
 671        git config branch.autosetuprebase local &&
 672        git config remote.local.url . &&
 673        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 674        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 675        git branch --no-track myr14 mybase2 &&
 676        test "z$(git config branch.myr14.remote)" = z &&
 677        test "z$(git config branch.myr14.merge)" = z &&
 678        test "z$(git config branch.myr14.rebase)" = z
 679'
 680
 681test_expect_success 'autosetuprebase remote on an untracked local branch' '
 682        git config branch.autosetuprebase remote &&
 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 myr15 mybase2 &&
 687        test "z$(git config branch.myr15.remote)" = z &&
 688        test "z$(git config branch.myr15.merge)" = z &&
 689        test "z$(git config branch.myr15.rebase)" = z
 690'
 691
 692test_expect_success 'autosetuprebase always on an untracked local branch' '
 693        git config branch.autosetuprebase always &&
 694        git config remote.local.url . &&
 695        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 696        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 697        git branch --no-track myr16 mybase2 &&
 698        test "z$(git config branch.myr16.remote)" = z &&
 699        test "z$(git config branch.myr16.merge)" = z &&
 700        test "z$(git config branch.myr16.rebase)" = z
 701'
 702
 703test_expect_success 'autosetuprebase never on an untracked remote branch' '
 704        git config branch.autosetuprebase never &&
 705        git config remote.local.url . &&
 706        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 707        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 708        git branch --no-track myr17 local/master &&
 709        test "z$(git config branch.myr17.remote)" = z &&
 710        test "z$(git config branch.myr17.merge)" = z &&
 711        test "z$(git config branch.myr17.rebase)" = z
 712'
 713
 714test_expect_success 'autosetuprebase local on an untracked remote branch' '
 715        git config branch.autosetuprebase local &&
 716        git config remote.local.url . &&
 717        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 718        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 719        git branch --no-track myr18 local/master &&
 720        test "z$(git config branch.myr18.remote)" = z &&
 721        test "z$(git config branch.myr18.merge)" = z &&
 722        test "z$(git config branch.myr18.rebase)" = z
 723'
 724
 725test_expect_success 'autosetuprebase remote on an untracked remote branch' '
 726        git config branch.autosetuprebase remote &&
 727        git config remote.local.url . &&
 728        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 729        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 730        git branch --no-track myr19 local/master &&
 731        test "z$(git config branch.myr19.remote)" = z &&
 732        test "z$(git config branch.myr19.merge)" = z &&
 733        test "z$(git config branch.myr19.rebase)" = z
 734'
 735
 736test_expect_success 'autosetuprebase always on an untracked remote branch' '
 737        git config branch.autosetuprebase always &&
 738        git config remote.local.url . &&
 739        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 740        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 741        git branch --no-track myr20 local/master &&
 742        test "z$(git config branch.myr20.remote)" = z &&
 743        test "z$(git config branch.myr20.merge)" = z &&
 744        test "z$(git config branch.myr20.rebase)" = z
 745'
 746
 747test_expect_success 'autosetuprebase always on detached HEAD' '
 748        git config branch.autosetupmerge always &&
 749        test_when_finished git checkout master &&
 750        git checkout HEAD^0 &&
 751        git branch my11 &&
 752        test -z "$(git config branch.my11.remote)" &&
 753        test -z "$(git config branch.my11.merge)"
 754'
 755
 756test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
 757        git config branch.autosetuprebase garbage &&
 758        test_must_fail git branch
 759'
 760
 761test_expect_success 'detect misconfigured autosetuprebase (no value)' '
 762        git config --unset branch.autosetuprebase &&
 763        echo "[branch] autosetuprebase" >> .git/config &&
 764        test_must_fail git branch &&
 765        git config --unset branch.autosetuprebase
 766'
 767
 768test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
 769        git checkout my9 &&
 770        git config --unset branch.my8.merge &&
 771        test_must_fail git branch -d my8
 772'
 773
 774test_expect_success 'attempt to delete a branch merged to its base' '
 775        # we are on my9 which is the initial commit; traditionally
 776        # we would not have allowed deleting my8 that is not merged
 777        # to my9, but it is set to track master that already has my8
 778        git config branch.my8.merge refs/heads/master &&
 779        git branch -d my8
 780'
 781
 782test_expect_success 'attempt to delete a branch merged to its base' '
 783        git checkout master &&
 784        echo Third >>A &&
 785        git commit -m "Third commit" A &&
 786        git branch -t my10 my9 &&
 787        git branch -f my10 HEAD^ &&
 788        # we are on master which is at the third commit, and my10
 789        # is behind us, so traditionally we would have allowed deleting
 790        # it; but my10 is set to track my9 that is further behind.
 791        test_must_fail git branch -d my10
 792'
 793
 794test_expect_success 'use set-upstream on the current branch' '
 795        git checkout master &&
 796        git --bare init myupstream.git &&
 797        git push myupstream.git master:refs/heads/frotz &&
 798        git remote add origin myupstream.git &&
 799        git fetch &&
 800        git branch --set-upstream master origin/frotz &&
 801
 802        test "z$(git config branch.master.remote)" = "zorigin" &&
 803        test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
 804
 805'
 806
 807test_expect_success 'use --edit-description' '
 808        write_script editor <<-\EOF &&
 809                echo "New contents" >"$1"
 810        EOF
 811        EDITOR=./editor git branch --edit-description &&
 812                write_script editor <<-\EOF &&
 813                git stripspace -s <"$1" >"EDITOR_OUTPUT"
 814        EOF
 815        EDITOR=./editor git branch --edit-description &&
 816        echo "New contents" >expect &&
 817        test_cmp EDITOR_OUTPUT expect
 818'
 819
 820test_expect_success 'detect typo in branch name when using --edit-description' '
 821        write_script editor <<-\EOF &&
 822                echo "New contents" >"$1"
 823        EOF
 824        (
 825                EDITOR=./editor &&
 826                export EDITOR &&
 827                test_must_fail git branch --edit-description no-such-branch
 828        )
 829'
 830
 831test_expect_success 'refuse --edit-description on unborn branch for now' '
 832        write_script editor <<-\EOF &&
 833                echo "New contents" >"$1"
 834        EOF
 835        git checkout --orphan unborn &&
 836        (
 837                EDITOR=./editor &&
 838                export EDITOR &&
 839                test_must_fail git branch --edit-description
 840        )
 841'
 842
 843test_expect_success '--merged catches invalid object names' '
 844        test_must_fail git branch --merged 0000000000000000000000000000000000000000
 845'
 846
 847test_done