t / t3203-branch-output.shon commit Merge branch 'rs/log-email-subject' (0a24610)
   1#!/bin/sh
   2
   3test_description='git branch display tests'
   4. ./test-lib.sh
   5
   6test_expect_success 'make commits' '
   7        echo content >file &&
   8        git add file &&
   9        git commit -m one &&
  10        echo content >>file &&
  11        git commit -a -m two
  12'
  13
  14test_expect_success 'make branches' '
  15        git branch branch-one &&
  16        git branch branch-two HEAD^
  17'
  18
  19test_expect_success 'make remote branches' '
  20        git update-ref refs/remotes/origin/branch-one branch-one &&
  21        git update-ref refs/remotes/origin/branch-two branch-two &&
  22        git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/branch-one
  23'
  24
  25cat >expect <<'EOF'
  26  branch-one
  27  branch-two
  28* master
  29EOF
  30test_expect_success 'git branch shows local branches' '
  31        git branch >actual &&
  32        test_cmp expect actual
  33'
  34
  35test_expect_success 'git branch --list shows local branches' '
  36        git branch --list >actual &&
  37        test_cmp expect actual
  38'
  39
  40cat >expect <<'EOF'
  41  branch-one
  42  branch-two
  43EOF
  44test_expect_success 'git branch --list pattern shows matching local branches' '
  45        git branch --list branch* >actual &&
  46        test_cmp expect actual
  47'
  48
  49cat >expect <<'EOF'
  50  origin/HEAD -> origin/branch-one
  51  origin/branch-one
  52  origin/branch-two
  53EOF
  54test_expect_success 'git branch -r shows remote branches' '
  55        git branch -r >actual &&
  56        test_cmp expect actual
  57'
  58
  59cat >expect <<'EOF'
  60  branch-one
  61  branch-two
  62* master
  63  remotes/origin/HEAD -> origin/branch-one
  64  remotes/origin/branch-one
  65  remotes/origin/branch-two
  66EOF
  67test_expect_success 'git branch -a shows local and remote branches' '
  68        git branch -a >actual &&
  69        test_cmp expect actual
  70'
  71
  72cat >expect <<'EOF'
  73two
  74one
  75two
  76EOF
  77test_expect_success 'git branch -v shows branch summaries' '
  78        git branch -v >tmp &&
  79        awk "{print \$NF}" <tmp >actual &&
  80        test_cmp expect actual
  81'
  82
  83cat >expect <<'EOF'
  84two
  85one
  86EOF
  87test_expect_success 'git branch --list -v pattern shows branch summaries' '
  88        git branch --list -v branch* >tmp &&
  89        awk "{print \$NF}" <tmp >actual &&
  90        test_cmp expect actual
  91'
  92test_expect_success 'git branch --ignore-case --list -v pattern shows branch summaries' '
  93        git branch --list --ignore-case -v BRANCH* >tmp &&
  94        awk "{print \$NF}" <tmp >actual &&
  95        test_cmp expect actual
  96'
  97
  98test_expect_success 'git branch -v pattern does not show branch summaries' '
  99        test_must_fail git branch -v branch*
 100'
 101
 102test_expect_success 'git branch shows detached HEAD properly' '
 103        cat >expect <<EOF &&
 104* (HEAD detached at $(git rev-parse --short HEAD^0))
 105  branch-one
 106  branch-two
 107  master
 108EOF
 109        git checkout HEAD^0 &&
 110        git branch >actual &&
 111        test_i18ncmp expect actual
 112'
 113
 114test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '
 115        git checkout master &&
 116        cat >expect <<EOF &&
 117* (HEAD detached at $(git rev-parse --short HEAD^0))
 118  branch-one
 119  branch-two
 120  master
 121EOF
 122        git checkout --detach &&
 123        git branch >actual &&
 124        test_i18ncmp expect actual
 125'
 126
 127test_expect_success 'git branch shows detached HEAD properly after moving' '
 128        cat >expect <<EOF &&
 129* (HEAD detached from $(git rev-parse --short HEAD))
 130  branch-one
 131  branch-two
 132  master
 133EOF
 134        git reset --hard HEAD^1 &&
 135        git branch >actual &&
 136        test_i18ncmp expect actual
 137'
 138
 139test_expect_success 'git branch shows detached HEAD properly from tag' '
 140        cat >expect <<EOF &&
 141* (HEAD detached at fromtag)
 142  branch-one
 143  branch-two
 144  master
 145EOF
 146        git tag fromtag master &&
 147        git checkout fromtag &&
 148        git branch >actual &&
 149        test_i18ncmp expect actual
 150'
 151
 152test_expect_success 'git branch shows detached HEAD properly after moving from tag' '
 153        cat >expect <<EOF &&
 154* (HEAD detached from fromtag)
 155  branch-one
 156  branch-two
 157  master
 158EOF
 159        git reset --hard HEAD^1 &&
 160        git branch >actual &&
 161        test_i18ncmp expect actual
 162'
 163
 164test_expect_success 'git branch `--sort` option' '
 165        cat >expect <<-\EOF &&
 166        * (HEAD detached from fromtag)
 167          branch-two
 168          branch-one
 169          master
 170        EOF
 171        git branch --sort=objectsize >actual &&
 172        test_i18ncmp expect actual
 173'
 174
 175test_expect_success 'git branch --points-at option' '
 176        cat >expect <<-\EOF &&
 177          branch-one
 178          master
 179        EOF
 180        git branch --points-at=branch-one >actual &&
 181        test_cmp expect actual
 182'
 183
 184test_expect_success 'ambiguous branch/tag not marked' '
 185        git tag ambiguous &&
 186        git branch ambiguous &&
 187        echo "  ambiguous" >expect &&
 188        git branch --list ambiguous >actual &&
 189        test_cmp expect actual
 190'
 191
 192test_expect_success 'local-branch symrefs shortened properly' '
 193        git symbolic-ref refs/heads/ref-to-branch refs/heads/branch-one &&
 194        git symbolic-ref refs/heads/ref-to-remote refs/remotes/origin/branch-one &&
 195        cat >expect <<-\EOF &&
 196          ref-to-branch -> branch-one
 197          ref-to-remote -> origin/branch-one
 198        EOF
 199        git branch >actual.raw &&
 200        grep ref-to <actual.raw >actual &&
 201        test_cmp expect actual
 202'
 203
 204test_expect_success 'sort branches, ignore case' '
 205        (
 206                git init sort-icase &&
 207                cd sort-icase &&
 208                test_commit initial &&
 209                git branch branch-one &&
 210                git branch BRANCH-two &&
 211                git branch --list | awk "{print \$NF}" >actual &&
 212                cat >expected <<-\EOF &&
 213                BRANCH-two
 214                branch-one
 215                master
 216                EOF
 217                test_cmp expected actual &&
 218                git branch --list -i | awk "{print \$NF}" >actual &&
 219                cat >expected <<-\EOF &&
 220                branch-one
 221                BRANCH-two
 222                master
 223                EOF
 224                test_cmp expected actual
 225        )
 226'
 227
 228test_expect_success 'git branch --format option' '
 229        cat >expect <<-\EOF &&
 230        Refname is (HEAD detached from fromtag)
 231        Refname is refs/heads/ambiguous
 232        Refname is refs/heads/branch-one
 233        Refname is refs/heads/branch-two
 234        Refname is refs/heads/master
 235        Refname is refs/heads/ref-to-branch
 236        Refname is refs/heads/ref-to-remote
 237        EOF
 238        git branch --format="Refname is %(refname)" >actual &&
 239        test_cmp expect actual
 240'
 241
 242test_done