mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
only show non-clean repo states (#553)
* only show repo state if not clean
This commit is contained in:
parent
fa93594f03
commit
67f3a13716
2 changed files with 25 additions and 16 deletions
|
|
@ -3,7 +3,7 @@ use git2::RepositoryState;
|
|||
use scopetime::scope_time;
|
||||
|
||||
///
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum RepoState {
|
||||
///
|
||||
Clean,
|
||||
|
|
|
|||
|
|
@ -14,14 +14,16 @@ use anyhow::Result;
|
|||
use asyncgit::{
|
||||
cached,
|
||||
sync::BranchCompare,
|
||||
sync::{self, status::StatusType},
|
||||
sync::{self, status::StatusType, RepoState},
|
||||
AsyncDiff, AsyncNotification, AsyncStatus, DiffParams, DiffType,
|
||||
StatusParams, CWD,
|
||||
};
|
||||
use crossbeam_channel::Sender;
|
||||
use crossterm::event::Event;
|
||||
use std::convert::TryFrom;
|
||||
use tui::{
|
||||
layout::{Alignment, Constraint, Direction, Layout},
|
||||
style::{Color, Style},
|
||||
widgets::Paragraph,
|
||||
};
|
||||
|
||||
|
|
@ -199,20 +201,27 @@ impl Status {
|
|||
f: &mut tui::Frame<B>,
|
||||
r: tui::layout::Rect,
|
||||
) {
|
||||
let w = Paragraph::new(format!(
|
||||
"{:?}",
|
||||
asyncgit::sync::repo_state(CWD).expect("")
|
||||
))
|
||||
.alignment(Alignment::Left);
|
||||
if let Ok(state) = asyncgit::sync::repo_state(CWD) {
|
||||
if state != RepoState::Clean {
|
||||
let txt = format!("{:?}", state);
|
||||
let txt_len = u16::try_from(txt.len())
|
||||
.expect("state name too long");
|
||||
let w = Paragraph::new(txt)
|
||||
.style(Style::default().fg(Color::Red))
|
||||
.alignment(Alignment::Left);
|
||||
|
||||
let mut rect = r;
|
||||
rect.x += 1;
|
||||
rect.width = rect.width.saturating_sub(2);
|
||||
rect.y += rect.height.saturating_sub(1);
|
||||
rect.height =
|
||||
rect.height.saturating_sub(rect.height.saturating_sub(1));
|
||||
let mut rect = r;
|
||||
rect.x += 1;
|
||||
rect.width =
|
||||
rect.width.saturating_sub(2).min(txt_len);
|
||||
rect.y += rect.height.saturating_sub(1);
|
||||
rect.height = rect
|
||||
.height
|
||||
.saturating_sub(rect.height.saturating_sub(1));
|
||||
|
||||
f.render_widget(w, rect);
|
||||
f.render_widget(w, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn can_focus_diff(&self) -> bool {
|
||||
|
|
@ -287,7 +296,7 @@ impl Status {
|
|||
self.git_status_stage
|
||||
.fetch(StatusParams::new(StatusType::Stage, true))?;
|
||||
|
||||
self.check_branch_state();
|
||||
self.branch_compare();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
@ -422,7 +431,7 @@ impl Status {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_branch_state(&mut self) {
|
||||
fn branch_compare(&mut self) {
|
||||
self.git_branch_state =
|
||||
self.git_branch_name.last().and_then(|branch| {
|
||||
sync::branch_compare_upstream(CWD, branch.as_str())
|
||||
|
|
|
|||
Loading…
Reference in a new issue