3 test_description
='git branch display tests'
6 test_expect_success
'make commits' '
10 echo content >>file &&
14 test_expect_success
'make branches' '
15 git branch branch-one &&
16 git branch branch-two HEAD^
19 test_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
30 test_expect_success
'git branch shows local branches' '
32 test_cmp expect actual
35 test_expect_success
'git branch --list shows local branches' '
36 git branch --list >actual &&
37 test_cmp expect actual
44 test_expect_success
'git branch --list pattern shows matching local branches' '
45 git branch --list branch* >actual &&
46 test_cmp expect actual
50 origin/HEAD -> origin/branch-one
54 test_expect_success
'git branch -r shows remote branches' '
55 git branch -r >actual &&
56 test_cmp expect actual
63 remotes/origin/HEAD -> origin/branch-one
64 remotes/origin/branch-one
65 remotes/origin/branch-two
67 test_expect_success
'git branch -a shows local and remote branches' '
68 git branch -a >actual &&
69 test_cmp expect actual
77 test_expect_success
'git branch -v shows branch summaries' '
79 awk "{print \$NF}" <tmp >actual &&
80 test_cmp expect actual
87 test_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
92 test_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
98 test_expect_success
'git branch -v pattern does not show branch summaries' '
99 test_must_fail git branch -v branch*
102 test_expect_success
'git branch shows detached HEAD properly' '
104 * (HEAD detached at $(git rev-parse --short HEAD^0))
109 git checkout HEAD^0 &&
110 git branch >actual &&
111 test_i18ncmp expect actual
114 test_expect_success
'git branch shows detached HEAD properly after checkout --detach' '
115 git checkout master &&
117 * (HEAD detached at $(git rev-parse --short HEAD^0))
122 git checkout --detach &&
123 git branch >actual &&
124 test_i18ncmp expect actual
127 test_expect_success
'git branch shows detached HEAD properly after moving' '
129 * (HEAD detached from $(git rev-parse --short HEAD))
134 git reset --hard HEAD^1 &&
135 git branch >actual &&
136 test_i18ncmp expect actual
139 test_expect_success
'git branch shows detached HEAD properly from tag' '
141 * (HEAD detached at fromtag)
146 git tag fromtag master &&
147 git checkout fromtag &&
148 git branch >actual &&
149 test_i18ncmp expect actual
152 test_expect_success
'git branch shows detached HEAD properly after moving from tag' '
154 * (HEAD detached from fromtag)
159 git reset --hard HEAD^1 &&
160 git branch >actual &&
161 test_i18ncmp expect actual
164 test_expect_success
'git branch `--sort` option' '
165 cat >expect <<-\EOF &&
166 * (HEAD detached from fromtag)
171 git branch --sort=objectsize >actual &&
172 test_i18ncmp expect actual
175 test_expect_success
'git branch --points-at option' '
176 cat >expect <<-\EOF &&
180 git branch --points-at=branch-one >actual &&
181 test_cmp expect actual
184 test_expect_success
'ambiguous branch/tag not marked' '
186 git branch ambiguous &&
187 echo " ambiguous" >expect &&
188 git branch --list ambiguous >actual &&
189 test_cmp expect actual
192 test_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
199 git branch >actual.raw &&
200 grep ref-to <actual.raw >actual &&
201 test_cmp expect actual
204 test_expect_success
'sort branches, ignore case' '
206 git init 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 &&
217 test_cmp expected actual &&
218 git branch --list -i | awk "{print \$NF}" >actual &&
219 cat >expected <<-\EOF &&
224 test_cmp expected actual
228 test_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
238 git branch --format="Refname is %(refname)" >actual &&
239 test_cmp expect actual