Start the 2.46 cycle
[git.git] / t / t3202-show-branch.sh
bloba1139f79e2ccfdff2b562571bdd8bdf8aa974883
1 #!/bin/sh
3 test_description='test show-branch'
5 . ./test-lib.sh
7 test_expect_success 'error descriptions on empty repository' '
8 current=$(git branch --show-current) &&
9 cat >expect <<-EOF &&
10 error: no commit on branch '\''$current'\'' yet
11 EOF
12 test_must_fail git branch --edit-description 2>actual &&
13 test_cmp expect actual &&
14 test_must_fail git branch --edit-description $current 2>actual &&
15 test_cmp expect actual
18 test_expect_success 'fatal descriptions on empty repository' '
19 current=$(git branch --show-current) &&
20 cat >expect <<-EOF &&
21 fatal: no commit on branch '\''$current'\'' yet
22 EOF
23 test_must_fail git branch --set-upstream-to=non-existent 2>actual &&
24 test_cmp expect actual &&
25 test_must_fail git branch -c new-branch 2>actual &&
26 test_cmp expect actual
29 test_expect_success 'setup' '
30 test_commit initial &&
31 for i in $(test_seq 1 10)
33 git checkout -b branch$i initial &&
34 test_commit --no-tag branch$i || return 1
35 done &&
36 git for-each-ref \
37 --sort=version:refname \
38 --format="%(refname:strip=2)" \
39 "refs/heads/branch*" >branches.sorted &&
40 sed "s/^> //" >expect <<-\EOF
41 > ! [branch1] branch1
42 > ! [branch2] branch2
43 > ! [branch3] branch3
44 > ! [branch4] branch4
45 > ! [branch5] branch5
46 > ! [branch6] branch6
47 > ! [branch7] branch7
48 > ! [branch8] branch8
49 > ! [branch9] branch9
50 > * [branch10] branch10
51 > ----------
52 > * [branch10] branch10
53 > + [branch9] branch9
54 > + [branch8] branch8
55 > + [branch7] branch7
56 > + [branch6] branch6
57 > + [branch5] branch5
58 > + [branch4] branch4
59 > + [branch3] branch3
60 > + [branch2] branch2
61 > + [branch1] branch1
62 > +++++++++* [branch10^] initial
63 EOF
66 test_expect_success 'show-branch with more than 8 branches' '
67 git show-branch $(cat branches.sorted) >actual &&
68 test_cmp expect actual
71 test_expect_success 'show-branch with showbranch.default' '
72 for branch in $(cat branches.sorted)
74 test_config showbranch.default $branch --add || return 1
75 done &&
76 git show-branch >actual &&
77 test_cmp expect actual
80 test_expect_success 'show-branch --color output' '
81 sed "s/^> //" >expect <<-\EOF &&
82 > <RED>!<RESET> [branch1] branch1
83 > <GREEN>!<RESET> [branch2] branch2
84 > <YELLOW>!<RESET> [branch3] branch3
85 > <BLUE>!<RESET> [branch4] branch4
86 > <MAGENTA>!<RESET> [branch5] branch5
87 > <CYAN>!<RESET> [branch6] branch6
88 > <BOLD;RED>!<RESET> [branch7] branch7
89 > <BOLD;GREEN>!<RESET> [branch8] branch8
90 > <BOLD;YELLOW>!<RESET> [branch9] branch9
91 > <BOLD;BLUE>*<RESET> [branch10] branch10
92 > ----------
93 > <BOLD;BLUE>*<RESET> [branch10] branch10
94 > <BOLD;YELLOW>+<RESET> [branch9] branch9
95 > <BOLD;GREEN>+<RESET> [branch8] branch8
96 > <BOLD;RED>+<RESET> [branch7] branch7
97 > <CYAN>+<RESET> [branch6] branch6
98 > <MAGENTA>+<RESET> [branch5] branch5
99 > <BLUE>+<RESET> [branch4] branch4
100 > <YELLOW>+<RESET> [branch3] branch3
101 > <GREEN>+<RESET> [branch2] branch2
102 > <RED>+<RESET> [branch1] branch1
103 > <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
105 git show-branch --color=always $(cat branches.sorted) >actual.raw &&
106 test_decode_color <actual.raw >actual &&
107 test_cmp expect actual
110 test_expect_success 'show branch --remotes' '
111 cat >expect.err <<-\EOF &&
112 No revs to be shown.
114 git show-branch -r 2>actual.err >actual.out &&
115 test_cmp expect.err actual.err &&
116 test_must_be_empty actual.out
119 test_expect_success 'show-branch --sparse' '
120 test_when_finished "git checkout branch10 && git branch -D branchA" &&
121 git checkout -b branchA branch10 &&
122 git merge -s ours -m "merge 1 and 10 to make A" branch1 &&
123 git commit --allow-empty -m "another" &&
125 git show-branch --sparse >out &&
126 grep "merge 1 and 10 to make A" out &&
128 git show-branch >out &&
129 ! grep "merge 1 and 10 to make A" out &&
131 git show-branch --no-sparse >out &&
132 ! grep "merge 1 and 10 to make A" out
135 test_expect_success 'setup show branch --list' '
136 sed "s/^> //" >expect <<-\EOF
137 > [branch1] branch1
138 > [branch2] branch2
139 > [branch3] branch3
140 > [branch4] branch4
141 > [branch5] branch5
142 > [branch6] branch6
143 > [branch7] branch7
144 > [branch8] branch8
145 > [branch9] branch9
146 > * [branch10] branch10
150 test_expect_success 'show branch --list' '
151 git show-branch --list $(cat branches.sorted) >actual &&
152 test_cmp expect actual
155 test_expect_success 'show branch --list has no --color output' '
156 git show-branch --color=always --list $(cat branches.sorted) >actual &&
157 test_cmp expect actual
160 test_expect_success 'show branch --merge-base with one argument' '
161 for branch in $(cat branches.sorted)
163 git rev-parse $branch >expect &&
164 git show-branch --merge-base $branch >actual &&
165 test_cmp expect actual || return 1
166 done
169 test_expect_success 'show branch --merge-base with two arguments' '
170 for branch in $(cat branches.sorted)
172 git rev-parse initial >expect &&
173 git show-branch --merge-base initial $branch >actual &&
174 test_cmp expect actual || return 1
175 done
178 test_expect_success 'show branch --merge-base with N arguments' '
179 git rev-parse initial >expect &&
180 git show-branch --merge-base $(cat branches.sorted) >actual &&
181 test_cmp expect actual &&
183 git merge-base $(cat branches.sorted) >actual &&
184 test_cmp expect actual
187 # incompatible options
188 while read combo
190 test_expect_success "show-branch $combo (should fail)" '
191 test_must_fail git show-branch $combo 2>error &&
192 grep -e "cannot be used together" -e "usage:" error
194 done <<\EOF
195 --all --reflog
196 --merge-base --reflog
197 --list --merge-base
198 --reflog --current
201 # unnegatable options
202 for opt in topo-order date-order reflog
204 test_expect_success "show-branch --no-$opt (should fail)" '
205 test_must_fail git show-branch --no-$opt 2>err &&
206 grep "unknown option .no-$opt." err
208 done
210 test_expect_success 'error descriptions on non-existent branch' '
211 cat >expect <<-EOF &&
212 error: no branch named '\''non-existent'\''
214 test_must_fail git branch --edit-description non-existent 2>actual &&
215 test_cmp expect actual
218 test_expect_success 'fatal descriptions on non-existent branch' '
219 cat >expect <<-EOF &&
220 fatal: branch '\''non-existent'\'' does not exist
222 test_must_fail git branch --set-upstream-to=non-existent non-existent 2>actual &&
223 test_cmp expect actual &&
225 cat >expect <<-EOF &&
226 fatal: no branch named '\''non-existent'\''
228 test_must_fail git branch -c non-existent new-branch 2>actual &&
229 test_cmp expect actual &&
230 test_must_fail git branch -m non-existent new-branch 2>actual &&
231 test_cmp expect actual
234 test_expect_success 'error descriptions on orphan branch' '
235 test_when_finished git worktree remove -f wt &&
236 git worktree add wt --detach &&
237 git -C wt checkout --orphan orphan-branch &&
238 test_branch_op_in_wt() {
239 test_orphan_error() {
240 test_must_fail git $* 2>actual &&
241 test_grep "no commit on branch .orphan-branch. yet$" actual
242 } &&
243 test_orphan_error -C wt branch $1 $2 && # implicit branch
244 test_orphan_error -C wt branch $1 orphan-branch $2 && # explicit branch
245 test_orphan_error branch $1 orphan-branch $2 # different worktree
246 } &&
247 test_branch_op_in_wt --edit-description &&
248 test_branch_op_in_wt --set-upstream-to=ne &&
249 test_branch_op_in_wt -c new-branch
252 test_expect_success 'setup reflogs' '
253 test_commit base &&
254 git checkout -b branch &&
255 test_commit one &&
256 git reset --hard HEAD^ &&
257 test_commit two &&
258 test_commit three
261 test_expect_success '--reflog shows reflog entries' '
262 cat >expect <<-\EOF &&
263 ! [branch@{0}] (0 seconds ago) commit: three
264 ! [branch@{1}] (60 seconds ago) commit: two
265 ! [branch@{2}] (2 minutes ago) reset: moving to HEAD^
266 ! [branch@{3}] (2 minutes ago) commit: one
267 ----
268 + [branch@{0}] three
269 ++ [branch@{1}] two
270 + [branch@{3}] one
271 ++++ [branch@{2}] base
273 # the output always contains relative timestamps; use
274 # a known time to get deterministic results
275 GIT_TEST_DATE_NOW=$test_tick \
276 git show-branch --reflog branch >actual &&
277 test_cmp expect actual
280 test_expect_success '--reflog handles missing reflog' '
281 git reflog expire --expire=now branch &&
282 git show-branch --reflog branch >actual &&
283 test_must_be_empty actual
286 test_done