branch: use ref-filter printing APIs
[git/git.git] / t / t3203-branch-output.sh
CommitLineData
0afc3044
JK
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' '
a48fcd83 15 git branch branch-one &&
0afc3044
JK
16 git branch branch-two HEAD^
17'
18
19test_expect_success 'make remote branches' '
a48fcd83
JN
20 git update-ref refs/remotes/origin/branch-one branch-one &&
21 git update-ref refs/remotes/origin/branch-two branch-two &&
0afc3044
JK
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
cddd127b
MG
35test_expect_success 'git branch --list shows local branches' '
36 git branch --list >actual &&
37 test_cmp expect actual
38'
39
d8d33736
MG
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
0afc3044
JK
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
d8d33736
MG
83cat >expect <<'EOF'
84two
85one
86EOF
7b787599
MG
87test_expect_success 'git branch --list -v pattern shows branch summaries' '
88 git branch --list -v branch* >tmp &&
d8d33736
MG
89 awk "{print \$NF}" <tmp >actual &&
90 test_cmp expect actual
91'
3bb16a8b
NTND
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'
d8d33736 97
7b787599
MG
98test_expect_success 'git branch -v pattern does not show branch summaries' '
99 test_must_fail git branch -v branch*
100'
101
c8183cd2
NTND
102test_expect_success 'git branch shows detached HEAD properly' '
103 cat >expect <<EOF &&
4b063186 104* (HEAD detached at $(git rev-parse --short HEAD^0))
0afc3044
JK
105 branch-one
106 branch-two
107 master
108EOF
0afc3044
JK
109 git checkout HEAD^0 &&
110 git branch >actual &&
fff1bb3a 111 test_i18ncmp expect actual
0afc3044
JK
112'
113
0eb8548f 114test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '
9cb07d81
MM
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
4b063186
MG
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
aedcb7dc
KN
164test_expect_success 'git branch `--sort` option' '
165 cat >expect <<-\EOF &&
aedcb7dc 166 * (HEAD detached from fromtag)
9e468334 167 branch-two
aedcb7dc
KN
168 branch-one
169 master
170 EOF
171 git branch --sort=objectsize >actual &&
172 test_i18ncmp expect actual
173'
174
aa3bc55e
KN
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
0571979b
JK
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
95c38fb0
JK
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
949af068 197 ref-to-remote -> origin/branch-one
95c38fb0
JK
198 EOF
199 git branch >actual.raw &&
200 grep ref-to <actual.raw >actual &&
201 test_cmp expect actual
202'
203
3bb16a8b
NTND
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
0afc3044 228test_done