diff --git a/src/exa.rs b/src/exa.rs index c8b26bb..c87c200 100644 --- a/src/exa.rs +++ b/src/exa.rs @@ -11,6 +11,7 @@ use ansi_term::{ANSIStrings, Style}; use log::debug; use crate::fs::{Dir, File}; +use crate::fs::filter::GitIgnore; use crate::fs::feature::git::GitCache; use crate::options::{Options, Vars}; pub use crate::options::vars; @@ -142,7 +143,8 @@ impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> { } let mut children = Vec::new(); - for file in dir.files(self.options.filter.dot_filter, self.git.as_ref()) { + let git_ignore = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore; + for file in dir.files(self.options.filter.dot_filter, self.git.as_ref(), git_ignore) { match file { Ok(file) => children.push(file), Err((path, e)) => writeln!(stderr(), "[{}: {}]", path.display(), e)?, @@ -201,7 +203,8 @@ impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> { let filter = &self.options.filter; let recurse = self.options.dir_action.recurse_options(); - let r = details::Render { dir, files, colours, style, opts, filter, recurse }; + let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore; + let r = details::Render { dir, files, colours, style, opts, filter, recurse, git_ignoring }; r.render(self.git.as_ref(), self.writer) } @@ -211,7 +214,8 @@ impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> { let details = &opts.details; let row_threshold = opts.row_threshold; - let r = grid_details::Render { dir, files, colours, style, grid, details, filter, row_threshold }; + let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore; + let r = grid_details::Render { dir, files, colours, style, grid, details, filter, row_threshold, git_ignoring }; r.render(self.git.as_ref(), self.writer) } } diff --git a/src/fs/dir.rs b/src/fs/dir.rs index 8024a51..2d81397 100644 --- a/src/fs/dir.rs +++ b/src/fs/dir.rs @@ -47,13 +47,13 @@ impl Dir { /// Produce an iterator of IO results of trying to read all the files in /// this directory. - pub fn files<'dir, 'ig>(&'dir self, dots: DotFilter, git: Option<&'ig GitCache>) -> Files<'dir, 'ig> { + pub fn files<'dir, 'ig>(&'dir self, dots: DotFilter, git: Option<&'ig GitCache>, git_ignoring: bool) -> Files<'dir, 'ig> { Files { inner: self.contents.iter(), dir: self, dotfiles: dots.shows_dotfiles(), dots: dots.dots(), - git, + git, git_ignoring, } } @@ -86,6 +86,8 @@ pub struct Files<'dir, 'ig> { dots: DotsNext, git: Option<&'ig GitCache>, + + git_ignoring: bool, } impl<'dir, 'ig> Files<'dir, 'ig> { @@ -106,9 +108,11 @@ impl<'dir, 'ig> Files<'dir, 'ig> { let filename = File::filename(path); if !self.dotfiles && filename.starts_with('.') { continue } - let git_status = self.git.map(|g| g.get(path, false)).unwrap_or_default(); - if git_status.unstaged == GitStatus::Ignored { - continue; + if self.git_ignoring { + let git_status = self.git.map(|g| g.get(path, false)).unwrap_or_default(); + if git_status.unstaged == GitStatus::Ignored { + continue; + } } return Some(File::from_args(path.clone(), self.dir, filename) diff --git a/src/output/details.rs b/src/output/details.rs index 5279fa5..db607ed 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -128,6 +128,9 @@ pub struct Render<'a> { /// How to sort and filter the files after getting their details. pub filter: &'a FileFilter, + + /// Whether we are skipping Git-ignored files. + pub git_ignoring: bool, } @@ -303,7 +306,7 @@ impl<'a> Render<'a> { rows.push(row); if let Some(ref dir) = egg.dir { - for file_to_add in dir.files(self.filter.dot_filter, git) { + for file_to_add in dir.files(self.filter.dot_filter, git, self.git_ignoring) { match file_to_add { Ok(f) => files.push(f), Err((path, e)) => errors.push((e, Some(path))) diff --git a/src/output/grid_details.rs b/src/output/grid_details.rs index 6e9504e..9ffedd1 100644 --- a/src/output/grid_details.rs +++ b/src/output/grid_details.rs @@ -76,6 +76,9 @@ pub struct Render<'a> { /// The minimum number of rows that there need to be before grid-details /// mode is activated. pub row_threshold: RowThreshold, + + /// Whether we are skipping Git-ignored files. + pub git_ignoring: bool, } impl<'a> Render<'a> { @@ -95,6 +98,7 @@ impl<'a> Render<'a> { opts: self.details, recurse: None, filter: self.filter, + git_ignoring: self.git_ignoring, } } @@ -109,6 +113,7 @@ impl<'a> Render<'a> { opts: self.details, recurse: None, filter: &self.filter, + git_ignoring: self.git_ignoring, } }