]>
Commit | Line | Data |
---|---|---|
0afc3044 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='git branch display tests' | |
4 | . ./test-lib.sh | |
11b087ad | 5 | . "$TEST_DIRECTORY"/lib-terminal.sh |
0afc3044 JK |
6 | |
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 | |
13 | ' | |
14 | ||
15 | test_expect_success 'make branches' ' | |
a48fcd83 | 16 | git branch branch-one && |
0afc3044 JK |
17 | git branch branch-two HEAD^ |
18 | ' | |
19 | ||
20 | test_expect_success 'make remote branches' ' | |
a48fcd83 JN |
21 | git update-ref refs/remotes/origin/branch-one branch-one && |
22 | git update-ref refs/remotes/origin/branch-two branch-two && | |
0afc3044 JK |
23 | git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/branch-one |
24 | ' | |
25 | ||
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 | |
34 | ' | |
35 | ||
cddd127b MG |
36 | test_expect_success 'git branch --list shows local branches' ' |
37 | git branch --list >actual && | |
38 | test_cmp expect actual | |
39 | ' | |
40 | ||
d8d33736 MG |
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 | |
48 | ' | |
49 | ||
0afc3044 JK |
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 | |
58 | ' | |
59 | ||
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 | |
71 | ' | |
72 | ||
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 | |
82 | ' | |
83 | ||
d8d33736 MG |
84 | cat >expect <<'EOF' |
85 | two | |
86 | one | |
87 | EOF | |
7b787599 MG |
88 | test_expect_success 'git branch --list -v pattern shows branch summaries' ' |
89 | git branch --list -v branch* >tmp && | |
d8d33736 MG |
90 | awk "{print \$NF}" <tmp >actual && |
91 | test_cmp expect actual | |
92 | ' | |
3bb16a8b NTND |
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 | |
97 | ' | |
d8d33736 | 98 | |
7b787599 MG |
99 | test_expect_success 'git branch -v pattern does not show branch summaries' ' |
100 | test_must_fail git branch -v branch* | |
101 | ' | |
102 | ||
c8183cd2 NTND |
103 | test_expect_success 'git branch shows detached HEAD properly' ' |
104 | cat >expect <<EOF && | |
4b063186 | 105 | * (HEAD detached at $(git rev-parse --short HEAD^0)) |
0afc3044 JK |
106 | branch-one |
107 | branch-two | |
108 | master | |
109 | EOF | |
0afc3044 JK |
110 | git checkout HEAD^0 && |
111 | git branch >actual && | |
fff1bb3a | 112 | test_i18ncmp expect actual |
0afc3044 JK |
113 | ' |
114 | ||
0eb8548f | 115 | test_expect_success 'git branch shows detached HEAD properly after checkout --detach' ' |
9cb07d81 MM |
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 | |
122 | EOF | |
123 | git checkout --detach && | |
124 | git branch >actual && | |
125 | test_i18ncmp expect actual | |
126 | ' | |
127 | ||
4b063186 MG |
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 | |
134 | EOF | |
135 | git reset --hard HEAD^1 && | |
136 | git branch >actual && | |
137 | test_i18ncmp expect actual | |
138 | ' | |
139 | ||
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 | |
146 | EOF | |
147 | git tag fromtag master && | |
148 | git checkout fromtag && | |
149 | git branch >actual && | |
150 | test_i18ncmp expect actual | |
151 | ' | |
152 | ||
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 | |
159 | EOF | |
160 | git reset --hard HEAD^1 && | |
161 | git branch >actual && | |
162 | test_i18ncmp expect actual | |
163 | ' | |
164 | ||
aedcb7dc KN |
165 | test_expect_success 'git branch `--sort` option' ' |
166 | cat >expect <<-\EOF && | |
aedcb7dc | 167 | * (HEAD detached from fromtag) |
9e468334 | 168 | branch-two |
aedcb7dc KN |
169 | branch-one |
170 | master | |
171 | EOF | |
172 | git branch --sort=objectsize >actual && | |
173 | test_i18ncmp expect actual | |
174 | ' | |
175 | ||
aa3bc55e KN |
176 | test_expect_success 'git branch --points-at option' ' |
177 | cat >expect <<-\EOF && | |
178 | branch-one | |
179 | master | |
180 | EOF | |
181 | git branch --points-at=branch-one >actual && | |
182 | test_cmp expect actual | |
183 | ' | |
184 | ||
0571979b JK |
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 | |
191 | ' | |
192 | ||
95c38fb0 JK |
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 | |
949af068 | 198 | ref-to-remote -> origin/branch-one |
95c38fb0 JK |
199 | EOF |
200 | git branch >actual.raw && | |
201 | grep ref-to <actual.raw >actual && | |
202 | test_cmp expect actual | |
203 | ' | |
204 | ||
3bb16a8b NTND |
205 | test_expect_success 'sort branches, ignore case' ' |
206 | ( | |
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 | |
217 | EOF | |
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 | |
224 | EOF | |
225 | test_cmp expected actual | |
226 | ) | |
227 | ' | |
228 | ||
3d9e4ce3 KN |
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 | |
238 | EOF | |
239 | git branch --format="Refname is %(refname)" >actual && | |
0d75bfe6 | 240 | test_i18ncmp expect actual |
3d9e4ce3 KN |
241 | ' |
242 | ||
11b087ad JK |
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" | |
247 | ' | |
248 | ||
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 | |
253 | ' | |
254 | ||
255 | test_expect_success TTY '%(color) present with tty' ' | |
e433749d | 256 | test_terminal git branch $color_args >actual.raw && |
11b087ad JK |
257 | test_decode_color <actual.raw >actual && |
258 | test_cmp expect.color actual | |
259 | ' | |
260 | ||
11b087ad JK |
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 | |
265 | ' | |
266 | ||
0afc3044 | 267 | test_done |