3 test_description
='test show-branch'
7 # arbitrary reference time: 2009-08-30 19:20:00
8 GIT_TEST_DATE_NOW
=1251660000; export GIT_TEST_DATE_NOW
10 test_expect_success
'error descriptions on empty repository' '
11 current=$(git branch --show-current) &&
13 error: No commit on branch '\''$current'\'' yet.
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
21 test_expect_success
'fatal descriptions on empty repository' '
22 current=$(git branch --show-current) &&
24 fatal: No commit on branch '\''$current'\'' yet.
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
32 test_expect_success
'setup' '
33 test_commit initial &&
34 for i in $(test_seq 1 10)
36 git checkout -b branch$i initial &&
37 test_commit --no-tag branch$i || return 1
40 --sort=version:refname \
41 --format="%(refname:strip=2)" \
42 "refs/heads/branch*" >branches.sorted &&
43 sed "s/^> //" >expect <<-\EOF
53 > * [branch10] branch10
55 > * [branch10] branch10
65 > +++++++++* [branch10^] initial
69 test_expect_success
'show-branch with more than 8 branches' '
70 git show-branch $(cat branches.sorted) >actual &&
71 test_cmp expect actual
74 test_expect_success
'show-branch with showbranch.default' '
75 for branch in $(cat branches.sorted)
77 test_config showbranch.default $branch --add || return 1
79 git show-branch >actual &&
80 test_cmp expect actual
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
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
108 git show-branch --color=always $(cat branches.sorted) >actual.raw &&
109 test_decode_color <actual.raw >actual &&
110 test_cmp expect actual
113 test_expect_success
'show branch --remotes' '
114 cat >expect.err <<-\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
122 test_expect_success
'setup show branch --list' '
123 sed "s/^> //" >expect <<-\EOF
133 > * [branch10] branch10
137 test_expect_success
'show branch --list' '
138 git show-branch --list $(cat branches.sorted) >actual &&
139 test_cmp expect actual
142 test_expect_success
'show branch --list has no --color output' '
143 git show-branch --color=always --list $(cat branches.sorted) >actual &&
144 test_cmp expect actual
147 test_expect_success
'show branch --merge-base with one argument' '
148 for branch in $(cat branches.sorted)
150 git rev-parse $branch >expect &&
151 git show-branch --merge-base $branch >actual &&
152 test_cmp expect actual || return 1
156 test_expect_success
'show branch --merge-base with two arguments' '
157 for branch in $(cat branches.sorted)
159 git rev-parse initial >expect &&
160 git show-branch --merge-base initial $branch >actual &&
161 test_cmp expect actual || return 1
165 test_expect_success
'show branch --merge-base with N arguments' '
166 git rev-parse initial >expect &&
167 git show-branch --merge-base $(cat branches.sorted) >actual &&
168 test_cmp expect actual &&
170 git merge-base $(cat branches.sorted) >actual &&
171 test_cmp expect actual
174 test_expect_success
'show branch --reflog=2' '
175 sed "s/^> //" >expect <<-\EOF &&
176 > ! [refs/heads/branch10@{0}] (4 years, 5 months ago) commit: branch10
177 > ! [refs/heads/branch10@{1}] (4 years, 5 months ago) commit: branch10
179 > + [refs/heads/branch10@{0}] branch10
180 > ++ [refs/heads/branch10@{1}] initial
182 git show-branch --reflog=2 >actual &&
183 test_cmp actual expect
186 # incompatible options
189 test_expect_success
"show-branch $combo (should fail)" '
190 test_must_fail git show-branch $combo 2>error &&
191 grep -e "cannot be used together" -e "usage:" error
195 --merge-base --reflog
200 test_expect_success
'error descriptions on non-existent branch' '
201 cat >expect <<-EOF &&
202 error: No branch named '\''non-existent'\'.
'
204 test_must_fail git branch --edit-description non-existent 2>actual &&
205 test_cmp expect actual
208 test_expect_success
'fatal descriptions on non-existent branch' '
209 cat >expect <<-EOF &&
210 fatal: branch '\''non-existent'\'' does not exist
212 test_must_fail git branch --set-upstream-to=non-existent non-existent 2>actual &&
213 test_cmp expect actual &&
215 cat >expect <<-EOF &&
216 fatal: No branch named '\''non-existent'\''.
218 test_must_fail git branch -c non-existent new-branch 2>actual &&
219 test_cmp expect actual &&
220 test_must_fail git branch -m non-existent new-branch 2>actual &&
221 test_cmp expect actual
224 test_expect_success
'error descriptions on orphan branch' '
225 test_when_finished git worktree remove -f wt &&
226 git worktree add wt --detach &&
227 git -C wt checkout --orphan orphan-branch &&
228 test_branch_op_in_wt() {
229 test_orphan_error() {
230 test_must_fail git $* 2>actual &&
231 test_i18ngrep "No commit on branch .orphan-branch. yet.$" actual
233 test_orphan_error -C wt branch $1 $2 && # implicit branch
234 test_orphan_error -C wt branch $1 orphan-branch $2 && # explicit branch
235 test_orphan_error branch $1 orphan-branch $2 # different worktree
237 test_branch_op_in_wt --edit-description &&
238 test_branch_op_in_wt --set-upstream-to=ne &&
239 test_branch_op_in_wt -c new-branch