fix empty branch list enter key still accepted and panics

This commit is contained in:
Stephan Dilly 2021-04-14 21:52:25 +02:00
parent b1e7b1381f
commit f7a17fa3bb
2 changed files with 18 additions and 3 deletions

View file

@ -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

View file

@ -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,