Skip to content

Commit f7a17fa

Browse files
author
Stephan Dilly
committed
fix empty branch list enter key still accepted and panics
1 parent b1e7b13 commit f7a17fa

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- fetch crashed when no upstream of branch is set ([#637](https://github.com/extrawurst/gitui/issues/637))
12+
- `enter` key panics in empty remote branch list ([#643](https://github.com/extrawurst/gitui/issues/643))
1213

1314
## [0.14.0] - 2020-04-11
1415

src/components/branchlist.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ impl Component for BranchListComponent {
129129
strings::commands::select_branch_popup(
130130
&self.key_config,
131131
),
132-
!self.selection_is_cur_branch(),
132+
!self.selection_is_cur_branch()
133+
&& self.valid_selection(),
133134
true,
134135
));
135136

@@ -179,12 +180,16 @@ impl Component for BranchListComponent {
179180
"switch branch error:",
180181
self.switch_to_selected_branch()
181182
);
182-
} else if e == self.key_config.create_branch {
183+
} else if e == self.key_config.create_branch
184+
&& self.local
185+
{
183186
self.queue
184187
.borrow_mut()
185188
.push_back(InternalEvent::CreateBranch);
186189
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+
{
188193
let cur_branch =
189194
&self.branches[self.selection as usize];
190195
self.queue.borrow_mut().push_back(
@@ -197,6 +202,7 @@ impl Component for BranchListComponent {
197202
self.update_branches()?;
198203
} else if e == self.key_config.delete_branch
199204
&& !self.selection_is_cur_branch()
205+
&& self.valid_selection()
200206
{
201207
self.queue.borrow_mut().push_back(
202208
InternalEvent::ConfirmAction(
@@ -276,6 +282,10 @@ impl BranchListComponent {
276282
Ok(())
277283
}
278284

285+
fn valid_selection(&self) -> bool {
286+
!self.branches.is_empty()
287+
}
288+
279289
fn selection_is_cur_branch(&self) -> bool {
280290
self.branches
281291
.iter()
@@ -433,6 +443,10 @@ impl BranchListComponent {
433443

434444
///
435445
fn switch_to_selected_branch(&mut self) -> Result<()> {
446+
if !self.valid_selection() {
447+
anyhow::bail!("no valid branch selected");
448+
}
449+
436450
if self.local {
437451
checkout_branch(
438452
asyncgit::CWD,

0 commit comments

Comments
 (0)