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