t / t3200-branch.shon commit attr: "binary" attribute should choose built-in "binary" merge driver (155a4b7)
   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
 163mv .git/config .git/config-saved
 164
 165test_expect_success 'git branch -m q q2 without config should succeed' '
 166        git branch -m q q2 &&
 167        git branch -m q2 q
 168'
 169
 170mv .git/config-saved .git/config
 171
 172git config branch.s/s.dummy Hello
 173
 174test_expect_success \
 175    'git branch -m s/s s should work when s/t is deleted' \
 176       'git branch -l s/s &&
 177        test_path_is_file .git/logs/refs/heads/s/s &&
 178        git branch -l s/t &&
 179        test_path_is_file .git/logs/refs/heads/s/t &&
 180        git branch -d s/t &&
 181        git branch -m s/s s &&
 182        test_path_is_file .git/logs/refs/heads/s'
 183
 184test_expect_success 'config information was renamed, too' \
 185        "test $(git config branch.s.dummy) = Hello &&
 186         test_must_fail git config branch.s/s/dummy"
 187
 188test_expect_success 'renaming a symref is not allowed' \
 189'
 190        git symbolic-ref refs/heads/master2 refs/heads/master &&
 191        test_must_fail git branch -m master2 master3 &&
 192        git symbolic-ref refs/heads/master2 &&
 193        test_path_is_file .git/refs/heads/master &&
 194        test_path_is_missing .git/refs/heads/master3
 195'
 196
 197test_expect_success SYMLINKS \
 198    'git branch -m u v should fail when the reflog for u is a symlink' '
 199     git branch -l u &&
 200     mv .git/logs/refs/heads/u real-u &&
 201     ln -s real-u .git/logs/refs/heads/u &&
 202     test_must_fail git branch -m u v
 203'
 204
 205test_expect_success 'test tracking setup via --track' \
 206    'git config remote.local.url . &&
 207     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 208     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 209     git branch --track my1 local/master &&
 210     test $(git config branch.my1.remote) = local &&
 211     test $(git config branch.my1.merge) = refs/heads/master'
 212
 213test_expect_success 'test tracking setup (non-wildcard, matching)' \
 214    'git config remote.local.url . &&
 215     git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
 216     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 217     git branch --track my4 local/master &&
 218     test $(git config branch.my4.remote) = local &&
 219     test $(git config branch.my4.merge) = refs/heads/master'
 220
 221test_expect_success 'test tracking setup (non-wildcard, not matching)' \
 222    'git config remote.local.url . &&
 223     git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
 224     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 225     git branch --track my5 local/master &&
 226     ! test "$(git config branch.my5.remote)" = local &&
 227     ! test "$(git config branch.my5.merge)" = refs/heads/master'
 228
 229test_expect_success 'test tracking setup via config' \
 230    'git config branch.autosetupmerge true &&
 231     git config remote.local.url . &&
 232     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 233     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 234     git branch my3 local/master &&
 235     test $(git config branch.my3.remote) = local &&
 236     test $(git config branch.my3.merge) = refs/heads/master'
 237
 238test_expect_success 'test overriding tracking setup via --no-track' \
 239    'git config branch.autosetupmerge true &&
 240     git config remote.local.url . &&
 241     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 242     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 243     git branch --no-track my2 local/master &&
 244     git config branch.autosetupmerge false &&
 245     ! test "$(git config branch.my2.remote)" = local &&
 246     ! test "$(git config branch.my2.merge)" = refs/heads/master'
 247
 248test_expect_success 'no tracking without .fetch entries' \
 249    'git config branch.autosetupmerge true &&
 250     git branch my6 s &&
 251     git config branch.automsetupmerge false &&
 252     test -z "$(git config branch.my6.remote)" &&
 253     test -z "$(git config branch.my6.merge)"'
 254
 255test_expect_success 'test tracking setup via --track but deeper' \
 256    'git config remote.local.url . &&
 257     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 258     (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
 259     git branch --track my7 local/o/o &&
 260     test "$(git config branch.my7.remote)" = local &&
 261     test "$(git config branch.my7.merge)" = refs/heads/o/o'
 262
 263test_expect_success 'test deleting branch deletes branch config' \
 264    'git branch -d my7 &&
 265     test -z "$(git config branch.my7.remote)" &&
 266     test -z "$(git config branch.my7.merge)"'
 267
 268test_expect_success 'test deleting branch without config' \
 269    'git branch my7 s &&
 270     sha1=$(git rev-parse my7 | cut -c 1-7) &&
 271     echo "Deleted branch my7 (was $sha1)." >expect &&
 272     git branch -d my7 >actual 2>&1 &&
 273     test_i18ncmp expect actual'
 274
 275test_expect_success 'test --track without .fetch entries' \
 276    'git branch --track my8 &&
 277     test "$(git config branch.my8.remote)" &&
 278     test "$(git config branch.my8.merge)"'
 279
 280test_expect_success \
 281    'branch from non-branch HEAD w/autosetupmerge=always' \
 282    'git config branch.autosetupmerge always &&
 283     git branch my9 HEAD^ &&
 284     git config branch.autosetupmerge false'
 285
 286test_expect_success \
 287    'branch from non-branch HEAD w/--track causes failure' \
 288    'test_must_fail git branch --track my10 HEAD^'
 289
 290test_expect_success \
 291    'branch from tag w/--track causes failure' \
 292    'git tag foobar &&
 293     test_must_fail git branch --track my11 foobar'
 294
 295# Keep this test last, as it changes the current branch
 296cat >expect <<EOF
 297$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
 298EOF
 299test_expect_success \
 300    'git checkout -b g/h/i -l should create a branch and a log' \
 301        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
 302     git checkout -b g/h/i -l master &&
 303         test_path_is_file .git/refs/heads/g/h/i &&
 304         test_path_is_file .git/logs/refs/heads/g/h/i &&
 305         test_cmp expect .git/logs/refs/heads/g/h/i'
 306
 307test_expect_success 'checkout -b makes reflog by default' '
 308        git checkout master &&
 309        git config --unset core.logAllRefUpdates &&
 310        git checkout -b alpha &&
 311        git rev-parse --verify alpha@{0}
 312'
 313
 314test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
 315        git checkout master &&
 316        git config core.logAllRefUpdates false &&
 317        git checkout -b beta &&
 318        test_must_fail git rev-parse --verify beta@{0}
 319'
 320
 321test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
 322        git checkout master &&
 323        git checkout -lb gamma &&
 324        git config --unset core.logAllRefUpdates &&
 325        git rev-parse --verify gamma@{0}
 326'
 327
 328test_expect_success 'avoid ambiguous track' '
 329        git config branch.autosetupmerge true &&
 330        git config remote.ambi1.url lalala &&
 331        git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
 332        git config remote.ambi2.url lilili &&
 333        git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
 334        git branch all1 master &&
 335        test -z "$(git config branch.all1.merge)"
 336'
 337
 338test_expect_success 'autosetuprebase local on a tracked local branch' '
 339        git config remote.local.url . &&
 340        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 341        git config branch.autosetuprebase local &&
 342        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 343        git branch mybase &&
 344        git branch --track myr1 mybase &&
 345        test "$(git config branch.myr1.remote)" = . &&
 346        test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
 347        test "$(git config branch.myr1.rebase)" = true
 348'
 349
 350test_expect_success 'autosetuprebase always on a tracked local branch' '
 351        git config remote.local.url . &&
 352        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 353        git config branch.autosetuprebase always &&
 354        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 355        git branch mybase2 &&
 356        git branch --track myr2 mybase &&
 357        test "$(git config branch.myr2.remote)" = . &&
 358        test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
 359        test "$(git config branch.myr2.rebase)" = true
 360'
 361
 362test_expect_success 'autosetuprebase remote on a tracked local branch' '
 363        git config remote.local.url . &&
 364        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 365        git config branch.autosetuprebase remote &&
 366        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 367        git branch mybase3 &&
 368        git branch --track myr3 mybase2 &&
 369        test "$(git config branch.myr3.remote)" = . &&
 370        test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
 371        ! test "$(git config branch.myr3.rebase)" = true
 372'
 373
 374test_expect_success 'autosetuprebase never on a tracked local branch' '
 375        git config remote.local.url . &&
 376        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 377        git config branch.autosetuprebase never &&
 378        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 379        git branch mybase4 &&
 380        git branch --track myr4 mybase2 &&
 381        test "$(git config branch.myr4.remote)" = . &&
 382        test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
 383        ! test "$(git config branch.myr4.rebase)" = true
 384'
 385
 386test_expect_success 'autosetuprebase local on a tracked remote branch' '
 387        git config remote.local.url . &&
 388        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 389        git config branch.autosetuprebase local &&
 390        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 391        git branch --track myr5 local/master &&
 392        test "$(git config branch.myr5.remote)" = local &&
 393        test "$(git config branch.myr5.merge)" = refs/heads/master &&
 394        ! test "$(git config branch.myr5.rebase)" = true
 395'
 396
 397test_expect_success 'autosetuprebase never on a tracked remote branch' '
 398        git config remote.local.url . &&
 399        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 400        git config branch.autosetuprebase never &&
 401        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 402        git branch --track myr6 local/master &&
 403        test "$(git config branch.myr6.remote)" = local &&
 404        test "$(git config branch.myr6.merge)" = refs/heads/master &&
 405        ! test "$(git config branch.myr6.rebase)" = true
 406'
 407
 408test_expect_success 'autosetuprebase remote on a tracked remote branch' '
 409        git config remote.local.url . &&
 410        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 411        git config branch.autosetuprebase remote &&
 412        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 413        git branch --track myr7 local/master &&
 414        test "$(git config branch.myr7.remote)" = local &&
 415        test "$(git config branch.myr7.merge)" = refs/heads/master &&
 416        test "$(git config branch.myr7.rebase)" = true
 417'
 418
 419test_expect_success 'autosetuprebase always on a tracked remote branch' '
 420        git config remote.local.url . &&
 421        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 422        git config branch.autosetuprebase remote &&
 423        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 424        git branch --track myr8 local/master &&
 425        test "$(git config branch.myr8.remote)" = local &&
 426        test "$(git config branch.myr8.merge)" = refs/heads/master &&
 427        test "$(git config branch.myr8.rebase)" = true
 428'
 429
 430test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
 431        git config --unset branch.autosetuprebase &&
 432        git config remote.local.url . &&
 433        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 434        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 435        git branch --track myr9 local/master &&
 436        test "$(git config branch.myr9.remote)" = local &&
 437        test "$(git config branch.myr9.merge)" = refs/heads/master &&
 438        test "z$(git config branch.myr9.rebase)" = z
 439'
 440
 441test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
 442        git config remote.local.url . &&
 443        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 444        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 445        git branch mybase10 &&
 446        git branch --track myr10 mybase2 &&
 447        test "$(git config branch.myr10.remote)" = . &&
 448        test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
 449        test "z$(git config branch.myr10.rebase)" = z
 450'
 451
 452test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
 453        git config remote.local.url . &&
 454        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 455        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 456        git branch --no-track myr11 mybase2 &&
 457        test "z$(git config branch.myr11.remote)" = z &&
 458        test "z$(git config branch.myr11.merge)" = z &&
 459        test "z$(git config branch.myr11.rebase)" = z
 460'
 461
 462test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
 463        git config remote.local.url . &&
 464        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 465        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 466        git branch --no-track myr12 local/master &&
 467        test "z$(git config branch.myr12.remote)" = z &&
 468        test "z$(git config branch.myr12.merge)" = z &&
 469        test "z$(git config branch.myr12.rebase)" = z
 470'
 471
 472test_expect_success 'autosetuprebase never on an untracked local branch' '
 473        git config branch.autosetuprebase never &&
 474        git config remote.local.url . &&
 475        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 476        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 477        git branch --no-track myr13 mybase2 &&
 478        test "z$(git config branch.myr13.remote)" = z &&
 479        test "z$(git config branch.myr13.merge)" = z &&
 480        test "z$(git config branch.myr13.rebase)" = z
 481'
 482
 483test_expect_success 'autosetuprebase local on an untracked local branch' '
 484        git config branch.autosetuprebase local &&
 485        git config remote.local.url . &&
 486        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 487        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 488        git branch --no-track myr14 mybase2 &&
 489        test "z$(git config branch.myr14.remote)" = z &&
 490        test "z$(git config branch.myr14.merge)" = z &&
 491        test "z$(git config branch.myr14.rebase)" = z
 492'
 493
 494test_expect_success 'autosetuprebase remote on an untracked local branch' '
 495        git config branch.autosetuprebase remote &&
 496        git config remote.local.url . &&
 497        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 498        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 499        git branch --no-track myr15 mybase2 &&
 500        test "z$(git config branch.myr15.remote)" = z &&
 501        test "z$(git config branch.myr15.merge)" = z &&
 502        test "z$(git config branch.myr15.rebase)" = z
 503'
 504
 505test_expect_success 'autosetuprebase always on an untracked local branch' '
 506        git config branch.autosetuprebase always &&
 507        git config remote.local.url . &&
 508        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 509        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 510        git branch --no-track myr16 mybase2 &&
 511        test "z$(git config branch.myr16.remote)" = z &&
 512        test "z$(git config branch.myr16.merge)" = z &&
 513        test "z$(git config branch.myr16.rebase)" = z
 514'
 515
 516test_expect_success 'autosetuprebase never on an untracked remote branch' '
 517        git config branch.autosetuprebase never &&
 518        git config remote.local.url . &&
 519        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 520        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 521        git branch --no-track myr17 local/master &&
 522        test "z$(git config branch.myr17.remote)" = z &&
 523        test "z$(git config branch.myr17.merge)" = z &&
 524        test "z$(git config branch.myr17.rebase)" = z
 525'
 526
 527test_expect_success 'autosetuprebase local on an untracked remote branch' '
 528        git config branch.autosetuprebase local &&
 529        git config remote.local.url . &&
 530        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 531        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 532        git branch --no-track myr18 local/master &&
 533        test "z$(git config branch.myr18.remote)" = z &&
 534        test "z$(git config branch.myr18.merge)" = z &&
 535        test "z$(git config branch.myr18.rebase)" = z
 536'
 537
 538test_expect_success 'autosetuprebase remote on an untracked remote branch' '
 539        git config branch.autosetuprebase remote &&
 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 myr19 local/master &&
 544        test "z$(git config branch.myr19.remote)" = z &&
 545        test "z$(git config branch.myr19.merge)" = z &&
 546        test "z$(git config branch.myr19.rebase)" = z
 547'
 548
 549test_expect_success 'autosetuprebase always on an untracked remote branch' '
 550        git config branch.autosetuprebase always &&
 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 myr20 local/master &&
 555        test "z$(git config branch.myr20.remote)" = z &&
 556        test "z$(git config branch.myr20.merge)" = z &&
 557        test "z$(git config branch.myr20.rebase)" = z
 558'
 559
 560test_expect_success 'autosetuprebase always on detached HEAD' '
 561        git config branch.autosetupmerge always &&
 562        test_when_finished git checkout master &&
 563        git checkout HEAD^0 &&
 564        git branch my11 &&
 565        test -z "$(git config branch.my11.remote)" &&
 566        test -z "$(git config branch.my11.merge)"
 567'
 568
 569test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
 570        git config branch.autosetuprebase garbage &&
 571        test_must_fail git branch
 572'
 573
 574test_expect_success 'detect misconfigured autosetuprebase (no value)' '
 575        git config --unset branch.autosetuprebase &&
 576        echo "[branch] autosetuprebase" >> .git/config &&
 577        test_must_fail git branch &&
 578        git config --unset branch.autosetuprebase
 579'
 580
 581test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
 582        git checkout my9 &&
 583        git config --unset branch.my8.merge &&
 584        test_must_fail git branch -d my8
 585'
 586
 587test_expect_success 'attempt to delete a branch merged to its base' '
 588        # we are on my9 which is the initial commit; traditionally
 589        # we would not have allowed deleting my8 that is not merged
 590        # to my9, but it is set to track master that already has my8
 591        git config branch.my8.merge refs/heads/master &&
 592        git branch -d my8
 593'
 594
 595test_expect_success 'attempt to delete a branch merged to its base' '
 596        git checkout master &&
 597        echo Third >>A &&
 598        git commit -m "Third commit" A &&
 599        git branch -t my10 my9 &&
 600        git branch -f my10 HEAD^ &&
 601        # we are on master which is at the third commit, and my10
 602        # is behind us, so traditionally we would have allowed deleting
 603        # it; but my10 is set to track my9 that is further behind.
 604        test_must_fail git branch -d my10
 605'
 606
 607test_expect_success 'use set-upstream on the current branch' '
 608        git checkout master &&
 609        git --bare init myupstream.git &&
 610        git push myupstream.git master:refs/heads/frotz &&
 611        git remote add origin myupstream.git &&
 612        git fetch &&
 613        git branch --set-upstream master origin/frotz &&
 614
 615        test "z$(git config branch.master.remote)" = "zorigin" &&
 616        test "z$(git config branch.master.merge)" = "zrefs/heads/frotz"
 617
 618'
 619
 620test_expect_success 'use --edit-description' '
 621        write_script editor <<-\EOF &&
 622                echo "New contents" >"$1"
 623        EOF
 624        EDITOR=./editor git branch --edit-description &&
 625                write_script editor <<-\EOF &&
 626                git stripspace -s <"$1" >"EDITOR_OUTPUT"
 627        EOF
 628        EDITOR=./editor git branch --edit-description &&
 629        echo "New contents" >expect &&
 630        test_cmp EDITOR_OUTPUT expect
 631'
 632
 633test_expect_success 'detect typo in branch name when using --edit-description' '
 634        write_script editor <<-\EOF &&
 635                echo "New contents" >"$1"
 636        EOF
 637        (
 638                EDITOR=./editor &&
 639                export EDITOR &&
 640                test_must_fail git branch --edit-description no-such-branch
 641        )
 642'
 643
 644test_expect_success 'refuse --edit-description on unborn branch for now' '
 645        write_script editor <<-\EOF &&
 646                echo "New contents" >"$1"
 647        EOF
 648        git checkout --orphan unborn &&
 649        (
 650                EDITOR=./editor &&
 651                export EDITOR &&
 652                test_must_fail git branch --edit-description
 653        )
 654'
 655
 656test_expect_success '--merged catches invalid object names' '
 657        test_must_fail git branch --merged 0000000000000000000000000000000000000000
 658'
 659
 660test_done