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