mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-27 00:14:52 +03:00
parent
779b2d572f
commit
44ba5a83c9
@ -247,6 +247,25 @@ mod tests_create_branch {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests_branch_compare {
|
||||
use super::*;
|
||||
use crate::sync::tests::repo_init;
|
||||
|
||||
#[test]
|
||||
fn test_smoke() {
|
||||
let (_td, repo) = repo_init().unwrap();
|
||||
let root = repo.path().parent().unwrap();
|
||||
let repo_path = root.as_os_str().to_str().unwrap();
|
||||
|
||||
create_branch(repo_path, "test").unwrap();
|
||||
|
||||
let res = branch_compare_upstream(repo_path, "test");
|
||||
|
||||
assert_eq!(res.is_err(), true);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests_branches {
|
||||
use super::*;
|
||||
|
@ -50,7 +50,7 @@ pub struct Status {
|
||||
git_diff: AsyncDiff,
|
||||
git_status_workdir: AsyncStatus,
|
||||
git_status_stage: AsyncStatus,
|
||||
git_branch_state: BranchCompare,
|
||||
git_branch_state: Option<BranchCompare>,
|
||||
git_branch_name: cached::BranchName,
|
||||
queue: Queue,
|
||||
git_action_executed: bool,
|
||||
@ -149,7 +149,7 @@ impl Status {
|
||||
git_status_workdir: AsyncStatus::new(sender.clone()),
|
||||
git_status_stage: AsyncStatus::new(sender.clone()),
|
||||
git_action_executed: false,
|
||||
git_branch_state: BranchCompare::default(),
|
||||
git_branch_state: None,
|
||||
git_branch_name: cached::BranchName::new(CWD),
|
||||
key_config,
|
||||
}
|
||||
@ -161,11 +161,18 @@ impl Status {
|
||||
chunks: &[tui::layout::Rect],
|
||||
) {
|
||||
if let Some(branch_name) = self.git_branch_name.last() {
|
||||
let ahead_behind =
|
||||
if let Some(state) = &self.git_branch_state {
|
||||
format!(
|
||||
"\u{2191}{} \u{2193}{} ",
|
||||
state.ahead, state.behind,
|
||||
)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
let w = Paragraph::new(format!(
|
||||
"\u{2191}{} \u{2193}{} {{{}}}",
|
||||
self.git_branch_state.ahead,
|
||||
self.git_branch_state.behind,
|
||||
branch_name
|
||||
"{}{{{}}}",
|
||||
ahead_behind, branch_name
|
||||
))
|
||||
.alignment(Alignment::Right);
|
||||
|
||||
@ -402,17 +409,17 @@ impl Status {
|
||||
}
|
||||
|
||||
fn check_branch_state(&mut self) {
|
||||
self.git_branch_state = self.git_branch_name.last().map_or(
|
||||
BranchCompare::default(),
|
||||
|branch| {
|
||||
self.git_branch_state =
|
||||
self.git_branch_name.last().and_then(|branch| {
|
||||
sync::branch_compare_upstream(CWD, branch.as_str())
|
||||
.unwrap_or_default()
|
||||
},
|
||||
);
|
||||
.ok()
|
||||
});
|
||||
}
|
||||
|
||||
const fn can_push(&self) -> bool {
|
||||
self.git_branch_state.ahead > 0
|
||||
fn can_push(&self) -> bool {
|
||||
self.git_branch_state
|
||||
.as_ref()
|
||||
.map_or(true, |state| state.ahead > 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user