Merge branch 'bc/t3430-fixup'
[git.git] / t / t3203-branch-output.sh
blobee6787614c80edb9b5b24065277dd413350a6fc6
1 #!/bin/sh
3 test_description='git branch display tests'
4 . ./test-lib.sh
5 . "$TEST_DIRECTORY"/lib-terminal.sh
7 test_expect_success 'make commits' '
8 echo content >file &&
9 git add file &&
10 git commit -m one &&
11 echo content >>file &&
12 git commit -a -m two
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
26 cat >expect <<'EOF'
27 branch-one
28 branch-two
29 * master
30 EOF
31 test_expect_success 'git branch shows local branches' '
32 git branch >actual &&
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
41 cat >expect <<'EOF'
42 branch-one
43 branch-two
44 EOF
45 test_expect_success 'git branch --list pattern shows matching local branches' '
46 git branch --list branch* >actual &&
47 test_cmp expect actual
50 cat >expect <<'EOF'
51 origin/HEAD -> origin/branch-one
52 origin/branch-one
53 origin/branch-two
54 EOF
55 test_expect_success 'git branch -r shows remote branches' '
56 git branch -r >actual &&
57 test_cmp expect actual
60 cat >expect <<'EOF'
61 branch-one
62 branch-two
63 * master
64 remotes/origin/HEAD -> origin/branch-one
65 remotes/origin/branch-one
66 remotes/origin/branch-two
67 EOF
68 test_expect_success 'git branch -a shows local and remote branches' '
69 git branch -a >actual &&
70 test_cmp expect actual
73 cat >expect <<'EOF'
74 two
75 one
76 two
77 EOF
78 test_expect_success 'git branch -v shows branch summaries' '
79 git branch -v >tmp &&
80 awk "{print \$NF}" <tmp >actual &&
81 test_cmp expect actual
84 cat >expect <<'EOF'
85 two
86 one
87 EOF
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' '
104 cat >expect <<EOF &&
105 * (HEAD detached at $(git rev-parse --short HEAD^0))
106 branch-one
107 branch-two
108 master
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 &&
117 cat >expect <<EOF &&
118 * (HEAD detached at $(git rev-parse --short HEAD^0))
119 branch-one
120 branch-two
121 master
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' '
129 cat >expect <<EOF &&
130 * (HEAD detached from $(git rev-parse --short HEAD))
131 branch-one
132 branch-two
133 master
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' '
141 cat >expect <<EOF &&
142 * (HEAD detached at fromtag)
143 branch-one
144 branch-two
145 master
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' '
154 cat >expect <<EOF &&
155 * (HEAD detached from fromtag)
156 branch-one
157 branch-two
158 master
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)
168 branch-two
169 branch-one
170 master
172 git branch --sort=objectsize >actual &&
173 test_i18ncmp expect actual
176 test_expect_success 'git branch --points-at option' '
177 cat >expect <<-\EOF &&
178 branch-one
179 master
181 git branch --points-at=branch-one >actual &&
182 test_cmp expect actual
185 test_expect_success 'ambiguous branch/tag not marked' '
186 git tag ambiguous &&
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 &&
208 cd 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 &&
214 BRANCH-two
215 branch-one
216 master
218 test_cmp expected actual &&
219 git branch --list -i | awk "{print \$NF}" >actual &&
220 cat >expected <<-\EOF &&
221 branch-one
222 BRANCH-two
223 master
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
267 test_done