From 34f6da980673698017db44dc4c9f0cdf9a94c0e9 Mon Sep 17 00:00:00 2001 From: altsem Date: Sat, 24 Feb 2024 12:33:33 +0100 Subject: [PATCH] feat: respect status.showUntrackedFiles config --- src/git2_opts.rs | 16 +++++++++++ src/lib.rs | 11 ++++++++ src/screen/status.rs | 3 ++- .../gitu__tests__hide_untracked.snap | 27 +++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/git2_opts.rs create mode 100644 src/snapshots/gitu__tests__hide_untracked.snap diff --git a/src/git2_opts.rs b/src/git2_opts.rs new file mode 100644 index 0000000000..e68dc0538d --- /dev/null +++ b/src/git2_opts.rs @@ -0,0 +1,16 @@ +use crate::Res; +use git2; +use git2::Repository; + +pub(crate) fn status(repo: &Repository) -> Res { + let mut opts = git2::StatusOptions::new(); + + opts.include_untracked( + repo.config()? + .get_bool("status.showUntrackedFiles") + .ok() + .unwrap_or(true), + ); + + Ok(opts) +} diff --git a/src/lib.rs b/src/lib.rs index d7a93645a4..95b912311c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ pub mod cli; mod git; +mod git2_opts; mod items; mod keybinds; mod screen; @@ -510,6 +511,16 @@ mod tests { insta::assert_snapshot!(redact_hashes(terminal, dir)); } + #[test] + fn hide_untracked() { + let (ref mut terminal, ref mut state, dir) = setup(60, 10); + run(&dir, &["git", "config", "status.showUntrackedFiles", "off"]); + run(&dir, &["touch", "i-am-untracked"]); + + update(terminal, state, &[key('g')]).unwrap(); + insta::assert_snapshot!(redact_hashes(terminal, dir)); + } + fn setup(width: u16, height: u16) -> (Terminal, State, TempDir) { let terminal = Terminal::new(TestBackend::new(width, height)).unwrap(); let dir = TempDir::new().unwrap(); diff --git a/src/screen/status.rs b/src/screen/status.rs index bb2cbfa7ba..3a11c20e5f 100644 --- a/src/screen/status.rs +++ b/src/screen/status.rs @@ -3,6 +3,7 @@ use std::{iter, rc::Rc}; use super::Screen; use crate::{ git::{self, diff::Diff, status::BranchStatus}, + git2_opts, items::{self, Item}, theme::CURRENT_THEME, Config, Res, @@ -16,7 +17,7 @@ pub(crate) fn create(repo: Rc, config: &Config, size: Rect) -> Res