@@ -129,7 +129,8 @@ impl Component for BranchListComponent {
129
129
strings:: commands:: select_branch_popup (
130
130
& self . key_config ,
131
131
) ,
132
- !self . selection_is_cur_branch ( ) ,
132
+ !self . selection_is_cur_branch ( )
133
+ && self . valid_selection ( ) ,
133
134
true ,
134
135
) ) ;
135
136
@@ -179,12 +180,16 @@ impl Component for BranchListComponent {
179
180
"switch branch error:" ,
180
181
self . switch_to_selected_branch( )
181
182
) ;
182
- } else if e == self . key_config . create_branch {
183
+ } else if e == self . key_config . create_branch
184
+ && self . local
185
+ {
183
186
self . queue
184
187
. borrow_mut ( )
185
188
. push_back ( InternalEvent :: CreateBranch ) ;
186
189
self . hide ( ) ;
187
- } else if e == self . key_config . rename_branch {
190
+ } else if e == self . key_config . rename_branch
191
+ && self . valid_selection ( )
192
+ {
188
193
let cur_branch =
189
194
& self . branches [ self . selection as usize ] ;
190
195
self . queue . borrow_mut ( ) . push_back (
@@ -197,6 +202,7 @@ impl Component for BranchListComponent {
197
202
self . update_branches ( ) ?;
198
203
} else if e == self . key_config . delete_branch
199
204
&& !self . selection_is_cur_branch ( )
205
+ && self . valid_selection ( )
200
206
{
201
207
self . queue . borrow_mut ( ) . push_back (
202
208
InternalEvent :: ConfirmAction (
@@ -276,6 +282,10 @@ impl BranchListComponent {
276
282
Ok ( ( ) )
277
283
}
278
284
285
+ fn valid_selection ( & self ) -> bool {
286
+ !self . branches . is_empty ( )
287
+ }
288
+
279
289
fn selection_is_cur_branch ( & self ) -> bool {
280
290
self . branches
281
291
. iter ( )
@@ -433,6 +443,10 @@ impl BranchListComponent {
433
443
434
444
///
435
445
fn switch_to_selected_branch ( & mut self ) -> Result < ( ) > {
446
+ if !self . valid_selection ( ) {
447
+ anyhow:: bail!( "no valid branch selected" ) ;
448
+ }
449
+
436
450
if self . local {
437
451
checkout_branch (
438
452
asyncgit:: CWD ,
0 commit comments