mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
don't close branchlist every time (#550)
* do not close branchlist after branch rename * do not close branchlist after deleting a branch * closes #543
This commit is contained in:
parent
dc3775caa2
commit
8d4c1ca26e
7 changed files with 57 additions and 57 deletions
|
|
@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||

|

|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
- don't close branchlist every time ([#550](https://github.com/extrawurst/gitui/issues/550))
|
||||||
- fixed key binding for *external exitor* in vim key bindings [[@yanganto](https://github.com/yanganto)] ([#549](https://github.com/extrawurst/gitui/issues/549))
|
- fixed key binding for *external exitor* in vim key bindings [[@yanganto](https://github.com/yanganto)] ([#549](https://github.com/extrawurst/gitui/issues/549))
|
||||||
- fix some potential errors when deleting files while they are being diffed ([#490](https://github.com/extrawurst/gitui/issues/490))
|
- fix some potential errors when deleting files while they are being diffed ([#490](https://github.com/extrawurst/gitui/issues/490))
|
||||||
- push defaults to 'origin' remote if it exists ([#494](https://github.com/extrawurst/gitui/issues/494))
|
- push defaults to 'origin' remote if it exists ([#494](https://github.com/extrawurst/gitui/issues/494))
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ pub(crate) fn get_branch_name(repo_path: &str) -> Result<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
pub struct BranchForDisplay {
|
pub struct BranchInfo {
|
||||||
///
|
///
|
||||||
pub name: String,
|
pub name: String,
|
||||||
///
|
///
|
||||||
|
|
@ -48,12 +48,9 @@ pub struct BranchForDisplay {
|
||||||
pub has_upstream: bool,
|
pub has_upstream: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to return only the nessessary information for displaying a branch
|
/// returns a list of `BranchInfo` with a simple summary of info about a single branch
|
||||||
/// rather than an iterator over the actual branches
|
pub fn get_branches_info(repo_path: &str) -> Result<Vec<BranchInfo>> {
|
||||||
pub fn get_branches_to_display(
|
scope_time!("get_branches_info");
|
||||||
repo_path: &str,
|
|
||||||
) -> Result<Vec<BranchForDisplay>> {
|
|
||||||
scope_time!("get_branches_to_display");
|
|
||||||
|
|
||||||
let cur_repo = utils::repo(repo_path)?;
|
let cur_repo = utils::repo(repo_path)?;
|
||||||
let branches_for_display = cur_repo
|
let branches_for_display = cur_repo
|
||||||
|
|
@ -62,7 +59,7 @@ pub fn get_branches_to_display(
|
||||||
let branch = b?.0;
|
let branch = b?.0;
|
||||||
let top_commit = branch.get().peel_to_commit()?;
|
let top_commit = branch.get().peel_to_commit()?;
|
||||||
|
|
||||||
Ok(BranchForDisplay {
|
Ok(BranchInfo {
|
||||||
name: bytes2string(branch.name_bytes()?)?,
|
name: bytes2string(branch.name_bytes()?)?,
|
||||||
reference: bytes2string(branch.get().name_bytes())?,
|
reference: bytes2string(branch.get().name_bytes())?,
|
||||||
top_commit_message: bytes2string(
|
top_commit_message: bytes2string(
|
||||||
|
|
@ -299,7 +296,7 @@ mod tests_branches {
|
||||||
let repo_path = root.as_os_str().to_str().unwrap();
|
let repo_path = root.as_os_str().to_str().unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_branches_to_display(repo_path)
|
get_branches_info(repo_path)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|b| b.name.clone())
|
.map(|b| b.name.clone())
|
||||||
|
|
@ -317,7 +314,7 @@ mod tests_branches {
|
||||||
create_branch(repo_path, "test").unwrap();
|
create_branch(repo_path, "test").unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_branches_to_display(repo_path)
|
get_branches_info(repo_path)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|b| b.name.clone())
|
.map(|b| b.name.clone())
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ pub mod utils;
|
||||||
|
|
||||||
pub use branch::{
|
pub use branch::{
|
||||||
branch_compare_upstream, checkout_branch, create_branch,
|
branch_compare_upstream, checkout_branch, create_branch,
|
||||||
delete_branch, get_branches_to_display, rename_branch,
|
delete_branch, get_branches_info, rename_branch, BranchCompare,
|
||||||
BranchCompare, BranchForDisplay,
|
BranchInfo,
|
||||||
};
|
};
|
||||||
pub use commit::{amend, commit, tag};
|
pub use commit::{amend, commit, tag};
|
||||||
pub use commit_details::{
|
pub use commit_details::{
|
||||||
|
|
|
||||||
15
src/app.rs
15
src/app.rs
|
|
@ -2,12 +2,13 @@ use crate::{
|
||||||
accessors,
|
accessors,
|
||||||
cmdbar::CommandBar,
|
cmdbar::CommandBar,
|
||||||
components::{
|
components::{
|
||||||
event_pump, CommandBlocking, CommandInfo, CommitComponent,
|
event_pump, BranchListComponent, CommandBlocking,
|
||||||
Component, CreateBranchComponent, DrawableComponent,
|
CommandInfo, CommitComponent, Component,
|
||||||
|
CreateBranchComponent, DrawableComponent,
|
||||||
ExternalEditorComponent, HelpComponent,
|
ExternalEditorComponent, HelpComponent,
|
||||||
InspectCommitComponent, MsgComponent, PushComponent,
|
InspectCommitComponent, MsgComponent, PushComponent,
|
||||||
RenameBranchComponent, ResetComponent, SelectBranchComponent,
|
RenameBranchComponent, ResetComponent, StashMsgComponent,
|
||||||
StashMsgComponent, TagCommitComponent,
|
TagCommitComponent,
|
||||||
},
|
},
|
||||||
input::{Input, InputEvent, InputState},
|
input::{Input, InputEvent, InputState},
|
||||||
keys::{KeyConfig, SharedKeyConfig},
|
keys::{KeyConfig, SharedKeyConfig},
|
||||||
|
|
@ -47,7 +48,7 @@ pub struct App {
|
||||||
tag_commit_popup: TagCommitComponent,
|
tag_commit_popup: TagCommitComponent,
|
||||||
create_branch_popup: CreateBranchComponent,
|
create_branch_popup: CreateBranchComponent,
|
||||||
rename_branch_popup: RenameBranchComponent,
|
rename_branch_popup: RenameBranchComponent,
|
||||||
select_branch_popup: SelectBranchComponent,
|
select_branch_popup: BranchListComponent,
|
||||||
cmdbar: RefCell<CommandBar>,
|
cmdbar: RefCell<CommandBar>,
|
||||||
tab: usize,
|
tab: usize,
|
||||||
revlog: Revlog,
|
revlog: Revlog,
|
||||||
|
|
@ -125,7 +126,7 @@ impl App {
|
||||||
theme.clone(),
|
theme.clone(),
|
||||||
key_config.clone(),
|
key_config.clone(),
|
||||||
),
|
),
|
||||||
select_branch_popup: SelectBranchComponent::new(
|
select_branch_popup: BranchListComponent::new(
|
||||||
queue.clone(),
|
queue.clone(),
|
||||||
theme.clone(),
|
theme.clone(),
|
||||||
key_config.clone(),
|
key_config.clone(),
|
||||||
|
|
@ -491,7 +492,7 @@ impl App {
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
flags.insert(NeedsUpdate::ALL);
|
flags.insert(NeedsUpdate::ALL);
|
||||||
self.select_branch_popup.hide();
|
self.select_branch_popup.update_branches()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::ForcePush(branch, force) => self
|
Action::ForcePush(branch, force) => self
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,11 @@ use crate::{
|
||||||
components::ScrollType,
|
components::ScrollType,
|
||||||
keys::SharedKeyConfig,
|
keys::SharedKeyConfig,
|
||||||
queue::{Action, InternalEvent, NeedsUpdate, Queue},
|
queue::{Action, InternalEvent, NeedsUpdate, Queue},
|
||||||
strings,
|
strings, try_or_popup,
|
||||||
ui::{self, calc_scroll_top},
|
ui::{self, calc_scroll_top},
|
||||||
};
|
};
|
||||||
use asyncgit::{
|
use asyncgit::{
|
||||||
sync::{
|
sync::{checkout_branch, get_branches_info, BranchInfo},
|
||||||
checkout_branch, get_branches_to_display, BranchForDisplay,
|
|
||||||
},
|
|
||||||
CWD,
|
CWD,
|
||||||
};
|
};
|
||||||
use crossterm::event::Event;
|
use crossterm::event::Event;
|
||||||
|
|
@ -33,8 +31,8 @@ use anyhow::Result;
|
||||||
use ui::style::SharedTheme;
|
use ui::style::SharedTheme;
|
||||||
|
|
||||||
///
|
///
|
||||||
pub struct SelectBranchComponent {
|
pub struct BranchListComponent {
|
||||||
branch_names: Vec<BranchForDisplay>,
|
branch_names: Vec<BranchInfo>,
|
||||||
visible: bool,
|
visible: bool,
|
||||||
selection: u16,
|
selection: u16,
|
||||||
scroll_top: Cell<usize>,
|
scroll_top: Cell<usize>,
|
||||||
|
|
@ -44,7 +42,7 @@ pub struct SelectBranchComponent {
|
||||||
key_config: SharedKeyConfig,
|
key_config: SharedKeyConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrawableComponent for SelectBranchComponent {
|
impl DrawableComponent for BranchListComponent {
|
||||||
fn draw<B: Backend>(
|
fn draw<B: Backend>(
|
||||||
&self,
|
&self,
|
||||||
f: &mut Frame<B>,
|
f: &mut Frame<B>,
|
||||||
|
|
@ -104,7 +102,7 @@ impl DrawableComponent for SelectBranchComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for SelectBranchComponent {
|
impl Component for BranchListComponent {
|
||||||
fn commands(
|
fn commands(
|
||||||
&self,
|
&self,
|
||||||
out: &mut Vec<CommandInfo>,
|
out: &mut Vec<CommandInfo>,
|
||||||
|
|
@ -166,15 +164,12 @@ impl Component for SelectBranchComponent {
|
||||||
} else if e == self.key_config.page_up {
|
} else if e == self.key_config.page_up {
|
||||||
return self.move_selection(ScrollType::PageUp);
|
return self.move_selection(ScrollType::PageUp);
|
||||||
} else if e == self.key_config.enter {
|
} else if e == self.key_config.enter {
|
||||||
if let Err(e) = self.switch_to_selected_branch() {
|
try_or_popup!(
|
||||||
log::error!("switch branch error: {}", e);
|
self,
|
||||||
self.queue.borrow_mut().push_back(
|
"switch branch error:",
|
||||||
InternalEvent::ShowErrorMsg(format!(
|
self.switch_to_selected_branch()
|
||||||
"switch branch error:\n{}",
|
);
|
||||||
e
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
self.hide()
|
self.hide()
|
||||||
} else if e == self.key_config.create_branch {
|
} else if e == self.key_config.create_branch {
|
||||||
self.queue
|
self.queue
|
||||||
|
|
@ -190,7 +185,8 @@ impl Component for SelectBranchComponent {
|
||||||
cur_branch.name.clone(),
|
cur_branch.name.clone(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
self.hide();
|
|
||||||
|
self.update_branches()?;
|
||||||
} else if e == self.key_config.delete_branch
|
} else if e == self.key_config.delete_branch
|
||||||
&& !self.selection_is_cur_branch()
|
&& !self.selection_is_cur_branch()
|
||||||
{
|
{
|
||||||
|
|
@ -228,7 +224,7 @@ impl Component for SelectBranchComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SelectBranchComponent {
|
impl BranchListComponent {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
queue: Queue,
|
queue: Queue,
|
||||||
theme: SharedTheme,
|
theme: SharedTheme,
|
||||||
|
|
@ -245,10 +241,6 @@ impl SelectBranchComponent {
|
||||||
current_height: Cell::new(0),
|
current_height: Cell::new(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get all the names of the branches in the repo
|
|
||||||
pub fn get_branch_names() -> Result<Vec<BranchForDisplay>> {
|
|
||||||
Ok(get_branches_to_display(CWD)?)
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
pub fn open(&mut self) -> Result<()> {
|
pub fn open(&mut self) -> Result<()> {
|
||||||
|
|
@ -258,14 +250,14 @@ impl SelectBranchComponent {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
/// fetch list of branches
|
||||||
pub fn update_branches(&mut self) -> Result<()> {
|
pub fn update_branches(&mut self) -> Result<()> {
|
||||||
self.branch_names = Self::get_branch_names()?;
|
self.branch_names = get_branches_info(CWD)?;
|
||||||
|
self.set_selection(self.selection)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
fn selection_is_cur_branch(&self) -> bool {
|
||||||
pub fn selection_is_cur_branch(&self) -> bool {
|
|
||||||
self.branch_names
|
self.branch_names
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
|
@ -278,10 +270,7 @@ impl SelectBranchComponent {
|
||||||
|
|
||||||
///
|
///
|
||||||
fn move_selection(&mut self, scroll: ScrollType) -> Result<bool> {
|
fn move_selection(&mut self, scroll: ScrollType) -> Result<bool> {
|
||||||
let num_branches: u16 = self.branch_names.len().try_into()?;
|
let new_selection = match scroll {
|
||||||
let num_branches = num_branches.saturating_sub(1);
|
|
||||||
|
|
||||||
let mut new_selection = match scroll {
|
|
||||||
ScrollType::Up => self.selection.saturating_add(1),
|
ScrollType::Up => self.selection.saturating_add(1),
|
||||||
ScrollType::Down => self.selection.saturating_sub(1),
|
ScrollType::Down => self.selection.saturating_sub(1),
|
||||||
ScrollType::PageDown => self
|
ScrollType::PageDown => self
|
||||||
|
|
@ -293,15 +282,26 @@ impl SelectBranchComponent {
|
||||||
_ => self.selection,
|
_ => self.selection,
|
||||||
};
|
};
|
||||||
|
|
||||||
if new_selection > num_branches {
|
self.set_selection(new_selection)?;
|
||||||
new_selection = num_branches;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.selection = new_selection;
|
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_selection(&mut self, selection: u16) -> Result<()> {
|
||||||
|
let num_branches: u16 = self.branch_names.len().try_into()?;
|
||||||
|
let num_branches = num_branches.saturating_sub(1);
|
||||||
|
|
||||||
|
let selection = if selection > num_branches {
|
||||||
|
num_branches
|
||||||
|
} else {
|
||||||
|
selection
|
||||||
|
};
|
||||||
|
|
||||||
|
self.selection = selection;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Get branches to display
|
/// Get branches to display
|
||||||
fn get_text(
|
fn get_text(
|
||||||
&self,
|
&self,
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
mod branchlist;
|
||||||
mod changes;
|
mod changes;
|
||||||
mod command;
|
mod command;
|
||||||
mod commit;
|
mod commit;
|
||||||
|
|
@ -14,12 +15,12 @@ mod msg;
|
||||||
mod push;
|
mod push;
|
||||||
mod rename_branch;
|
mod rename_branch;
|
||||||
mod reset;
|
mod reset;
|
||||||
mod select_branch;
|
|
||||||
mod stashmsg;
|
mod stashmsg;
|
||||||
mod tag_commit;
|
mod tag_commit;
|
||||||
mod textinput;
|
mod textinput;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
pub use branchlist::BranchListComponent;
|
||||||
pub use changes::ChangesComponent;
|
pub use changes::ChangesComponent;
|
||||||
pub use command::{CommandInfo, CommandText};
|
pub use command::{CommandInfo, CommandText};
|
||||||
pub use commit::CommitComponent;
|
pub use commit::CommitComponent;
|
||||||
|
|
@ -35,7 +36,6 @@ pub use msg::MsgComponent;
|
||||||
pub use push::PushComponent;
|
pub use push::PushComponent;
|
||||||
pub use rename_branch::RenameBranchComponent;
|
pub use rename_branch::RenameBranchComponent;
|
||||||
pub use reset::ResetComponent;
|
pub use reset::ResetComponent;
|
||||||
pub use select_branch::SelectBranchComponent;
|
|
||||||
pub use stashmsg::StashMsgComponent;
|
pub use stashmsg::StashMsgComponent;
|
||||||
pub use tag_commit::TagCommitComponent;
|
pub use tag_commit::TagCommitComponent;
|
||||||
pub use textinput::{InputType, TextInputComponent};
|
pub use textinput::{InputType, TextInputComponent};
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ pub mod statustree;
|
||||||
macro_rules! try_or_popup {
|
macro_rules! try_or_popup {
|
||||||
($self:ident, $msg:literal, $e:expr) => {
|
($self:ident, $msg:literal, $e:expr) => {
|
||||||
if let Err(err) = $e {
|
if let Err(err) = $e {
|
||||||
|
::log::error!("{} {}", $msg, err);
|
||||||
$self.queue.borrow_mut().push_back(
|
$self.queue.borrow_mut().push_back(
|
||||||
InternalEvent::ShowErrorMsg(format!(
|
InternalEvent::ShowErrorMsg(format!(
|
||||||
"{}\n{}",
|
"{}\n{}",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue