]>
Commit | Line | Data |
---|---|---|
ce567d18 JS |
1 | #!/bin/sh |
2 | ||
4f5ce122 | 3 | test_description='test show-branch' |
ce567d18 JS |
4 | |
5 | . ./test-lib.sh | |
6 | ||
f2463490 HWN |
7 | # arbitrary reference time: 2009-08-30 19:20:00 |
8 | GIT_TEST_DATE_NOW=1251660000; export GIT_TEST_DATE_NOW | |
9 | ||
bcfc82bd RJ |
10 | test_expect_success 'error descriptions on empty repository' ' |
11 | current=$(git branch --show-current) && | |
12 | cat >expect <<-EOF && | |
12b99928 | 13 | error: no commit on branch '\''$current'\'' yet |
bcfc82bd RJ |
14 | EOF |
15 | test_must_fail git branch --edit-description 2>actual && | |
16 | test_cmp expect actual && | |
17 | test_must_fail git branch --edit-description $current 2>actual && | |
18 | test_cmp expect actual | |
19 | ' | |
20 | ||
21 | test_expect_success 'fatal descriptions on empty repository' ' | |
22 | current=$(git branch --show-current) && | |
23 | cat >expect <<-EOF && | |
12b99928 | 24 | fatal: no commit on branch '\''$current'\'' yet |
bcfc82bd RJ |
25 | EOF |
26 | test_must_fail git branch --set-upstream-to=non-existent 2>actual && | |
27 | test_cmp expect actual && | |
28 | test_must_fail git branch -c new-branch 2>actual && | |
29 | test_cmp expect actual | |
30 | ' | |
31 | ||
ce567d18 | 32 | test_expect_success 'setup' ' |
9b6e74a9 ÆAB |
33 | test_commit initial && |
34 | for i in $(test_seq 1 10) | |
ce567d18 | 35 | do |
9b6e74a9 | 36 | git checkout -b branch$i initial && |
db5875aa | 37 | test_commit --no-tag branch$i || return 1 |
9b6e74a9 ÆAB |
38 | done && |
39 | git for-each-ref \ | |
40 | --sort=version:refname \ | |
41 | --format="%(refname:strip=2)" \ | |
42 | "refs/heads/branch*" >branches.sorted && | |
43 | sed "s/^> //" >expect <<-\EOF | |
44 | > ! [branch1] branch1 | |
45 | > ! [branch2] branch2 | |
46 | > ! [branch3] branch3 | |
47 | > ! [branch4] branch4 | |
48 | > ! [branch5] branch5 | |
49 | > ! [branch6] branch6 | |
50 | > ! [branch7] branch7 | |
51 | > ! [branch8] branch8 | |
52 | > ! [branch9] branch9 | |
53 | > * [branch10] branch10 | |
54 | > ---------- | |
55 | > * [branch10] branch10 | |
56 | > + [branch9] branch9 | |
57 | > + [branch8] branch8 | |
58 | > + [branch7] branch7 | |
59 | > + [branch6] branch6 | |
60 | > + [branch5] branch5 | |
61 | > + [branch4] branch4 | |
62 | > + [branch3] branch3 | |
63 | > + [branch2] branch2 | |
64 | > + [branch1] branch1 | |
65 | > +++++++++* [branch10^] initial | |
66 | EOF | |
ce567d18 JS |
67 | ' |
68 | ||
e358f3c3 | 69 | test_expect_success 'show-branch with more than 8 branches' ' |
9b6e74a9 ÆAB |
70 | git show-branch $(cat branches.sorted) >actual && |
71 | test_cmp expect actual | |
ce567d18 JS |
72 | ' |
73 | ||
3af1cae4 | 74 | test_expect_success 'show-branch with showbranch.default' ' |
9b6e74a9 ÆAB |
75 | for branch in $(cat branches.sorted) |
76 | do | |
db5875aa | 77 | test_config showbranch.default $branch --add || return 1 |
3af1cae4 | 78 | done && |
9b6e74a9 ÆAB |
79 | git show-branch >actual && |
80 | test_cmp expect actual | |
3af1cae4 JH |
81 | ' |
82 | ||
4465690c ÆAB |
83 | test_expect_success 'show-branch --color output' ' |
84 | sed "s/^> //" >expect <<-\EOF && | |
85 | > <RED>!<RESET> [branch1] branch1 | |
86 | > <GREEN>!<RESET> [branch2] branch2 | |
87 | > <YELLOW>!<RESET> [branch3] branch3 | |
88 | > <BLUE>!<RESET> [branch4] branch4 | |
89 | > <MAGENTA>!<RESET> [branch5] branch5 | |
90 | > <CYAN>!<RESET> [branch6] branch6 | |
91 | > <BOLD;RED>!<RESET> [branch7] branch7 | |
92 | > <BOLD;GREEN>!<RESET> [branch8] branch8 | |
93 | > <BOLD;YELLOW>!<RESET> [branch9] branch9 | |
94 | > <BOLD;BLUE>*<RESET> [branch10] branch10 | |
95 | > ---------- | |
96 | > <BOLD;BLUE>*<RESET> [branch10] branch10 | |
97 | > <BOLD;YELLOW>+<RESET> [branch9] branch9 | |
98 | > <BOLD;GREEN>+<RESET> [branch8] branch8 | |
99 | > <BOLD;RED>+<RESET> [branch7] branch7 | |
100 | > <CYAN>+<RESET> [branch6] branch6 | |
101 | > <MAGENTA>+<RESET> [branch5] branch5 | |
102 | > <BLUE>+<RESET> [branch4] branch4 | |
103 | > <YELLOW>+<RESET> [branch3] branch3 | |
104 | > <GREEN>+<RESET> [branch2] branch2 | |
105 | > <RED>+<RESET> [branch1] branch1 | |
106 | > <RED>+<RESET><GREEN>+<RESET><YELLOW>+<RESET><BLUE>+<RESET><MAGENTA>+<RESET><CYAN>+<RESET><BOLD;RED>+<RESET><BOLD;GREEN>+<RESET><BOLD;YELLOW>+<RESET><BOLD;BLUE>*<RESET> [branch10^] initial | |
107 | EOF | |
108 | git show-branch --color=always $(cat branches.sorted) >actual.raw && | |
109 | test_decode_color <actual.raw >actual && | |
110 | test_cmp expect actual | |
111 | ' | |
112 | ||
d65aea37 ÆAB |
113 | test_expect_success 'show branch --remotes' ' |
114 | cat >expect.err <<-\EOF && | |
115 | No revs to be shown. | |
116 | EOF | |
117 | git show-branch -r 2>actual.err >actual.out && | |
118 | test_cmp expect.err actual.err && | |
119 | test_must_be_empty actual.out | |
120 | ' | |
121 | ||
83bb8e5a JH |
122 | test_expect_success 'show-branch --sparse' ' |
123 | test_when_finished "git checkout branch10 && git branch -D branchA" && | |
124 | git checkout -b branchA branch10 && | |
125 | git merge -s ours -m "merge 1 and 10 to make A" branch1 && | |
126 | git commit --allow-empty -m "another" && | |
127 | ||
128 | git show-branch --sparse >out && | |
129 | grep "merge 1 and 10 to make A" out && | |
130 | ||
131 | git show-branch >out && | |
132 | ! grep "merge 1 and 10 to make A" out && | |
133 | ||
134 | git show-branch --no-sparse >out && | |
135 | ! grep "merge 1 and 10 to make A" out | |
136 | ' | |
137 | ||
d65aea37 ÆAB |
138 | test_expect_success 'setup show branch --list' ' |
139 | sed "s/^> //" >expect <<-\EOF | |
140 | > [branch1] branch1 | |
141 | > [branch2] branch2 | |
142 | > [branch3] branch3 | |
143 | > [branch4] branch4 | |
144 | > [branch5] branch5 | |
145 | > [branch6] branch6 | |
146 | > [branch7] branch7 | |
147 | > [branch8] branch8 | |
148 | > [branch9] branch9 | |
149 | > * [branch10] branch10 | |
150 | EOF | |
151 | ' | |
152 | ||
153 | test_expect_success 'show branch --list' ' | |
154 | git show-branch --list $(cat branches.sorted) >actual && | |
155 | test_cmp expect actual | |
156 | ' | |
157 | ||
158 | test_expect_success 'show branch --list has no --color output' ' | |
159 | git show-branch --color=always --list $(cat branches.sorted) >actual && | |
160 | test_cmp expect actual | |
161 | ' | |
162 | ||
163 | test_expect_success 'show branch --merge-base with one argument' ' | |
164 | for branch in $(cat branches.sorted) | |
165 | do | |
166 | git rev-parse $branch >expect && | |
167 | git show-branch --merge-base $branch >actual && | |
db5875aa | 168 | test_cmp expect actual || return 1 |
d65aea37 ÆAB |
169 | done |
170 | ' | |
171 | ||
172 | test_expect_success 'show branch --merge-base with two arguments' ' | |
173 | for branch in $(cat branches.sorted) | |
174 | do | |
175 | git rev-parse initial >expect && | |
176 | git show-branch --merge-base initial $branch >actual && | |
db5875aa | 177 | test_cmp expect actual || return 1 |
d65aea37 ÆAB |
178 | done |
179 | ' | |
180 | ||
181 | test_expect_success 'show branch --merge-base with N arguments' ' | |
182 | git rev-parse initial >expect && | |
183 | git show-branch --merge-base $(cat branches.sorted) >actual && | |
184 | test_cmp expect actual && | |
185 | ||
186 | git merge-base $(cat branches.sorted) >actual && | |
187 | test_cmp expect actual | |
188 | ' | |
189 | ||
f2463490 HWN |
190 | test_expect_success 'show branch --reflog=2' ' |
191 | sed "s/^> //" >expect <<-\EOF && | |
192 | > ! [refs/heads/branch10@{0}] (4 years, 5 months ago) commit: branch10 | |
193 | > ! [refs/heads/branch10@{1}] (4 years, 5 months ago) commit: branch10 | |
194 | > -- | |
195 | > + [refs/heads/branch10@{0}] branch10 | |
196 | > ++ [refs/heads/branch10@{1}] initial | |
197 | EOF | |
198 | git show-branch --reflog=2 >actual && | |
199 | test_cmp actual expect | |
200 | ' | |
201 | ||
41c64ae0 JH |
202 | # incompatible options |
203 | while read combo | |
204 | do | |
205 | test_expect_success "show-branch $combo (should fail)" ' | |
206 | test_must_fail git show-branch $combo 2>error && | |
207 | grep -e "cannot be used together" -e "usage:" error | |
208 | ' | |
209 | done <<\EOF | |
210 | --all --reflog | |
211 | --merge-base --reflog | |
212 | --list --merge-base | |
213 | --reflog --current | |
214 | EOF | |
215 | ||
68cbb20e JH |
216 | # unnegatable options |
217 | for opt in topo-order date-order reflog | |
218 | do | |
219 | test_expect_success "show-branch --no-$opt (should fail)" ' | |
220 | test_must_fail git show-branch --no-$opt 2>err && | |
221 | grep "unknown option .no-$opt." err | |
222 | ' | |
223 | done | |
224 | ||
bcfc82bd RJ |
225 | test_expect_success 'error descriptions on non-existent branch' ' |
226 | cat >expect <<-EOF && | |
12b99928 | 227 | error: no branch named '\''non-existent'\'' |
bcfc82bd RJ |
228 | EOF |
229 | test_must_fail git branch --edit-description non-existent 2>actual && | |
230 | test_cmp expect actual | |
231 | ' | |
232 | ||
233 | test_expect_success 'fatal descriptions on non-existent branch' ' | |
234 | cat >expect <<-EOF && | |
235 | fatal: branch '\''non-existent'\'' does not exist | |
236 | EOF | |
237 | test_must_fail git branch --set-upstream-to=non-existent non-existent 2>actual && | |
238 | test_cmp expect actual && | |
239 | ||
240 | cat >expect <<-EOF && | |
12b99928 | 241 | fatal: no branch named '\''non-existent'\'' |
bcfc82bd RJ |
242 | EOF |
243 | test_must_fail git branch -c non-existent new-branch 2>actual && | |
244 | test_cmp expect actual && | |
245 | test_must_fail git branch -m non-existent new-branch 2>actual && | |
246 | test_cmp expect actual | |
247 | ' | |
248 | ||
7a6ccdfb RJ |
249 | test_expect_success 'error descriptions on orphan branch' ' |
250 | test_when_finished git worktree remove -f wt && | |
251 | git worktree add wt --detach && | |
252 | git -C wt checkout --orphan orphan-branch && | |
253 | test_branch_op_in_wt() { | |
254 | test_orphan_error() { | |
255 | test_must_fail git $* 2>actual && | |
a8e23947 | 256 | test_grep "no commit on branch .orphan-branch. yet$" actual |
7a6ccdfb RJ |
257 | } && |
258 | test_orphan_error -C wt branch $1 $2 && # implicit branch | |
259 | test_orphan_error -C wt branch $1 orphan-branch $2 && # explicit branch | |
260 | test_orphan_error branch $1 orphan-branch $2 # different worktree | |
261 | } && | |
262 | test_branch_op_in_wt --edit-description && | |
263 | test_branch_op_in_wt --set-upstream-to=ne && | |
264 | test_branch_op_in_wt -c new-branch | |
265 | ' | |
266 | ||
ce567d18 | 267 | test_done |