t / t3200-branch.shon commit i18n: git-clone "Cloning into" message (3781fcc)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Amos Waterland
   4#
   5
   6test_description='git branch --foo should not create bogus branch
   7
   8This test runs git branch --help and checks that the argument is properly
   9handled.  Specifically, that a bogus branch is not created.
  10'
  11. ./test-lib.sh
  12
  13test_expect_success \
  14    'prepare a trivial repository' \
  15    'echo Hello > A &&
  16     git update-index --add A &&
  17     git commit -m "Initial commit." &&
  18     echo World >> A &&
  19     git update-index --add A &&
  20     git commit -m "Second commit." &&
  21     HEAD=$(git rev-parse --verify HEAD)'
  22
  23test_expect_success \
  24    'git branch --help should not have created a bogus branch' '
  25     git branch --help </dev/null >/dev/null 2>/dev/null;
  26     ! test -f .git/refs/heads/--help
  27'
  28
  29test_expect_success 'branch -h in broken repository' '
  30        mkdir broken &&
  31        (
  32                cd broken &&
  33                git init &&
  34                >.git/refs/heads/master &&
  35                test_expect_code 129 git branch -h >usage 2>&1
  36        ) &&
  37        grep "[Uu]sage" broken/usage
  38'
  39
  40test_expect_success \
  41    'git branch abc should create a branch' \
  42    'git branch abc && test -f .git/refs/heads/abc'
  43
  44test_expect_success \
  45    'git branch a/b/c should create a branch' \
  46    'git branch a/b/c && test -f .git/refs/heads/a/b/c'
  47
  48cat >expect <<EOF
  490000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000      branch: Created from master
  50EOF
  51test_expect_success \
  52    'git branch -l d/e/f should create a branch and a log' \
  53        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
  54     git branch -l d/e/f &&
  55         test -f .git/refs/heads/d/e/f &&
  56         test -f .git/logs/refs/heads/d/e/f &&
  57         test_cmp expect .git/logs/refs/heads/d/e/f'
  58
  59test_expect_success \
  60    'git branch -d d/e/f should delete a branch and a log' \
  61        'git branch -d d/e/f &&
  62         test ! -f .git/refs/heads/d/e/f &&
  63         test ! -f .git/logs/refs/heads/d/e/f'
  64
  65test_expect_success \
  66    'git branch j/k should work after branch j has been deleted' \
  67       'git branch j &&
  68        git branch -d j &&
  69        git branch j/k'
  70
  71test_expect_success \
  72    'git branch l should work after branch l/m has been deleted' \
  73       'git branch l/m &&
  74        git branch -d l/m &&
  75        git branch l'
  76
  77test_expect_success \
  78    'git branch -m m m/m should work' \
  79       'git branch -l m &&
  80        git branch -m m m/m &&
  81        test -f .git/logs/refs/heads/m/m'
  82
  83test_expect_success \
  84    'git branch -m n/n n should work' \
  85       'git branch -l n/n &&
  86        git branch -m n/n n
  87        test -f .git/logs/refs/heads/n'
  88
  89test_expect_success 'git branch -m o/o o should fail when o/p exists' '
  90        git branch o/o &&
  91        git branch o/p &&
  92        test_must_fail git branch -m o/o o
  93'
  94
  95test_expect_success 'git branch -m q r/q should fail when r exists' '
  96        git branch q &&
  97        git branch r &&
  98        test_must_fail git branch -m q r/q
  99'
 100
 101mv .git/config .git/config-saved
 102
 103test_expect_success 'git branch -m q q2 without config should succeed' '
 104        git branch -m q q2 &&
 105        git branch -m q2 q
 106'
 107
 108mv .git/config-saved .git/config
 109
 110git config branch.s/s.dummy Hello
 111
 112test_expect_success \
 113    'git branch -m s/s s should work when s/t is deleted' \
 114       'git branch -l s/s &&
 115        test -f .git/logs/refs/heads/s/s &&
 116        git branch -l s/t &&
 117        test -f .git/logs/refs/heads/s/t &&
 118        git branch -d s/t &&
 119        git branch -m s/s s &&
 120        test -f .git/logs/refs/heads/s'
 121
 122test_expect_success 'config information was renamed, too' \
 123        "test $(git config branch.s.dummy) = Hello &&
 124         test_must_fail git config branch.s/s/dummy"
 125
 126test_expect_success 'renaming a symref is not allowed' \
 127'
 128        git symbolic-ref refs/heads/master2 refs/heads/master &&
 129        test_must_fail git branch -m master2 master3 &&
 130        git symbolic-ref refs/heads/master2 &&
 131        test -f .git/refs/heads/master &&
 132        ! test -f .git/refs/heads/master3
 133'
 134
 135test_expect_success SYMLINKS \
 136    'git branch -m u v should fail when the reflog for u is a symlink' '
 137     git branch -l u &&
 138     mv .git/logs/refs/heads/u real-u &&
 139     ln -s real-u .git/logs/refs/heads/u &&
 140     test_must_fail git branch -m u v
 141'
 142
 143test_expect_success 'test tracking setup via --track' \
 144    'git config remote.local.url . &&
 145     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 146     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 147     git branch --track my1 local/master &&
 148     test $(git config branch.my1.remote) = local &&
 149     test $(git config branch.my1.merge) = refs/heads/master'
 150
 151test_expect_success 'test tracking setup (non-wildcard, matching)' \
 152    'git config remote.local.url . &&
 153     git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
 154     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 155     git branch --track my4 local/master &&
 156     test $(git config branch.my4.remote) = local &&
 157     test $(git config branch.my4.merge) = refs/heads/master'
 158
 159test_expect_success 'test tracking setup (non-wildcard, not matching)' \
 160    'git config remote.local.url . &&
 161     git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
 162     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 163     git branch --track my5 local/master &&
 164     ! test "$(git config branch.my5.remote)" = local &&
 165     ! test "$(git config branch.my5.merge)" = refs/heads/master'
 166
 167test_expect_success 'test tracking setup via config' \
 168    'git config branch.autosetupmerge true &&
 169     git config remote.local.url . &&
 170     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 171     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 172     git branch my3 local/master &&
 173     test $(git config branch.my3.remote) = local &&
 174     test $(git config branch.my3.merge) = refs/heads/master'
 175
 176test_expect_success 'test overriding tracking setup via --no-track' \
 177    'git config branch.autosetupmerge true &&
 178     git config remote.local.url . &&
 179     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 180     (git show-ref -q refs/remotes/local/master || git fetch local) &&
 181     git branch --no-track my2 local/master &&
 182     git config branch.autosetupmerge false &&
 183     ! test "$(git config branch.my2.remote)" = local &&
 184     ! test "$(git config branch.my2.merge)" = refs/heads/master'
 185
 186test_expect_success 'no tracking without .fetch entries' \
 187    'git config branch.autosetupmerge true &&
 188     git branch my6 s &&
 189     git config branch.automsetupmerge false &&
 190     test -z "$(git config branch.my6.remote)" &&
 191     test -z "$(git config branch.my6.merge)"'
 192
 193test_expect_success 'test tracking setup via --track but deeper' \
 194    'git config remote.local.url . &&
 195     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 196     (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
 197     git branch --track my7 local/o/o &&
 198     test "$(git config branch.my7.remote)" = local &&
 199     test "$(git config branch.my7.merge)" = refs/heads/o/o'
 200
 201test_expect_success 'test deleting branch deletes branch config' \
 202    'git branch -d my7 &&
 203     test -z "$(git config branch.my7.remote)" &&
 204     test -z "$(git config branch.my7.merge)"'
 205
 206test_expect_success 'test deleting branch without config' \
 207    'git branch my7 s &&
 208     sha1=$(git rev-parse my7 | cut -c 1-7) &&
 209     test "$(git branch -d my7 2>&1)" = "Deleted branch my7 (was $sha1)."'
 210
 211test_expect_success 'test --track without .fetch entries' \
 212    'git branch --track my8 &&
 213     test "$(git config branch.my8.remote)" &&
 214     test "$(git config branch.my8.merge)"'
 215
 216test_expect_success \
 217    'branch from non-branch HEAD w/autosetupmerge=always' \
 218    'git config branch.autosetupmerge always &&
 219     git branch my9 HEAD^ &&
 220     git config branch.autosetupmerge false'
 221
 222test_expect_success \
 223    'branch from non-branch HEAD w/--track causes failure' \
 224    'test_must_fail git branch --track my10 HEAD^'
 225
 226# Keep this test last, as it changes the current branch
 227cat >expect <<EOF
 2280000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000      branch: Created from master
 229EOF
 230test_expect_success \
 231    'git checkout -b g/h/i -l should create a branch and a log' \
 232        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
 233     git checkout -b g/h/i -l master &&
 234         test -f .git/refs/heads/g/h/i &&
 235         test -f .git/logs/refs/heads/g/h/i &&
 236         test_cmp expect .git/logs/refs/heads/g/h/i'
 237
 238test_expect_success 'checkout -b makes reflog by default' '
 239        git checkout master &&
 240        git config --unset core.logAllRefUpdates &&
 241        git checkout -b alpha &&
 242        git rev-parse --verify alpha@{0}
 243'
 244
 245test_expect_success 'checkout -b does not make reflog when core.logAllRefUpdates = false' '
 246        git checkout master &&
 247        git config core.logAllRefUpdates false &&
 248        git checkout -b beta &&
 249        test_must_fail git rev-parse --verify beta@{0}
 250'
 251
 252test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates = false' '
 253        git checkout master &&
 254        git checkout -lb gamma &&
 255        git config --unset core.logAllRefUpdates &&
 256        git rev-parse --verify gamma@{0}
 257'
 258
 259test_expect_success 'avoid ambiguous track' '
 260        git config branch.autosetupmerge true &&
 261        git config remote.ambi1.url lalala &&
 262        git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
 263        git config remote.ambi2.url lilili &&
 264        git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
 265        git branch all1 master &&
 266        test -z "$(git config branch.all1.merge)"
 267'
 268
 269test_expect_success 'autosetuprebase local on a tracked local branch' '
 270        git config remote.local.url . &&
 271        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 272        git config branch.autosetuprebase local &&
 273        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 274        git branch mybase &&
 275        git branch --track myr1 mybase &&
 276        test "$(git config branch.myr1.remote)" = . &&
 277        test "$(git config branch.myr1.merge)" = refs/heads/mybase &&
 278        test "$(git config branch.myr1.rebase)" = true
 279'
 280
 281test_expect_success 'autosetuprebase always on a tracked local branch' '
 282        git config remote.local.url . &&
 283        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 284        git config branch.autosetuprebase always &&
 285        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 286        git branch mybase2 &&
 287        git branch --track myr2 mybase &&
 288        test "$(git config branch.myr2.remote)" = . &&
 289        test "$(git config branch.myr2.merge)" = refs/heads/mybase &&
 290        test "$(git config branch.myr2.rebase)" = true
 291'
 292
 293test_expect_success 'autosetuprebase remote on a tracked local branch' '
 294        git config remote.local.url . &&
 295        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 296        git config branch.autosetuprebase remote &&
 297        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 298        git branch mybase3 &&
 299        git branch --track myr3 mybase2 &&
 300        test "$(git config branch.myr3.remote)" = . &&
 301        test "$(git config branch.myr3.merge)" = refs/heads/mybase2 &&
 302        ! test "$(git config branch.myr3.rebase)" = true
 303'
 304
 305test_expect_success 'autosetuprebase never on a tracked local branch' '
 306        git config remote.local.url . &&
 307        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 308        git config branch.autosetuprebase never &&
 309        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 310        git branch mybase4 &&
 311        git branch --track myr4 mybase2 &&
 312        test "$(git config branch.myr4.remote)" = . &&
 313        test "$(git config branch.myr4.merge)" = refs/heads/mybase2 &&
 314        ! test "$(git config branch.myr4.rebase)" = true
 315'
 316
 317test_expect_success 'autosetuprebase local on a tracked remote branch' '
 318        git config remote.local.url . &&
 319        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 320        git config branch.autosetuprebase local &&
 321        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 322        git branch --track myr5 local/master &&
 323        test "$(git config branch.myr5.remote)" = local &&
 324        test "$(git config branch.myr5.merge)" = refs/heads/master &&
 325        ! test "$(git config branch.myr5.rebase)" = true
 326'
 327
 328test_expect_success 'autosetuprebase never on a tracked remote branch' '
 329        git config remote.local.url . &&
 330        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 331        git config branch.autosetuprebase never &&
 332        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 333        git branch --track myr6 local/master &&
 334        test "$(git config branch.myr6.remote)" = local &&
 335        test "$(git config branch.myr6.merge)" = refs/heads/master &&
 336        ! test "$(git config branch.myr6.rebase)" = true
 337'
 338
 339test_expect_success 'autosetuprebase remote on a tracked remote branch' '
 340        git config remote.local.url . &&
 341        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 342        git config branch.autosetuprebase remote &&
 343        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 344        git branch --track myr7 local/master &&
 345        test "$(git config branch.myr7.remote)" = local &&
 346        test "$(git config branch.myr7.merge)" = refs/heads/master &&
 347        test "$(git config branch.myr7.rebase)" = true
 348'
 349
 350test_expect_success 'autosetuprebase always on a tracked remote branch' '
 351        git config remote.local.url . &&
 352        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 353        git config branch.autosetuprebase remote &&
 354        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 355        git branch --track myr8 local/master &&
 356        test "$(git config branch.myr8.remote)" = local &&
 357        test "$(git config branch.myr8.merge)" = refs/heads/master &&
 358        test "$(git config branch.myr8.rebase)" = true
 359'
 360
 361test_expect_success 'autosetuprebase unconfigured on a tracked remote branch' '
 362        git config --unset branch.autosetuprebase &&
 363        git config remote.local.url . &&
 364        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 365        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 366        git branch --track myr9 local/master &&
 367        test "$(git config branch.myr9.remote)" = local &&
 368        test "$(git config branch.myr9.merge)" = refs/heads/master &&
 369        test "z$(git config branch.myr9.rebase)" = z
 370'
 371
 372test_expect_success 'autosetuprebase unconfigured on a tracked local branch' '
 373        git config remote.local.url . &&
 374        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 375        (git show-ref -q refs/remotes/local/o || git fetch local) &&
 376        git branch mybase10 &&
 377        git branch --track myr10 mybase2 &&
 378        test "$(git config branch.myr10.remote)" = . &&
 379        test "$(git config branch.myr10.merge)" = refs/heads/mybase2 &&
 380        test "z$(git config branch.myr10.rebase)" = z
 381'
 382
 383test_expect_success 'autosetuprebase unconfigured on untracked local branch' '
 384        git config remote.local.url . &&
 385        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 386        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 387        git branch --no-track myr11 mybase2 &&
 388        test "z$(git config branch.myr11.remote)" = z &&
 389        test "z$(git config branch.myr11.merge)" = z &&
 390        test "z$(git config branch.myr11.rebase)" = z
 391'
 392
 393test_expect_success 'autosetuprebase unconfigured on untracked remote branch' '
 394        git config remote.local.url . &&
 395        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 396        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 397        git branch --no-track myr12 local/master &&
 398        test "z$(git config branch.myr12.remote)" = z &&
 399        test "z$(git config branch.myr12.merge)" = z &&
 400        test "z$(git config branch.myr12.rebase)" = z
 401'
 402
 403test_expect_success 'autosetuprebase never on an untracked local branch' '
 404        git config branch.autosetuprebase never &&
 405        git config remote.local.url . &&
 406        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 407        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 408        git branch --no-track myr13 mybase2 &&
 409        test "z$(git config branch.myr13.remote)" = z &&
 410        test "z$(git config branch.myr13.merge)" = z &&
 411        test "z$(git config branch.myr13.rebase)" = z
 412'
 413
 414test_expect_success 'autosetuprebase local on an untracked local branch' '
 415        git config branch.autosetuprebase local &&
 416        git config remote.local.url . &&
 417        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 418        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 419        git branch --no-track myr14 mybase2 &&
 420        test "z$(git config branch.myr14.remote)" = z &&
 421        test "z$(git config branch.myr14.merge)" = z &&
 422        test "z$(git config branch.myr14.rebase)" = z
 423'
 424
 425test_expect_success 'autosetuprebase remote on an untracked local branch' '
 426        git config branch.autosetuprebase remote &&
 427        git config remote.local.url . &&
 428        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 429        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 430        git branch --no-track myr15 mybase2 &&
 431        test "z$(git config branch.myr15.remote)" = z &&
 432        test "z$(git config branch.myr15.merge)" = z &&
 433        test "z$(git config branch.myr15.rebase)" = z
 434'
 435
 436test_expect_success 'autosetuprebase always on an untracked local branch' '
 437        git config branch.autosetuprebase always &&
 438        git config remote.local.url . &&
 439        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 440        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 441        git branch --no-track myr16 mybase2 &&
 442        test "z$(git config branch.myr16.remote)" = z &&
 443        test "z$(git config branch.myr16.merge)" = z &&
 444        test "z$(git config branch.myr16.rebase)" = z
 445'
 446
 447test_expect_success 'autosetuprebase never on an untracked remote branch' '
 448        git config branch.autosetuprebase never &&
 449        git config remote.local.url . &&
 450        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 451        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 452        git branch --no-track myr17 local/master &&
 453        test "z$(git config branch.myr17.remote)" = z &&
 454        test "z$(git config branch.myr17.merge)" = z &&
 455        test "z$(git config branch.myr17.rebase)" = z
 456'
 457
 458test_expect_success 'autosetuprebase local on an untracked remote branch' '
 459        git config branch.autosetuprebase local &&
 460        git config remote.local.url . &&
 461        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 462        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 463        git branch --no-track myr18 local/master &&
 464        test "z$(git config branch.myr18.remote)" = z &&
 465        test "z$(git config branch.myr18.merge)" = z &&
 466        test "z$(git config branch.myr18.rebase)" = z
 467'
 468
 469test_expect_success 'autosetuprebase remote on an untracked remote branch' '
 470        git config branch.autosetuprebase remote &&
 471        git config remote.local.url . &&
 472        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 473        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 474        git branch --no-track myr19 local/master &&
 475        test "z$(git config branch.myr19.remote)" = z &&
 476        test "z$(git config branch.myr19.merge)" = z &&
 477        test "z$(git config branch.myr19.rebase)" = z
 478'
 479
 480test_expect_success 'autosetuprebase always on an untracked remote branch' '
 481        git config branch.autosetuprebase always &&
 482        git config remote.local.url . &&
 483        git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 484        (git show-ref -q refs/remotes/local/master || git fetch local) &&
 485        git branch --no-track myr20 local/master &&
 486        test "z$(git config branch.myr20.remote)" = z &&
 487        test "z$(git config branch.myr20.merge)" = z &&
 488        test "z$(git config branch.myr20.rebase)" = z
 489'
 490
 491test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
 492        git config branch.autosetuprebase garbage &&
 493        test_must_fail git branch
 494'
 495
 496test_expect_success 'detect misconfigured autosetuprebase (no value)' '
 497        git config --unset branch.autosetuprebase &&
 498        echo "[branch] autosetuprebase" >> .git/config &&
 499        test_must_fail git branch &&
 500        git config --unset branch.autosetuprebase
 501'
 502
 503test_expect_success 'attempt to delete a branch without base and unmerged to HEAD' '
 504        git checkout my9 &&
 505        git config --unset branch.my8.merge &&
 506        test_must_fail git branch -d my8
 507'
 508
 509test_expect_success 'attempt to delete a branch merged to its base' '
 510        # we are on my9 which is the initial commit; traditionally
 511        # we would not have allowed deleting my8 that is not merged
 512        # to my9, but it is set to track master that already has my8
 513        git config branch.my8.merge refs/heads/master &&
 514        git branch -d my8
 515'
 516
 517test_expect_success 'attempt to delete a branch merged to its base' '
 518        git checkout master &&
 519        echo Third >>A &&
 520        git commit -m "Third commit" A &&
 521        git branch -t my10 my9 &&
 522        git branch -f my10 HEAD^ &&
 523        # we are on master which is at the third commit, and my10
 524        # is behind us, so traditionally we would have allowed deleting
 525        # it; but my10 is set to track my9 that is further behind.
 526        test_must_fail git branch -d my10
 527'
 528
 529test_done