Merge branch 'ab/test-readme-updates'
[git/raj.git] / t / t3203-branch-output.sh
blob5778c0afe12be2495b58a5251fb9bc8dc395a143
1 #!/bin/sh
3 test_description='git branch display tests'
4 . ./test-lib.sh
6 test_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
14 test_expect_success 'make branches' '
15 git branch branch-one &&
16 git branch branch-two HEAD^
19 test_expect_success 'make remote branches' '
20 git update-ref refs/remotes/origin/branch-one branch-one &&
21 git update-ref refs/remotes/origin/branch-two branch-two &&
22 git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/branch-one
25 cat >expect <<'EOF'
26 branch-one
27 branch-two
28 * master
29 EOF
30 test_expect_success 'git branch shows local branches' '
31 git branch >actual &&
32 test_cmp expect actual
35 test_expect_success 'git branch --list shows local branches' '
36 git branch --list >actual &&
37 test_cmp expect actual
40 cat >expect <<'EOF'
41 branch-one
42 branch-two
43 EOF
44 test_expect_success 'git branch --list pattern shows matching local branches' '
45 git branch --list branch* >actual &&
46 test_cmp expect actual
49 cat >expect <<'EOF'
50 origin/HEAD -> origin/branch-one
51 origin/branch-one
52 origin/branch-two
53 EOF
54 test_expect_success 'git branch -r shows remote branches' '
55 git branch -r >actual &&
56 test_cmp expect actual
59 cat >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
66 EOF
67 test_expect_success 'git branch -a shows local and remote branches' '
68 git branch -a >actual &&
69 test_cmp expect actual
72 cat >expect <<'EOF'
73 two
74 one
75 two
76 EOF
77 test_expect_success 'git branch -v shows branch summaries' '
78 git branch -v >tmp &&
79 awk "{print \$NF}" <tmp >actual &&
80 test_cmp expect actual
83 cat >expect <<'EOF'
84 two
85 one
86 EOF
87 test_expect_success 'git branch --list -v pattern shows branch summaries' '
88 git branch --list -v branch* >tmp &&
89 awk "{print \$NF}" <tmp >actual &&
90 test_cmp expect actual
92 test_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
98 test_expect_success 'git branch -v pattern does not show branch summaries' '
99 test_must_fail git branch -v branch*
102 test_expect_success 'git branch shows detached HEAD properly' '
103 cat >expect <<EOF &&
104 * (HEAD detached at $(git rev-parse --short HEAD^0))
105 branch-one
106 branch-two
107 master
109 git checkout HEAD^0 &&
110 git branch >actual &&
111 test_i18ncmp expect actual
114 test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '
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
122 git checkout --detach &&
123 git branch >actual &&
124 test_i18ncmp expect actual
127 test_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
134 git reset --hard HEAD^1 &&
135 git branch >actual &&
136 test_i18ncmp expect actual
139 test_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
146 git tag fromtag master &&
147 git checkout fromtag &&
148 git branch >actual &&
149 test_i18ncmp expect actual
152 test_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
159 git reset --hard HEAD^1 &&
160 git branch >actual &&
161 test_i18ncmp expect actual
164 test_expect_success 'git branch `--sort` option' '
165 cat >expect <<-\EOF &&
166 * (HEAD detached from fromtag)
167 branch-two
168 branch-one
169 master
171 git branch --sort=objectsize >actual &&
172 test_i18ncmp expect actual
175 test_expect_success 'git branch --points-at option' '
176 cat >expect <<-\EOF &&
177 branch-one
178 master
180 git branch --points-at=branch-one >actual &&
181 test_cmp expect actual
184 test_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
192 test_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
197 ref-to-remote -> origin/branch-one
199 git branch >actual.raw &&
200 grep ref-to <actual.raw >actual &&
201 test_cmp expect actual
204 test_expect_success 'sort branches, ignore case' '
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
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
224 test_cmp expected actual
228 test_expect_success 'git branch --format option' '
229 cat >expect <<-\EOF &&
230 Refname is (HEAD detached from fromtag)
231 Refname is refs/heads/ambiguous
232 Refname is refs/heads/branch-one
233 Refname is refs/heads/branch-two
234 Refname is refs/heads/master
235 Refname is refs/heads/ref-to-branch
236 Refname is refs/heads/ref-to-remote
238 git branch --format="Refname is %(refname)" >actual &&
239 test_cmp expect actual
242 test_done