3 test_description
='git branch display tests'
5 .
"$TEST_DIRECTORY"/lib-terminal.sh
7 test_expect_success
'make commits' '
11 echo content >>file &&
15 test_expect_success
'make branches' '
16 git branch branch-one &&
17 git branch branch-two HEAD^
20 test_expect_success
'make remote branches' '
21 git update-ref refs/remotes/origin/branch-one branch-one &&
22 git update-ref refs/remotes/origin/branch-two branch-two &&
23 git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/branch-one
31 test_expect_success
'git branch shows local branches' '
33 test_cmp expect actual
36 test_expect_success
'git branch --list shows local branches' '
37 git branch --list >actual &&
38 test_cmp expect actual
45 test_expect_success
'git branch --list pattern shows matching local branches' '
46 git branch --list branch* >actual &&
47 test_cmp expect actual
51 origin/HEAD -> origin/branch-one
55 test_expect_success
'git branch -r shows remote branches' '
56 git branch -r >actual &&
57 test_cmp expect actual
64 remotes/origin/HEAD -> origin/branch-one
65 remotes/origin/branch-one
66 remotes/origin/branch-two
68 test_expect_success
'git branch -a shows local and remote branches' '
69 git branch -a >actual &&
70 test_cmp expect actual
78 test_expect_success
'git branch -v shows branch summaries' '
80 awk "{print \$NF}" <tmp >actual &&
81 test_cmp expect actual
88 test_expect_success
'git branch --list -v pattern shows branch summaries' '
89 git branch --list -v branch* >tmp &&
90 awk "{print \$NF}" <tmp >actual &&
91 test_cmp expect actual
93 test_expect_success
'git branch --ignore-case --list -v pattern shows branch summaries' '
94 git branch --list --ignore-case -v BRANCH* >tmp &&
95 awk "{print \$NF}" <tmp >actual &&
96 test_cmp expect actual
99 test_expect_success
'git branch -v pattern does not show branch summaries' '
100 test_must_fail git branch -v branch*
103 test_expect_success
'git branch shows detached HEAD properly' '
105 * (HEAD detached at $(git rev-parse --short HEAD^0))
110 git checkout HEAD^0 &&
111 git branch >actual &&
112 test_i18ncmp expect actual
115 test_expect_success
'git branch shows detached HEAD properly after checkout --detach' '
116 git checkout master &&
118 * (HEAD detached at $(git rev-parse --short HEAD^0))
123 git checkout --detach &&
124 git branch >actual &&
125 test_i18ncmp expect actual
128 test_expect_success
'git branch shows detached HEAD properly after moving' '
130 * (HEAD detached from $(git rev-parse --short HEAD))
135 git reset --hard HEAD^1 &&
136 git branch >actual &&
137 test_i18ncmp expect actual
140 test_expect_success
'git branch shows detached HEAD properly from tag' '
142 * (HEAD detached at fromtag)
147 git tag fromtag master &&
148 git checkout fromtag &&
149 git branch >actual &&
150 test_i18ncmp expect actual
153 test_expect_success
'git branch shows detached HEAD properly after moving from tag' '
155 * (HEAD detached from fromtag)
160 git reset --hard HEAD^1 &&
161 git branch >actual &&
162 test_i18ncmp expect actual
165 test_expect_success
'git branch `--sort` option' '
166 cat >expect <<-\EOF &&
167 * (HEAD detached from fromtag)
172 git branch --sort=objectsize >actual &&
173 test_i18ncmp expect actual
176 test_expect_success
'git branch --points-at option' '
177 cat >expect <<-\EOF &&
181 git branch --points-at=branch-one >actual &&
182 test_cmp expect actual
185 test_expect_success
'ambiguous branch/tag not marked' '
187 git branch ambiguous &&
188 echo " ambiguous" >expect &&
189 git branch --list ambiguous >actual &&
190 test_cmp expect actual
193 test_expect_success
'local-branch symrefs shortened properly' '
194 git symbolic-ref refs/heads/ref-to-branch refs/heads/branch-one &&
195 git symbolic-ref refs/heads/ref-to-remote refs/remotes/origin/branch-one &&
196 cat >expect <<-\EOF &&
197 ref-to-branch -> branch-one
198 ref-to-remote -> origin/branch-one
200 git branch >actual.raw &&
201 grep ref-to <actual.raw >actual &&
202 test_cmp expect actual
205 test_expect_success
'sort branches, ignore case' '
207 git init sort-icase &&
209 test_commit initial &&
210 git branch branch-one &&
211 git branch BRANCH-two &&
212 git branch --list | awk "{print \$NF}" >actual &&
213 cat >expected <<-\EOF &&
218 test_cmp expected actual &&
219 git branch --list -i | awk "{print \$NF}" >actual &&
220 cat >expected <<-\EOF &&
225 test_cmp expected actual
229 test_expect_success
'git branch --format option' '
230 cat >expect <<-\EOF &&
231 Refname is (HEAD detached from fromtag)
232 Refname is refs/heads/ambiguous
233 Refname is refs/heads/branch-one
234 Refname is refs/heads/branch-two
235 Refname is refs/heads/master
236 Refname is refs/heads/ref-to-branch
237 Refname is refs/heads/ref-to-remote
239 git branch --format="Refname is %(refname)" >actual &&
240 test_i18ncmp expect actual
243 test_expect_success
"set up color tests" '
244 echo "<RED>master<RESET>" >expect.color &&
245 echo "master" >expect.bare &&
246 color_args="--format=%(color:red)%(refname:short) --list master"
249 test_expect_success
'%(color) omitted without tty' '
250 TERM=vt100 git branch $color_args >actual.raw &&
251 test_decode_color <actual.raw >actual &&
252 test_cmp expect.bare actual
255 test_expect_success TTY
'%(color) present with tty' '
256 test_terminal git branch $color_args >actual.raw &&
257 test_decode_color <actual.raw >actual &&
258 test_cmp expect.color actual
261 test_expect_success
'--color overrides auto-color' '
262 git branch --color $color_args >actual.raw &&
263 test_decode_color <actual.raw >actual &&
264 test_cmp expect.color actual