t / t3200-branch.shon commit branch: optionally setup branch.*.merge from upstream local branches (9ed36cf)
   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_failure \
  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
  28test_expect_success \
  29    'git branch abc should create a branch' \
  30    'git branch abc && test -f .git/refs/heads/abc'
  31
  32test_expect_success \
  33    'git branch a/b/c should create a branch' \
  34    'git branch a/b/c && test -f .git/refs/heads/a/b/c'
  35
  36cat >expect <<EOF
  370000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000      branch: Created from master
  38EOF
  39test_expect_success \
  40    'git branch -l d/e/f should create a branch and a log' \
  41        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
  42     git branch -l d/e/f &&
  43         test -f .git/refs/heads/d/e/f &&
  44         test -f .git/logs/refs/heads/d/e/f &&
  45         diff expect .git/logs/refs/heads/d/e/f'
  46
  47test_expect_success \
  48    'git branch -d d/e/f should delete a branch and a log' \
  49        'git branch -d d/e/f &&
  50         test ! -f .git/refs/heads/d/e/f &&
  51         test ! -f .git/logs/refs/heads/d/e/f'
  52
  53test_expect_success \
  54    'git branch j/k should work after branch j has been deleted' \
  55       'git branch j &&
  56        git branch -d j &&
  57        git branch j/k'
  58
  59test_expect_success \
  60    'git branch l should work after branch l/m has been deleted' \
  61       'git branch l/m &&
  62        git branch -d l/m &&
  63        git branch l'
  64
  65test_expect_success \
  66    'git branch -m m m/m should work' \
  67       'git branch -l m &&
  68        git branch -m m m/m &&
  69        test -f .git/logs/refs/heads/m/m'
  70
  71test_expect_success \
  72    'git branch -m n/n n should work' \
  73       'git branch -l n/n &&
  74        git branch -m n/n n
  75        test -f .git/logs/refs/heads/n'
  76
  77test_expect_failure \
  78    'git branch -m o/o o should fail when o/p exists' \
  79       'git branch o/o &&
  80        git branch o/p &&
  81        git branch -m o/o o'
  82
  83test_expect_failure \
  84    'git branch -m q r/q should fail when r exists' \
  85       'git branch q &&
  86         git branch r &&
  87         git branch -m q r/q'
  88
  89mv .git/config .git/config-saved
  90
  91test_expect_success 'git branch -m q q2 without config should succeed' '
  92        git branch -m q q2 &&
  93        git branch -m q2 q
  94'
  95
  96mv .git/config-saved .git/config
  97
  98git config branch.s/s.dummy Hello
  99
 100test_expect_success \
 101    'git branch -m s/s s should work when s/t is deleted' \
 102       'git branch -l s/s &&
 103        test -f .git/logs/refs/heads/s/s &&
 104        git branch -l s/t &&
 105        test -f .git/logs/refs/heads/s/t &&
 106        git branch -d s/t &&
 107        git branch -m s/s s &&
 108        test -f .git/logs/refs/heads/s'
 109
 110test_expect_success 'config information was renamed, too' \
 111        "test $(git config branch.s.dummy) = Hello &&
 112         ! git config branch.s/s/dummy"
 113
 114test_expect_failure \
 115    'git branch -m u v should fail when the reflog for u is a symlink' \
 116    'git branch -l u &&
 117     mv .git/logs/refs/heads/u real-u &&
 118     ln -s real-u .git/logs/refs/heads/u &&
 119     git branch -m u v'
 120
 121test_expect_success 'test tracking setup via --track' \
 122    'git config remote.local.url . &&
 123     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 124     (git show-ref -q refs/remotes/local/master || git-fetch local) &&
 125     git branch --track my1 local/master &&
 126     test $(git config branch.my1.remote) = local &&
 127     test $(git config branch.my1.merge) = refs/heads/master'
 128
 129test_expect_success 'test tracking setup (non-wildcard, matching)' \
 130    'git config remote.local.url . &&
 131     git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
 132     (git show-ref -q refs/remotes/local/master || git-fetch local) &&
 133     git branch --track my4 local/master &&
 134     test $(git config branch.my4.remote) = local &&
 135     test $(git config branch.my4.merge) = refs/heads/master'
 136
 137test_expect_success 'test tracking setup (non-wildcard, not matching)' \
 138    'git config remote.local.url . &&
 139     git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
 140     (git show-ref -q refs/remotes/local/master || git-fetch local) &&
 141     git branch --track my5 local/master &&
 142     ! test "$(git config branch.my5.remote)" = local &&
 143     ! test "$(git config branch.my5.merge)" = refs/heads/master'
 144
 145test_expect_success 'test tracking setup via config' \
 146    'git config branch.autosetupmerge true &&
 147     git config remote.local.url . &&
 148     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 149     (git show-ref -q refs/remotes/local/master || git-fetch local) &&
 150     git branch my3 local/master &&
 151     test $(git config branch.my3.remote) = local &&
 152     test $(git config branch.my3.merge) = refs/heads/master'
 153
 154test_expect_success 'avoid ambiguous track' '
 155        git config branch.autosetupmerge true &&
 156        git config remote.ambi1.url = lalala &&
 157        git config remote.ambi1.fetch = refs/heads/lalala:refs/heads/master &&
 158        git config remote.ambi2.url = lilili &&
 159        git config remote.ambi2.fetch = refs/heads/lilili:refs/heads/master &&
 160        git branch all1 master &&
 161        test -z "$(git config branch.all1.merge)"
 162'
 163
 164test_expect_success 'test overriding tracking setup via --no-track' \
 165    'git config branch.autosetupmerge true &&
 166     git config remote.local.url . &&
 167     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 168     (git show-ref -q refs/remotes/local/master || git-fetch local) &&
 169     git branch --no-track my2 local/master &&
 170     git config branch.autosetupmerge false &&
 171     ! test "$(git config branch.my2.remote)" = local &&
 172     ! test "$(git config branch.my2.merge)" = refs/heads/master'
 173
 174test_expect_success 'no tracking without .fetch entries' \
 175    'git config branch.autosetupmerge true &&
 176     git branch my6 s &&
 177     git config branch.automsetupmerge false &&
 178     test -z "$(git config branch.my6.remote)" &&
 179     test -z "$(git config branch.my6.merge)"'
 180
 181test_expect_success 'test tracking setup via --track but deeper' \
 182    'git config remote.local.url . &&
 183     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 184     (git show-ref -q refs/remotes/local/o/o || git-fetch local) &&
 185     git branch --track my7 local/o/o &&
 186     test "$(git config branch.my7.remote)" = local &&
 187     test "$(git config branch.my7.merge)" = refs/heads/o/o'
 188
 189test_expect_success 'test deleting branch deletes branch config' \
 190    'git branch -d my7 &&
 191     test -z "$(git config branch.my7.remote)" &&
 192     test -z "$(git config branch.my7.merge)"'
 193
 194test_expect_success 'test deleting branch without config' \
 195    'git branch my7 s &&
 196     test "$(git branch -d my7 2>&1)" = "Deleted branch my7."'
 197
 198test_expect_success 'test --track without .fetch entries' \
 199    'git branch --track my8 &&
 200     test "$(git config branch.my8.remote)" &&
 201     test "$(git config branch.my8.merge)"'
 202
 203test_expect_success \
 204    'branch from non-branch HEAD w/autosetupmerge=always' \
 205    'git config branch.autosetupmerge always &&
 206     git branch my9 HEAD^ &&
 207     git config branch.autosetupmerge false'
 208
 209test_expect_success \
 210    'branch from non-branch HEAD w/--track causes failure' \
 211    '!(git branch --track my10 HEAD^)'
 212
 213# Keep this test last, as it changes the current branch
 214cat >expect <<EOF
 2150000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000      branch: Created from master
 216EOF
 217test_expect_success \
 218    'git checkout -b g/h/i -l should create a branch and a log' \
 219        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
 220     git-checkout -b g/h/i -l master &&
 221         test -f .git/refs/heads/g/h/i &&
 222         test -f .git/logs/refs/heads/g/h/i &&
 223         diff expect .git/logs/refs/heads/g/h/i'
 224
 225test_done