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