diff --git a/Makefile b/Makefile index 9a1eabf3..7d7866b6 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,10 @@ clippy: cargo clean cargo clippy --all-features +clippy-pedantic: + cargo clean + cargo clippy --all-features -- -W clippy::pedantic + install: cargo install --path "." diff --git a/asyncgit/src/lib.rs b/asyncgit/src/lib.rs index 85b0ba10..60dc40d8 100644 --- a/asyncgit/src/lib.rs +++ b/asyncgit/src/lib.rs @@ -3,7 +3,6 @@ #![forbid(unsafe_code)] #![forbid(missing_docs)] #![deny(clippy::all)] -#![warn(clippy::pedantic)] mod diff; mod status; diff --git a/asyncgit/src/sync/diff.rs b/asyncgit/src/sync/diff.rs index 199e0a71..61ac9d4b 100644 --- a/asyncgit/src/sync/diff.rs +++ b/asyncgit/src/sync/diff.rs @@ -72,11 +72,7 @@ pub fn get_diff(p: String, stage: bool) -> Diff { let mut opt = DiffOptions::new(); opt.pathspec(p); - let diff = if !stage { - opt.include_untracked(true); - opt.recurse_untracked_dirs(true); - repo.diff_index_to_workdir(None, Some(&mut opt)).unwrap() - } else { + let diff = if stage { // diff against head let ref_head = repo.head().unwrap(); let parent = @@ -88,6 +84,10 @@ pub fn get_diff(p: String, stage: bool) -> Diff { Some(&mut opt), ) .unwrap() + } else { + opt.include_untracked(true); + opt.recurse_untracked_dirs(true); + repo.diff_index_to_workdir(None, Some(&mut opt)).unwrap() }; let mut res: Diff = Diff::default(); diff --git a/src/app.rs b/src/app.rs index cdbd4ada..2530ff84 100644 --- a/src/app.rs +++ b/src/app.rs @@ -127,7 +127,11 @@ impl App { self.index.draw(f, left_chunks[1]); self.diff.draw(f, chunks[1]); - Self::draw_commands(f, chunks_main[2], self.commands()); + Self::draw_commands( + f, + chunks_main[2], + self.commands().as_slice(), + ); self.commit.draw(f, f.size()); self.help.draw(f, f.size()); @@ -233,7 +237,13 @@ impl App { let path = i.path; let diff_params = DiffParams(path.clone(), is_stage); - if self.diff.current() != (path.clone(), is_stage) { + if self.diff.current() == (path.clone(), is_stage) { + // we are already showing a diff of the right file + // maybe the diff changed (outside file change) + if let Some(last) = self.git_diff.last() { + self.diff.update(path, is_stage, last); + } + } else { // we dont show the right diff right now, so we need to request if let Some(diff) = self.git_diff.request(diff_params) { @@ -241,12 +251,6 @@ impl App { } else { self.diff.clear(); } - } else { - // we are already showing a diff of the right file - // maybe the diff changed (outside file change) - if let Some(last) = self.git_diff.last() { - self.diff.update(path, is_stage, last); - } } } else { self.diff.clear(); @@ -354,7 +358,7 @@ impl App { fn draw_commands( f: &mut Frame, r: Rect, - cmds: Vec, + cmds: &[CommandInfo], ) { let splitter = Text::Styled( Cow::from(strings::CMD_SPLITTER), diff --git a/src/components/commit.rs b/src/components/commit.rs index 54e153e9..905a9557 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -21,13 +21,13 @@ pub struct CommitComponent { impl Component for CommitComponent { fn draw(&self, f: &mut Frame, _rect: Rect) { if self.visible { - let txt = if !self.msg.is_empty() { - [Text::Raw(Cow::from(self.msg.clone()))] - } else { + let txt = if self.msg.is_empty() { [Text::Styled( Cow::from(strings::COMMIT_MSG), Style::default().fg(Color::DarkGray), )] + } else { + [Text::Raw(Cow::from(self.msg.clone()))] }; ui::Clear::new( diff --git a/src/components/diff.rs b/src/components/diff.rs index b0e3a004..9119c743 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -71,10 +71,10 @@ impl DiffComponent { let max = min + height; let mut res = Vec::new(); - let mut line_cursor = 0u16; - let mut lines_added = 0u16; + let mut line_cursor = 0_u16; + let mut lines_added = 0_u16; - for hunk in self.diff.0.iter() { + for hunk in &self.diff.0 { if lines_added >= height { break; } @@ -131,7 +131,12 @@ impl DiffComponent { Color::Reset }) .fg(Color::DarkGray); - if !end_of_hunk { + if end_of_hunk { + text.push(Text::Styled( + Cow::from(symbols::line::BOTTOM_LEFT), + style, + )); + } else { text.push(match line.line_type { DiffLineType::Header => Text::Styled( Cow::from(symbols::line::TOP_LEFT), @@ -142,11 +147,6 @@ impl DiffComponent { style, ), }); - } else { - text.push(Text::Styled( - Cow::from(symbols::line::BOTTOM_LEFT), - style, - )); } } diff --git a/src/components/index.rs b/src/components/index.rs index 8bce4426..a987742b 100644 --- a/src/components/index.rs +++ b/src/components/index.rs @@ -41,10 +41,10 @@ impl IndexComponent { self.items = list.clone(); let old_selection = self.selection.unwrap_or_default(); - self.selection = if !self.items.is_empty() { - Some(cmp::min(old_selection, self.items.len() - 1)) - } else { + self.selection = if self.items.is_empty() { None + } else { + Some(cmp::min(old_selection, self.items.len() - 1)) }; } } diff --git a/src/main.rs b/src/main.rs index fed216cf..d6df0044 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ #![deny(clippy::all)] -#![warn(clippy::pedantic)] mod app; mod components; diff --git a/src/ui/scrolllist.rs b/src/ui/scrolllist.rs index 34c6332f..bdc0e0ad 100644 --- a/src/ui/scrolllist.rs +++ b/src/ui/scrolllist.rs @@ -29,7 +29,7 @@ where block: None, items, scroll: 0, - style: Default::default(), + style: Style::default(), } }