diff --git a/CHANGELOG.md b/CHANGELOG.md index ec739617..683fd440 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - fetch crashed when no upstream of branch is set ([#637](https://github.com/extrawurst/gitui/issues/637)) +- `enter` key panics in empty remote branch list ([#643](https://github.com/extrawurst/gitui/issues/643)) ## [0.14.0] - 2020-04-11 diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs index 7fa04bec..f0ce89bc 100644 --- a/src/components/branchlist.rs +++ b/src/components/branchlist.rs @@ -129,7 +129,8 @@ impl Component for BranchListComponent { strings::commands::select_branch_popup( &self.key_config, ), - !self.selection_is_cur_branch(), + !self.selection_is_cur_branch() + && self.valid_selection(), true, )); @@ -179,12 +180,16 @@ impl Component for BranchListComponent { "switch branch error:", self.switch_to_selected_branch() ); - } else if e == self.key_config.create_branch { + } else if e == self.key_config.create_branch + && self.local + { self.queue .borrow_mut() .push_back(InternalEvent::CreateBranch); self.hide(); - } else if e == self.key_config.rename_branch { + } else if e == self.key_config.rename_branch + && self.valid_selection() + { let cur_branch = &self.branches[self.selection as usize]; self.queue.borrow_mut().push_back( @@ -197,6 +202,7 @@ impl Component for BranchListComponent { self.update_branches()?; } else if e == self.key_config.delete_branch && !self.selection_is_cur_branch() + && self.valid_selection() { self.queue.borrow_mut().push_back( InternalEvent::ConfirmAction( @@ -276,6 +282,10 @@ impl BranchListComponent { Ok(()) } + fn valid_selection(&self) -> bool { + !self.branches.is_empty() + } + fn selection_is_cur_branch(&self) -> bool { self.branches .iter() @@ -433,6 +443,10 @@ impl BranchListComponent { /// fn switch_to_selected_branch(&mut self) -> Result<()> { + if !self.valid_selection() { + anyhow::bail!("no valid branch selected"); + } + if self.local { checkout_branch( asyncgit::CWD,