]>
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 | ||
0ecb1fc7 DU |
103 | test_expect_success 'git branch `--show-current` shows current branch' ' |
104 | cat >expect <<-\EOF && | |
105 | branch-two | |
106 | EOF | |
107 | git checkout branch-two && | |
108 | git branch --show-current >actual && | |
109 | test_cmp expect actual | |
110 | ' | |
111 | ||
112 | test_expect_success 'git branch `--show-current` is silent when detached HEAD' ' | |
113 | git checkout HEAD^0 && | |
114 | git branch --show-current >actual && | |
115 | test_must_be_empty actual | |
116 | ' | |
117 | ||
118 | test_expect_success 'git branch `--show-current` works properly when tag exists' ' | |
119 | cat >expect <<-\EOF && | |
120 | branch-and-tag-name | |
121 | EOF | |
122 | test_when_finished " | |
123 | git checkout branch-one | |
124 | git branch -D branch-and-tag-name | |
125 | " && | |
126 | git checkout -b branch-and-tag-name && | |
127 | test_when_finished "git tag -d branch-and-tag-name" && | |
128 | git tag branch-and-tag-name && | |
129 | git branch --show-current >actual && | |
130 | test_cmp expect actual | |
131 | ' | |
132 | ||
133 | test_expect_success 'git branch `--show-current` works properly with worktrees' ' | |
134 | cat >expect <<-\EOF && | |
135 | branch-one | |
136 | branch-two | |
137 | EOF | |
138 | git checkout branch-one && | |
139 | git worktree add worktree branch-two && | |
140 | { | |
141 | git branch --show-current && | |
142 | git -C worktree branch --show-current | |
143 | } >actual && | |
144 | test_cmp expect actual | |
145 | ' | |
146 | ||
c8183cd2 NTND |
147 | test_expect_success 'git branch shows detached HEAD properly' ' |
148 | cat >expect <<EOF && | |
4b063186 | 149 | * (HEAD detached at $(git rev-parse --short HEAD^0)) |
0afc3044 JK |
150 | branch-one |
151 | branch-two | |
152 | master | |
153 | EOF | |
0afc3044 JK |
154 | git checkout HEAD^0 && |
155 | git branch >actual && | |
fff1bb3a | 156 | test_i18ncmp expect actual |
0afc3044 JK |
157 | ' |
158 | ||
0eb8548f | 159 | test_expect_success 'git branch shows detached HEAD properly after checkout --detach' ' |
9cb07d81 MM |
160 | git checkout master && |
161 | cat >expect <<EOF && | |
162 | * (HEAD detached at $(git rev-parse --short HEAD^0)) | |
163 | branch-one | |
164 | branch-two | |
165 | master | |
166 | EOF | |
167 | git checkout --detach && | |
168 | git branch >actual && | |
169 | test_i18ncmp expect actual | |
170 | ' | |
171 | ||
4b063186 MG |
172 | test_expect_success 'git branch shows detached HEAD properly after moving' ' |
173 | cat >expect <<EOF && | |
174 | * (HEAD detached from $(git rev-parse --short HEAD)) | |
175 | branch-one | |
176 | branch-two | |
177 | master | |
178 | EOF | |
179 | git reset --hard HEAD^1 && | |
180 | git branch >actual && | |
181 | test_i18ncmp expect actual | |
182 | ' | |
183 | ||
184 | test_expect_success 'git branch shows detached HEAD properly from tag' ' | |
185 | cat >expect <<EOF && | |
186 | * (HEAD detached at fromtag) | |
187 | branch-one | |
188 | branch-two | |
189 | master | |
190 | EOF | |
191 | git tag fromtag master && | |
192 | git checkout fromtag && | |
193 | git branch >actual && | |
194 | test_i18ncmp expect actual | |
195 | ' | |
196 | ||
197 | test_expect_success 'git branch shows detached HEAD properly after moving from tag' ' | |
198 | cat >expect <<EOF && | |
199 | * (HEAD detached from fromtag) | |
200 | branch-one | |
201 | branch-two | |
202 | master | |
203 | EOF | |
204 | git reset --hard HEAD^1 && | |
205 | git branch >actual && | |
206 | test_i18ncmp expect actual | |
207 | ' | |
208 | ||
aedcb7dc KN |
209 | test_expect_success 'git branch `--sort` option' ' |
210 | cat >expect <<-\EOF && | |
aedcb7dc | 211 | * (HEAD detached from fromtag) |
9e468334 | 212 | branch-two |
aedcb7dc KN |
213 | branch-one |
214 | master | |
215 | EOF | |
216 | git branch --sort=objectsize >actual && | |
217 | test_i18ncmp expect actual | |
218 | ' | |
219 | ||
aa3bc55e KN |
220 | test_expect_success 'git branch --points-at option' ' |
221 | cat >expect <<-\EOF && | |
222 | branch-one | |
223 | master | |
224 | EOF | |
225 | git branch --points-at=branch-one >actual && | |
226 | test_cmp expect actual | |
227 | ' | |
228 | ||
0571979b JK |
229 | test_expect_success 'ambiguous branch/tag not marked' ' |
230 | git tag ambiguous && | |
231 | git branch ambiguous && | |
232 | echo " ambiguous" >expect && | |
233 | git branch --list ambiguous >actual && | |
234 | test_cmp expect actual | |
235 | ' | |
236 | ||
95c38fb0 JK |
237 | test_expect_success 'local-branch symrefs shortened properly' ' |
238 | git symbolic-ref refs/heads/ref-to-branch refs/heads/branch-one && | |
239 | git symbolic-ref refs/heads/ref-to-remote refs/remotes/origin/branch-one && | |
240 | cat >expect <<-\EOF && | |
241 | ref-to-branch -> branch-one | |
949af068 | 242 | ref-to-remote -> origin/branch-one |
95c38fb0 JK |
243 | EOF |
244 | git branch >actual.raw && | |
245 | grep ref-to <actual.raw >actual && | |
246 | test_cmp expect actual | |
247 | ' | |
248 | ||
3bb16a8b NTND |
249 | test_expect_success 'sort branches, ignore case' ' |
250 | ( | |
251 | git init sort-icase && | |
252 | cd sort-icase && | |
253 | test_commit initial && | |
254 | git branch branch-one && | |
255 | git branch BRANCH-two && | |
256 | git branch --list | awk "{print \$NF}" >actual && | |
257 | cat >expected <<-\EOF && | |
258 | BRANCH-two | |
259 | branch-one | |
260 | master | |
261 | EOF | |
262 | test_cmp expected actual && | |
263 | git branch --list -i | awk "{print \$NF}" >actual && | |
264 | cat >expected <<-\EOF && | |
265 | branch-one | |
266 | BRANCH-two | |
267 | master | |
268 | EOF | |
269 | test_cmp expected actual | |
270 | ) | |
271 | ' | |
272 | ||
3d9e4ce3 KN |
273 | test_expect_success 'git branch --format option' ' |
274 | cat >expect <<-\EOF && | |
275 | Refname is (HEAD detached from fromtag) | |
276 | Refname is refs/heads/ambiguous | |
277 | Refname is refs/heads/branch-one | |
278 | Refname is refs/heads/branch-two | |
279 | Refname is refs/heads/master | |
280 | Refname is refs/heads/ref-to-branch | |
281 | Refname is refs/heads/ref-to-remote | |
282 | EOF | |
283 | git branch --format="Refname is %(refname)" >actual && | |
0d75bfe6 | 284 | test_i18ncmp expect actual |
3d9e4ce3 KN |
285 | ' |
286 | ||
11b087ad JK |
287 | test_expect_success "set up color tests" ' |
288 | echo "<RED>master<RESET>" >expect.color && | |
289 | echo "master" >expect.bare && | |
290 | color_args="--format=%(color:red)%(refname:short) --list master" | |
291 | ' | |
292 | ||
293 | test_expect_success '%(color) omitted without tty' ' | |
294 | TERM=vt100 git branch $color_args >actual.raw && | |
295 | test_decode_color <actual.raw >actual && | |
296 | test_cmp expect.bare actual | |
297 | ' | |
298 | ||
299 | test_expect_success TTY '%(color) present with tty' ' | |
e433749d | 300 | test_terminal git branch $color_args >actual.raw && |
11b087ad JK |
301 | test_decode_color <actual.raw >actual && |
302 | test_cmp expect.color actual | |
303 | ' | |
304 | ||
11b087ad JK |
305 | test_expect_success '--color overrides auto-color' ' |
306 | git branch --color $color_args >actual.raw && | |
307 | test_decode_color <actual.raw >actual && | |
308 | test_cmp expect.color actual | |
309 | ' | |
310 | ||
0afc3044 | 311 | test_done |