branch.c: use 'ref-filter' 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'
92
7b787599
MG
93test_expect_success 'git branch -v pattern does not show branch summaries' '
94 test_must_fail git branch -v branch*
95'
96
c8183cd2
NTND
97test_expect_success 'git branch shows detached HEAD properly' '
98 cat >expect <<EOF &&
4b063186 99* (HEAD detached at $(git rev-parse --short HEAD^0))
0afc3044
JK
100 branch-one
101 branch-two
102 master
103EOF
0afc3044
JK
104 git checkout HEAD^0 &&
105 git branch >actual &&
fff1bb3a 106 test_i18ncmp expect actual
0afc3044
JK
107'
108
4b063186
MG
109test_expect_success 'git branch shows detached HEAD properly after moving' '
110 cat >expect <<EOF &&
111* (HEAD detached from $(git rev-parse --short HEAD))
112 branch-one
113 branch-two
114 master
115EOF
116 git reset --hard HEAD^1 &&
117 git branch >actual &&
118 test_i18ncmp expect actual
119'
120
121test_expect_success 'git branch shows detached HEAD properly from tag' '
122 cat >expect <<EOF &&
123* (HEAD detached at fromtag)
124 branch-one
125 branch-two
126 master
127EOF
128 git tag fromtag master &&
129 git checkout fromtag &&
130 git branch >actual &&
131 test_i18ncmp expect actual
132'
133
134test_expect_success 'git branch shows detached HEAD properly after moving from tag' '
135 cat >expect <<EOF &&
136* (HEAD detached from fromtag)
137 branch-one
138 branch-two
139 master
140EOF
141 git reset --hard HEAD^1 &&
142 git branch >actual &&
143 test_i18ncmp expect actual
144'
145
aedcb7dc
KN
146test_expect_success 'git branch `--sort` option' '
147 cat >expect <<-\EOF &&
148 branch-two
149 * (HEAD detached from fromtag)
150 branch-one
151 master
152 EOF
153 git branch --sort=objectsize >actual &&
154 test_i18ncmp expect actual
155'
156
0afc3044 157test_done