t / t3200-branch.shon commit Merge branch 'maint' (aa576e6)
   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 an 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_failure \
  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
  25test_expect_success \
  26    'git branch abc should create a branch' \
  27    'git-branch abc && test -f .git/refs/heads/abc'
  28
  29test_expect_success \
  30    'git branch a/b/c should create a branch' \
  31    'git-branch a/b/c && test -f .git/refs/heads/a/b/c'
  32
  33cat >expect <<EOF
  340000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000      branch: Created from master
  35EOF
  36test_expect_success \
  37    'git branch -l d/e/f should create a branch and a log' \
  38        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
  39     git-branch -l d/e/f &&
  40         test -f .git/refs/heads/d/e/f &&
  41         test -f .git/logs/refs/heads/d/e/f &&
  42         diff expect .git/logs/refs/heads/d/e/f'
  43
  44test_expect_success \
  45    'git branch -d d/e/f should delete a branch and a log' \
  46        'git-branch -d d/e/f &&
  47         test ! -f .git/refs/heads/d/e/f &&
  48         test ! -f .git/logs/refs/heads/d/e/f'
  49
  50test_expect_success \
  51    'git branch j/k should work after branch j has been deleted' \
  52       'git-branch j &&
  53        git-branch -d j &&
  54        git-branch j/k'
  55
  56test_expect_success \
  57    'git branch l should work after branch l/m has been deleted' \
  58       'git-branch l/m &&
  59        git-branch -d l/m &&
  60        git-branch l'
  61
  62test_expect_success \
  63    'git branch -m m m/m should work' \
  64       'git-branch -l m &&
  65        git-branch -m m m/m &&
  66        test -f .git/logs/refs/heads/m/m'
  67
  68test_expect_success \
  69    'git branch -m n/n n should work' \
  70       'git-branch -l n/n &&
  71        git-branch -m n/n n
  72        test -f .git/logs/refs/heads/n'
  73
  74test_expect_failure \
  75    '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
  80test_expect_failure \
  81    '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
  86git-config branch.s/s.dummy Hello
  87
  88test_expect_success \
  89    'git branch -m s/s s should work when s/t is deleted' \
  90       'git-branch -l s/s &&
  91        test -f .git/logs/refs/heads/s/s &&
  92        git-branch -l s/t &&
  93        test -f .git/logs/refs/heads/s/t &&
  94        git-branch -d s/t &&
  95        git-branch -m s/s s &&
  96        test -f .git/logs/refs/heads/s'
  97
  98test_expect_success 'config information was renamed, too' \
  99        "test $(git-config branch.s.dummy) = Hello &&
 100         ! git-config branch.s/s/dummy"
 101
 102test_expect_failure \
 103    'git-branch -m u v should fail when the reflog for u is a symlink' \
 104    'git-branch -l u &&
 105     mv .git/logs/refs/heads/u real-u &&
 106     ln -s real-u .git/logs/refs/heads/u &&
 107     git-branch -m u v'
 108
 109test_expect_success 'test tracking setup via --track' \
 110    'git-config remote.local.url . &&
 111     git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 112     (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
 113     git-branch --track my1 local/master &&
 114     test $(git-config branch.my1.remote) = local &&
 115     test $(git-config branch.my1.merge) = refs/heads/master'
 116
 117test_expect_success 'test tracking setup (non-wildcard, matching)' \
 118    'git-config remote.local.url . &&
 119     git-config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
 120     (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
 121     git-branch --track my4 local/master &&
 122     test $(git-config branch.my4.remote) = local &&
 123     test $(git-config branch.my4.merge) = refs/heads/master'
 124
 125test_expect_success 'test tracking setup (non-wildcard, not matching)' \
 126    'git-config remote.local.url . &&
 127     git-config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
 128     (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
 129     git-branch --track my5 local/master &&
 130     ! test $(git-config branch.my5.remote) = local &&
 131     ! test $(git-config branch.my5.merge) = refs/heads/master'
 132
 133test_expect_success 'test tracking setup via config' \
 134    'git-config branch.autosetupmerge true &&
 135     git-config remote.local.url . &&
 136     git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
 137     (git-show-ref -q refs/remotes/local/master || git-fetch local) &&
 138     git-branch my3 local/master &&
 139     test $(git-config branch.my3.remote) = local &&
 140     test $(git-config branch.my3.merge) = refs/heads/master'
 141
 142test_expect_success 'test overriding tracking setup via --no-track' \
 143    'git-config branch.autosetupmerge true &&
 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 --no-track my2 local/master &&
 148     git-config branch.autosetupmerge false &&
 149     ! test $(git-config branch.my2.remote) = local &&
 150     ! test $(git-config branch.my2.merge) = refs/heads/master'
 151
 152test_expect_success 'test local tracking setup' \
 153    'git branch --track my6 s &&
 154     test $(git-config branch.my6.remote) = . &&
 155     test $(git-config branch.my6.merge) = refs/heads/s'
 156
 157# Keep this test last, as it changes the current branch
 158cat >expect <<EOF
 1590000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000      branch: Created from master
 160EOF
 161test_expect_success \
 162    'git checkout -b g/h/i -l should create a branch and a log' \
 163        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
 164     git-checkout -b g/h/i -l master &&
 165         test -f .git/refs/heads/g/h/i &&
 166         test -f .git/logs/refs/heads/g/h/i &&
 167         diff expect .git/logs/refs/heads/g/h/i'
 168
 169test_done