Browse Source

fix(git)!: remove Repo column when using --git-repos when no git repo

Repo column was always showing even tho no repo was here
see eza-community/eza#579 first point

test(nix): changed nix tests on git repos
MartinFillon 2 years ago
parent
commit
66dc7551bf

+ 55 - 0
src/main.rs

@@ -71,6 +71,7 @@ fn main() {
 
             let git = git_options(&options, &input_paths);
             let writer = io::stdout();
+            let git_repos = git_repos(&options, &input_paths);
 
             let console_width = options.view.width.actual_terminal_width();
             let theme = options.theme.to_theme(stdout_istty);
@@ -81,6 +82,7 @@ fn main() {
                 theme,
                 console_width,
                 git,
+                git_repos,
             };
 
             info!("matching on exa.run");
@@ -148,6 +150,8 @@ pub struct Exa<'args> {
     /// This has to last the lifetime of the program, because the user might
     /// want to list several directories in the same repository.
     pub git: Option<GitCache>,
+
+    pub git_repos: bool,
 }
 
 /// The “real” environment variables type.
@@ -170,6 +174,51 @@ fn git_options(options: &Options, args: &[&OsStr]) -> Option<GitCache> {
     }
 }
 
+fn get_files_in_dir(paths: &mut Vec<PathBuf>, path: PathBuf) {
+    let temp_paths = if path.is_dir() {
+        path.read_dir()
+            .unwrap()
+            .map(|entry| entry.unwrap().path())
+            .collect::<Vec<PathBuf>>()
+    } else {
+        vec![path]
+    };
+    paths.extend(temp_paths);
+}
+
+fn git_repos(options: &Options, args: &[&OsStr]) -> bool {
+    let option_enabled = match options.view.mode {
+        Mode::Details(details::Options {
+            table: Some(ref table),
+            ..
+        })
+        | Mode::GridDetails(grid_details::Options {
+            details:
+                details::Options {
+                    table: Some(ref table),
+                    ..
+                },
+            ..
+        }) => table.columns.subdir_git_repos || table.columns.subdir_git_repos_no_stat,
+        _ => false,
+    };
+    if option_enabled {
+        let paths: Vec<PathBuf> = args.iter().map(PathBuf::from).collect::<Vec<PathBuf>>();
+        let mut files: Vec<PathBuf> = Vec::new();
+        for path in paths {
+            get_files_in_dir(&mut files, path);
+        }
+        let repos: Vec<bool> = files
+            .iter()
+            .map(git2::Repository::open)
+            .map(|repo| repo.is_ok())
+            .collect();
+        repos.contains(&true)
+    } else {
+        false
+    }
+}
+
 impl<'args> Exa<'args> {
     /// # Errors
     ///
@@ -355,6 +404,7 @@ impl<'args> Exa<'args> {
 
                 let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore;
                 let git = self.git.as_ref();
+                let git_repos = self.git_repos;
                 let r = details::Render {
                     dir,
                     files,
@@ -365,6 +415,7 @@ impl<'args> Exa<'args> {
                     filter,
                     git_ignoring,
                     git,
+                    git_repos,
                 };
                 r.render(&mut self.writer)
             }
@@ -377,6 +428,7 @@ impl<'args> Exa<'args> {
                 let filter = &self.options.filter;
                 let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore;
                 let git = self.git.as_ref();
+                let git_repos = self.git_repos;
 
                 let r = grid_details::Render {
                     dir,
@@ -390,6 +442,7 @@ impl<'args> Exa<'args> {
                     git_ignoring,
                     git,
                     console_width,
+                    git_repos,
                 };
                 r.render(&mut self.writer)
             }
@@ -400,6 +453,7 @@ impl<'args> Exa<'args> {
                 let recurse = self.options.dir_action.recurse_options();
                 let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore;
                 let git = self.git.as_ref();
+                let git_repos = self.git_repos;
 
                 let r = details::Render {
                     dir,
@@ -411,6 +465,7 @@ impl<'args> Exa<'args> {
                     filter,
                     git_ignoring,
                     git,
+                    git_repos,
                 };
                 r.render(&mut self.writer)
             }

+ 356 - 74
src/options/flags.rs

@@ -1,95 +1,377 @@
 use crate::options::parser::{Arg, Args, TakesValue, Values};
 
 // exa options
-pub static VERSION: Arg = Arg { short: Some(b'v'), long: "version",  takes_value: TakesValue::Forbidden };
-pub static HELP:    Arg = Arg { short: Some(b'?'), long: "help",     takes_value: TakesValue::Forbidden };
+pub static VERSION: Arg = Arg {
+    short: Some(b'v'),
+    long: "version",
+    takes_value: TakesValue::Forbidden,
+};
+pub static HELP: Arg = Arg {
+    short: Some(b'?'),
+    long: "help",
+    takes_value: TakesValue::Forbidden,
+};
 
 // display options
-pub static ONE_LINE:    Arg = Arg { short: Some(b'1'), long: "oneline",     takes_value: TakesValue::Forbidden };
-pub static LONG:        Arg = Arg { short: Some(b'l'), long: "long",        takes_value: TakesValue::Forbidden };
-pub static GRID:        Arg = Arg { short: Some(b'G'), long: "grid",        takes_value: TakesValue::Forbidden };
-pub static ACROSS:      Arg = Arg { short: Some(b'x'), long: "across",      takes_value: TakesValue::Forbidden };
-pub static RECURSE:     Arg = Arg { short: Some(b'R'), long: "recurse",     takes_value: TakesValue::Forbidden };
-pub static TREE:        Arg = Arg { short: Some(b'T'), long: "tree",        takes_value: TakesValue::Forbidden };
-pub static CLASSIFY:    Arg = Arg { short: Some(b'F'), long: "classify",    takes_value: TakesValue::Forbidden };
-pub static DEREF_LINKS: Arg = Arg { short: Some(b'X'), long: "dereference", takes_value: TakesValue::Forbidden };
-pub static WIDTH:       Arg = Arg { short: Some(b'w'), long: "width",       takes_value: TakesValue::Necessary(None) };
-pub static NO_QUOTES:   Arg = Arg { short: None,       long: "no-quotes",   takes_value: TakesValue::Forbidden };
+pub static ONE_LINE: Arg = Arg {
+    short: Some(b'1'),
+    long: "oneline",
+    takes_value: TakesValue::Forbidden,
+};
+pub static LONG: Arg = Arg {
+    short: Some(b'l'),
+    long: "long",
+    takes_value: TakesValue::Forbidden,
+};
+pub static GRID: Arg = Arg {
+    short: Some(b'G'),
+    long: "grid",
+    takes_value: TakesValue::Forbidden,
+};
+pub static ACROSS: Arg = Arg {
+    short: Some(b'x'),
+    long: "across",
+    takes_value: TakesValue::Forbidden,
+};
+pub static RECURSE: Arg = Arg {
+    short: Some(b'R'),
+    long: "recurse",
+    takes_value: TakesValue::Forbidden,
+};
+pub static TREE: Arg = Arg {
+    short: Some(b'T'),
+    long: "tree",
+    takes_value: TakesValue::Forbidden,
+};
+pub static CLASSIFY: Arg = Arg {
+    short: Some(b'F'),
+    long: "classify",
+    takes_value: TakesValue::Forbidden,
+};
+pub static DEREF_LINKS: Arg = Arg {
+    short: Some(b'X'),
+    long: "dereference",
+    takes_value: TakesValue::Forbidden,
+};
+pub static WIDTH: Arg = Arg {
+    short: Some(b'w'),
+    long: "width",
+    takes_value: TakesValue::Necessary(None),
+};
+pub static NO_QUOTES: Arg = Arg {
+    short: None,
+    long: "no-quotes",
+    takes_value: TakesValue::Forbidden,
+};
 
-pub static COLOR:  Arg = Arg { short: None, long: "color",  takes_value: TakesValue::Optional(Some(WHEN)) };
-pub static COLOUR: Arg = Arg { short: None, long: "colour", takes_value: TakesValue::Optional(Some(WHEN)) };
+pub static COLOR: Arg = Arg {
+    short: None,
+    long: "color",
+    takes_value: TakesValue::Optional(Some(WHEN)),
+};
+pub static COLOUR: Arg = Arg {
+    short: None,
+    long: "colour",
+    takes_value: TakesValue::Optional(Some(WHEN)),
+};
 const WHEN: &[&str] = &["always", "auto", "never"];
 
-pub static COLOR_SCALE:  Arg = Arg { short: None, long: "color-scale",  takes_value: TakesValue::Forbidden };
-pub static COLOUR_SCALE: Arg = Arg { short: None, long: "colour-scale", takes_value: TakesValue::Forbidden };
+pub static COLOR_SCALE: Arg = Arg {
+    short: None,
+    long: "color-scale",
+    takes_value: TakesValue::Forbidden,
+};
+pub static COLOUR_SCALE: Arg = Arg {
+    short: None,
+    long: "colour-scale",
+    takes_value: TakesValue::Forbidden,
+};
 
 // filtering and sorting options
-pub static ALL:         Arg = Arg { short: Some(b'a'), long: "all",         takes_value: TakesValue::Forbidden };
-pub static ALMOST_ALL:  Arg = Arg { short: Some(b'A'), long: "almost-all",  takes_value: TakesValue::Forbidden };
-pub static LIST_DIRS:   Arg = Arg { short: Some(b'd'), long: "list-dirs",   takes_value: TakesValue::Forbidden };
-pub static LEVEL:       Arg = Arg { short: Some(b'L'), long: "level",       takes_value: TakesValue::Necessary(None) };
-pub static REVERSE:     Arg = Arg { short: Some(b'r'), long: "reverse",     takes_value: TakesValue::Forbidden };
-pub static SORT:        Arg = Arg { short: Some(b's'), long: "sort",        takes_value: TakesValue::Necessary(Some(SORTS)) };
-pub static IGNORE_GLOB: Arg = Arg { short: Some(b'I'), long: "ignore-glob", takes_value: TakesValue::Necessary(None) };
-pub static GIT_IGNORE:  Arg = Arg { short: None, long: "git-ignore",           takes_value: TakesValue::Forbidden };
-pub static DIRS_FIRST:  Arg = Arg { short: None, long: "group-directories-first",  takes_value: TakesValue::Forbidden };
-pub static ONLY_DIRS:   Arg = Arg { short: Some(b'D'), long: "only-dirs", takes_value: TakesValue::Forbidden };
-pub static ONLY_FILES:  Arg = Arg { short: Some(b'f'), long: "only-files", takes_value: TakesValue::Forbidden };
-const SORTS: Values = &[ "name", "Name", "size", "extension",
-                         "Extension", "modified", "changed", "accessed",
-                         "created", "inode", "type", "none" ];
+pub static ALL: Arg = Arg {
+    short: Some(b'a'),
+    long: "all",
+    takes_value: TakesValue::Forbidden,
+};
+pub static ALMOST_ALL: Arg = Arg {
+    short: Some(b'A'),
+    long: "almost-all",
+    takes_value: TakesValue::Forbidden,
+};
+pub static LIST_DIRS: Arg = Arg {
+    short: Some(b'd'),
+    long: "list-dirs",
+    takes_value: TakesValue::Forbidden,
+};
+pub static LEVEL: Arg = Arg {
+    short: Some(b'L'),
+    long: "level",
+    takes_value: TakesValue::Necessary(None),
+};
+pub static REVERSE: Arg = Arg {
+    short: Some(b'r'),
+    long: "reverse",
+    takes_value: TakesValue::Forbidden,
+};
+pub static SORT: Arg = Arg {
+    short: Some(b's'),
+    long: "sort",
+    takes_value: TakesValue::Necessary(Some(SORTS)),
+};
+pub static IGNORE_GLOB: Arg = Arg {
+    short: Some(b'I'),
+    long: "ignore-glob",
+    takes_value: TakesValue::Necessary(None),
+};
+pub static GIT_IGNORE: Arg = Arg {
+    short: None,
+    long: "git-ignore",
+    takes_value: TakesValue::Forbidden,
+};
+pub static DIRS_FIRST: Arg = Arg {
+    short: None,
+    long: "group-directories-first",
+    takes_value: TakesValue::Forbidden,
+};
+pub static ONLY_DIRS: Arg = Arg {
+    short: Some(b'D'),
+    long: "only-dirs",
+    takes_value: TakesValue::Forbidden,
+};
+pub static ONLY_FILES: Arg = Arg {
+    short: Some(b'f'),
+    long: "only-files",
+    takes_value: TakesValue::Forbidden,
+};
+const SORTS: Values = &[
+    "name",
+    "Name",
+    "size",
+    "extension",
+    "Extension",
+    "modified",
+    "changed",
+    "accessed",
+    "created",
+    "inode",
+    "type",
+    "none",
+];
 
 // display options
-pub static BINARY:      Arg = Arg { short: Some(b'b'), long: "binary",      takes_value: TakesValue::Forbidden };
-pub static BYTES:       Arg = Arg { short: Some(b'B'), long: "bytes",       takes_value: TakesValue::Forbidden };
-pub static GROUP:       Arg = Arg { short: Some(b'g'), long: "group",       takes_value: TakesValue::Forbidden };
-pub static NUMERIC:     Arg = Arg { short: Some(b'n'), long: "numeric",     takes_value: TakesValue::Forbidden };
-pub static HEADER:      Arg = Arg { short: Some(b'h'), long: "header",      takes_value: TakesValue::Forbidden };
-pub static ICONS:       Arg = Arg { short: None,       long: "icons",       takes_value: TakesValue::Optional(Some(WHEN))};
-pub static INODE:       Arg = Arg { short: Some(b'i'), long: "inode",       takes_value: TakesValue::Forbidden };
-pub static LINKS:       Arg = Arg { short: Some(b'H'), long: "links",       takes_value: TakesValue::Forbidden };
-pub static MODIFIED:    Arg = Arg { short: Some(b'm'), long: "modified",    takes_value: TakesValue::Forbidden };
-pub static CHANGED:     Arg = Arg { short: None,       long: "changed",     takes_value: TakesValue::Forbidden };
-pub static BLOCKSIZE:   Arg = Arg { short: Some(b'S'), long: "blocksize",   takes_value: TakesValue::Forbidden };
-pub static TOTAL_SIZE:  Arg = Arg { short: None,       long: "total-size",  takes_value: TakesValue::Forbidden };
-pub static TIME:        Arg = Arg { short: Some(b't'), long: "time",        takes_value: TakesValue::Necessary(Some(TIMES)) };
-pub static ACCESSED:    Arg = Arg { short: Some(b'u'), long: "accessed",    takes_value: TakesValue::Forbidden };
-pub static CREATED:     Arg = Arg { short: Some(b'U'), long: "created",     takes_value: TakesValue::Forbidden };
-pub static TIME_STYLE:  Arg = Arg { short: None,       long: "time-style",  takes_value: TakesValue::Necessary(Some(TIME_STYLES)) };
-pub static HYPERLINK:   Arg = Arg { short: None,       long: "hyperlink",   takes_value: TakesValue::Forbidden };
-pub static MOUNTS:      Arg = Arg { short: Some(b'M'), long: "mounts",      takes_value: TakesValue::Forbidden };
-pub static SMART_GROUP: Arg = Arg { short: None,       long: "smart-group", takes_value: TakesValue::Forbidden };
+pub static BINARY: Arg = Arg {
+    short: Some(b'b'),
+    long: "binary",
+    takes_value: TakesValue::Forbidden,
+};
+pub static BYTES: Arg = Arg {
+    short: Some(b'B'),
+    long: "bytes",
+    takes_value: TakesValue::Forbidden,
+};
+pub static GROUP: Arg = Arg {
+    short: Some(b'g'),
+    long: "group",
+    takes_value: TakesValue::Forbidden,
+};
+pub static NUMERIC: Arg = Arg {
+    short: Some(b'n'),
+    long: "numeric",
+    takes_value: TakesValue::Forbidden,
+};
+pub static HEADER: Arg = Arg {
+    short: Some(b'h'),
+    long: "header",
+    takes_value: TakesValue::Forbidden,
+};
+pub static ICONS: Arg = Arg {
+    short: None,
+    long: "icons",
+    takes_value: TakesValue::Optional(Some(WHEN)),
+};
+pub static INODE: Arg = Arg {
+    short: Some(b'i'),
+    long: "inode",
+    takes_value: TakesValue::Forbidden,
+};
+pub static LINKS: Arg = Arg {
+    short: Some(b'H'),
+    long: "links",
+    takes_value: TakesValue::Forbidden,
+};
+pub static MODIFIED: Arg = Arg {
+    short: Some(b'm'),
+    long: "modified",
+    takes_value: TakesValue::Forbidden,
+};
+pub static CHANGED: Arg = Arg {
+    short: None,
+    long: "changed",
+    takes_value: TakesValue::Forbidden,
+};
+pub static BLOCKSIZE: Arg = Arg {
+    short: Some(b'S'),
+    long: "blocksize",
+    takes_value: TakesValue::Forbidden,
+};
+pub static TOTAL_SIZE: Arg = Arg {
+    short: None,
+    long: "total-size",
+    takes_value: TakesValue::Forbidden,
+};
+pub static TIME: Arg = Arg {
+    short: Some(b't'),
+    long: "time",
+    takes_value: TakesValue::Necessary(Some(TIMES)),
+};
+pub static ACCESSED: Arg = Arg {
+    short: Some(b'u'),
+    long: "accessed",
+    takes_value: TakesValue::Forbidden,
+};
+pub static CREATED: Arg = Arg {
+    short: Some(b'U'),
+    long: "created",
+    takes_value: TakesValue::Forbidden,
+};
+pub static TIME_STYLE: Arg = Arg {
+    short: None,
+    long: "time-style",
+    takes_value: TakesValue::Necessary(Some(TIME_STYLES)),
+};
+pub static HYPERLINK: Arg = Arg {
+    short: None,
+    long: "hyperlink",
+    takes_value: TakesValue::Forbidden,
+};
+pub static MOUNTS: Arg = Arg {
+    short: Some(b'M'),
+    long: "mounts",
+    takes_value: TakesValue::Forbidden,
+};
+pub static SMART_GROUP: Arg = Arg {
+    short: None,
+    long: "smart-group",
+    takes_value: TakesValue::Forbidden,
+};
 const TIMES: Values = &["modified", "changed", "accessed", "created"];
 const TIME_STYLES: Values = &["default", "long-iso", "full-iso", "iso", "relative"];
 
 // suppressing columns
-pub static NO_PERMISSIONS: Arg = Arg { short: None, long: "no-permissions", takes_value: TakesValue::Forbidden };
-pub static NO_FILESIZE: Arg = Arg { short: None, long: "no-filesize", takes_value: TakesValue::Forbidden };
-pub static NO_USER: Arg = Arg { short: None, long: "no-user", takes_value: TakesValue::Forbidden };
-pub static NO_TIME: Arg = Arg { short: None, long: "no-time", takes_value: TakesValue::Forbidden };
+pub static NO_PERMISSIONS: Arg = Arg {
+    short: None,
+    long: "no-permissions",
+    takes_value: TakesValue::Forbidden,
+};
+pub static NO_FILESIZE: Arg = Arg {
+    short: None,
+    long: "no-filesize",
+    takes_value: TakesValue::Forbidden,
+};
+pub static NO_USER: Arg = Arg {
+    short: None,
+    long: "no-user",
+    takes_value: TakesValue::Forbidden,
+};
+pub static NO_TIME: Arg = Arg {
+    short: None,
+    long: "no-time",
+    takes_value: TakesValue::Forbidden,
+};
 
 // optional feature options
-pub static GIT:               Arg = Arg { short: None,       long: "git",                  takes_value: TakesValue::Forbidden };
-pub static NO_GIT:            Arg = Arg { short: None,       long: "no-git",               takes_value: TakesValue::Forbidden };
-pub static GIT_REPOS:         Arg = Arg { short: None,       long: "git-repos",            takes_value: TakesValue::Forbidden };
-pub static GIT_REPOS_NO_STAT: Arg = Arg { short: None,       long: "git-repos-no-status",  takes_value: TakesValue::Forbidden };
-pub static EXTENDED:          Arg = Arg { short: Some(b'@'), long: "extended",             takes_value: TakesValue::Forbidden };
-pub static OCTAL:             Arg = Arg { short: Some(b'o'), long: "octal-permissions",    takes_value: TakesValue::Forbidden };
-pub static SECURITY_CONTEXT:  Arg = Arg { short: Some(b'Z'), long: "context",              takes_value: TakesValue::Forbidden };
+pub static GIT: Arg = Arg {
+    short: None,
+    long: "git",
+    takes_value: TakesValue::Forbidden,
+};
+pub static NO_GIT: Arg = Arg {
+    short: None,
+    long: "no-git",
+    takes_value: TakesValue::Forbidden,
+};
+pub static GIT_REPOS: Arg = Arg {
+    short: None,
+    long: "git-repos",
+    takes_value: TakesValue::Forbidden,
+};
+pub static GIT_REPOS_NO_STAT: Arg = Arg {
+    short: None,
+    long: "git-repos-no-status",
+    takes_value: TakesValue::Forbidden,
+};
+pub static EXTENDED: Arg = Arg {
+    short: Some(b'@'),
+    long: "extended",
+    takes_value: TakesValue::Forbidden,
+};
+pub static OCTAL: Arg = Arg {
+    short: Some(b'o'),
+    long: "octal-permissions",
+    takes_value: TakesValue::Forbidden,
+};
+pub static SECURITY_CONTEXT: Arg = Arg {
+    short: Some(b'Z'),
+    long: "context",
+    takes_value: TakesValue::Forbidden,
+};
 
 pub static ALL_ARGS: Args = Args(&[
-    &VERSION, &HELP,
-
-    &ONE_LINE, &LONG, &GRID, &ACROSS, &RECURSE, &TREE, &CLASSIFY, &DEREF_LINKS,
-    &COLOR, &COLOUR, &COLOR_SCALE, &COLOUR_SCALE, &WIDTH, &NO_QUOTES,
-
-    &ALL, &ALMOST_ALL, &LIST_DIRS, &LEVEL, &REVERSE, &SORT, &DIRS_FIRST,
-    &IGNORE_GLOB, &GIT_IGNORE, &ONLY_DIRS, &ONLY_FILES,
-
-    &BINARY, &BYTES, &GROUP, &NUMERIC, &HEADER, &ICONS, &INODE, &LINKS, &MODIFIED, &CHANGED,
-    &BLOCKSIZE, &TOTAL_SIZE, &TIME, &ACCESSED, &CREATED, &TIME_STYLE, &HYPERLINK, &MOUNTS,
-    &NO_PERMISSIONS, &NO_FILESIZE, &NO_USER, &NO_TIME, &SMART_GROUP,
-
-    &GIT, &NO_GIT, &GIT_REPOS, &GIT_REPOS_NO_STAT,
-    &EXTENDED, &OCTAL, &SECURITY_CONTEXT
+    &VERSION,
+    &HELP,
+    &ONE_LINE,
+    &LONG,
+    &GRID,
+    &ACROSS,
+    &RECURSE,
+    &TREE,
+    &CLASSIFY,
+    &DEREF_LINKS,
+    &COLOR,
+    &COLOUR,
+    &COLOR_SCALE,
+    &COLOUR_SCALE,
+    &WIDTH,
+    &NO_QUOTES,
+    &ALL,
+    &ALMOST_ALL,
+    &LIST_DIRS,
+    &LEVEL,
+    &REVERSE,
+    &SORT,
+    &DIRS_FIRST,
+    &IGNORE_GLOB,
+    &GIT_IGNORE,
+    &ONLY_DIRS,
+    &ONLY_FILES,
+    &BINARY,
+    &BYTES,
+    &GROUP,
+    &NUMERIC,
+    &HEADER,
+    &ICONS,
+    &INODE,
+    &LINKS,
+    &MODIFIED,
+    &CHANGED,
+    &BLOCKSIZE,
+    &TOTAL_SIZE,
+    &TIME,
+    &ACCESSED,
+    &CREATED,
+    &TIME_STYLE,
+    &HYPERLINK,
+    &MOUNTS,
+    &NO_PERMISSIONS,
+    &NO_FILESIZE,
+    &NO_USER,
+    &NO_TIME,
+    &SMART_GROUP,
+    &GIT,
+    &NO_GIT,
+    &GIT_REPOS,
+    &GIT_REPOS_NO_STAT,
+    &EXTENDED,
+    &OCTAL,
+    &SECURITY_CONTEXT,
 ]);

+ 3 - 1
src/output/details.rs

@@ -134,6 +134,8 @@ pub struct Render<'a> {
     pub git_ignoring: bool,
 
     pub git: Option<&'a GitCache>,
+
+    pub git_repos: bool,
 }
 
 #[rustfmt::skip]
@@ -175,7 +177,7 @@ impl<'a> Render<'a> {
                 (None, _) => { /* Keep Git how it is */ }
             }
 
-            let mut table = Table::new(table, self.git, self.theme);
+            let mut table = Table::new(table, self.git, self.theme, self.git_repos);
 
             if self.opts.header {
                 let header = table.header_row();

+ 5 - 1
src/output/grid_details.rs

@@ -87,6 +87,8 @@ pub struct Render<'a> {
     pub git: Option<&'a GitCache>,
 
     pub console_width: usize,
+
+    pub git_repos: bool,
 }
 
 impl<'a> Render<'a> {
@@ -108,6 +110,7 @@ impl<'a> Render<'a> {
             filter:        self.filter,
             git_ignoring:  self.git_ignoring,
             git:           self.git,
+            git_repos:     self.git_repos,
         };
     }
 
@@ -127,6 +130,7 @@ impl<'a> Render<'a> {
             filter:        self.filter,
             git_ignoring:  self.git_ignoring,
             git:           self.git,
+            git_repos:     self.git_repos,
         };
     }
 
@@ -259,7 +263,7 @@ impl<'a> Render<'a> {
             (None, _) => { /* Keep Git how it is */ }
         }
 
-        let mut table = Table::new(options, self.git, self.theme);
+        let mut table = Table::new(options, self.git, self.theme, self.git_repos);
         let mut rows = Vec::new();
 
         if self.details.header {

+ 12 - 5
src/output/table.rs

@@ -54,7 +54,7 @@ pub struct Columns {
 }
 
 impl Columns {
-    pub fn collect(&self, actually_enable_git: bool) -> Vec<Column> {
+    pub fn collect(&self, actually_enable_git: bool, git_repos: bool) -> Vec<Column> {
         let mut columns = Vec::with_capacity(4);
 
         if self.inode {
@@ -120,11 +120,11 @@ impl Columns {
             columns.push(Column::GitStatus);
         }
 
-        if self.subdir_git_repos {
+        if self.subdir_git_repos && git_repos {
             columns.push(Column::SubdirGitRepo(true));
         }
 
-        if self.subdir_git_repos_no_stat {
+        if self.subdir_git_repos_no_stat && git_repos {
             columns.push(Column::SubdirGitRepo(false));
         }
 
@@ -374,11 +374,18 @@ pub struct Row {
 }
 
 impl<'a> Table<'a> {
-    pub fn new(options: &'a Options, git: Option<&'a GitCache>, theme: &'a Theme) -> Table<'a> {
-        let columns = options.columns.collect(git.is_some());
+    pub fn new(
+        options: &'a Options,
+        git: Option<&'a GitCache>,
+        theme: &'a Theme,
+        git_repos: bool,
+    ) -> Table<'a> {
+        let columns = options.columns.collect(git.is_some(), git_repos);
         let widths = TableWidths::zero(columns.len());
         let env = &*ENVIRONMENT;
 
+        debug!("Creating table with columns: {:?}", columns);
+
         Table {
             theme,
             widths,

+ 21 - 21
tests/cmd/long_git_repos_nix.stdout

@@ -1,21 +1,21 @@
-.rw-r--r--  0 nixbld  1 Jan  1970 - - a
-.rw-r--r--  0 nixbld  1 Jan  1970 - - b
-.rw-r--r--  0 nixbld  1 Jan  1970 - - c
-.rw-r--r--  0 nixbld  1 Jan  1970 - - d
-.rw-r--r--  0 nixbld  1 Jan  1970 - - e
-drwxr-xr-x  - nixbld  1 Jan  1970 - - exa
-.rw-r--r--  0 nixbld  1 Jan  1970 - - f
-.rw-r--r--  0 nixbld  1 Jan  1970 - - g
-.rw-r--r--  0 nixbld  1 Jan  1970 - - h
-.rw-r--r--  0 nixbld  1 Jan  1970 - - i
-.rw-r--r--  0 nixbld  1 Jan  1970 - - image.jpg.img.c.rs.log.png
-.rw-r--r-- 19 nixbld  1 Jan  1970 - - index.svg
-.rw-r--r--  0 nixbld  1 Jan  1970 - - j
-.rw-r--r--  0 nixbld  1 Jan  1970 - - k
-.rw-r--r--  0 nixbld  1 Jan  1970 - - l
-.rw-r--r--  0 nixbld  1 Jan  1970 - - m
-.rw-r--r--  0 nixbld  1 Jan  1970 - - n
-.rw-r--r--  0 nixbld  1 Jan  1970 - - o
-.rw-r--r--  0 nixbld  1 Jan  1970 - - p
-.rw-r--r--  0 nixbld  1 Jan  1970 - - q
-drwxr-xr-x  - nixbld  1 Jan  1970 - - vagrant
+.rw-r--r--  0 nixbld  1 Jan  1970 a
+.rw-r--r--  0 nixbld  1 Jan  1970 b
+.rw-r--r--  0 nixbld  1 Jan  1970 c
+.rw-r--r--  0 nixbld  1 Jan  1970 d
+.rw-r--r--  0 nixbld  1 Jan  1970 e
+drwxr-xr-x  - nixbld  1 Jan  1970 exa
+.rw-r--r--  0 nixbld  1 Jan  1970 f
+.rw-r--r--  0 nixbld  1 Jan  1970 g
+.rw-r--r--  0 nixbld  1 Jan  1970 h
+.rw-r--r--  0 nixbld  1 Jan  1970 i
+.rw-r--r--  0 nixbld  1 Jan  1970 image.jpg.img.c.rs.log.png
+.rw-r--r-- 19 nixbld  1 Jan  1970 index.svg
+.rw-r--r--  0 nixbld  1 Jan  1970 j
+.rw-r--r--  0 nixbld  1 Jan  1970 k
+.rw-r--r--  0 nixbld  1 Jan  1970 l
+.rw-r--r--  0 nixbld  1 Jan  1970 m
+.rw-r--r--  0 nixbld  1 Jan  1970 n
+.rw-r--r--  0 nixbld  1 Jan  1970 o
+.rw-r--r--  0 nixbld  1 Jan  1970 p
+.rw-r--r--  0 nixbld  1 Jan  1970 q
+drwxr-xr-x  - nixbld  1 Jan  1970 vagrant

+ 21 - 21
tests/cmd/long_git_repos_no_status_nix.stdout

@@ -1,21 +1,21 @@
-.rw-r--r--  0 nixbld  1 Jan  1970 - - a
-.rw-r--r--  0 nixbld  1 Jan  1970 - - b
-.rw-r--r--  0 nixbld  1 Jan  1970 - - c
-.rw-r--r--  0 nixbld  1 Jan  1970 - - d
-.rw-r--r--  0 nixbld  1 Jan  1970 - - e
-drwxr-xr-x  - nixbld  1 Jan  1970 -   exa
-.rw-r--r--  0 nixbld  1 Jan  1970 - - f
-.rw-r--r--  0 nixbld  1 Jan  1970 - - g
-.rw-r--r--  0 nixbld  1 Jan  1970 - - h
-.rw-r--r--  0 nixbld  1 Jan  1970 - - i
-.rw-r--r--  0 nixbld  1 Jan  1970 - - image.jpg.img.c.rs.log.png
-.rw-r--r-- 19 nixbld  1 Jan  1970 - - index.svg
-.rw-r--r--  0 nixbld  1 Jan  1970 - - j
-.rw-r--r--  0 nixbld  1 Jan  1970 - - k
-.rw-r--r--  0 nixbld  1 Jan  1970 - - l
-.rw-r--r--  0 nixbld  1 Jan  1970 - - m
-.rw-r--r--  0 nixbld  1 Jan  1970 - - n
-.rw-r--r--  0 nixbld  1 Jan  1970 - - o
-.rw-r--r--  0 nixbld  1 Jan  1970 - - p
-.rw-r--r--  0 nixbld  1 Jan  1970 - - q
-drwxr-xr-x  - nixbld  1 Jan  1970 -   vagrant
+.rw-r--r--  0 nixbld  1 Jan  1970 a
+.rw-r--r--  0 nixbld  1 Jan  1970 b
+.rw-r--r--  0 nixbld  1 Jan  1970 c
+.rw-r--r--  0 nixbld  1 Jan  1970 d
+.rw-r--r--  0 nixbld  1 Jan  1970 e
+drwxr-xr-x  - nixbld  1 Jan  1970 exa
+.rw-r--r--  0 nixbld  1 Jan  1970 f
+.rw-r--r--  0 nixbld  1 Jan  1970 g
+.rw-r--r--  0 nixbld  1 Jan  1970 h
+.rw-r--r--  0 nixbld  1 Jan  1970 i
+.rw-r--r--  0 nixbld  1 Jan  1970 image.jpg.img.c.rs.log.png
+.rw-r--r-- 19 nixbld  1 Jan  1970 index.svg
+.rw-r--r--  0 nixbld  1 Jan  1970 j
+.rw-r--r--  0 nixbld  1 Jan  1970 k
+.rw-r--r--  0 nixbld  1 Jan  1970 l
+.rw-r--r--  0 nixbld  1 Jan  1970 m
+.rw-r--r--  0 nixbld  1 Jan  1970 n
+.rw-r--r--  0 nixbld  1 Jan  1970 o
+.rw-r--r--  0 nixbld  1 Jan  1970 p
+.rw-r--r--  0 nixbld  1 Jan  1970 q
+drwxr-xr-x  - nixbld  1 Jan  1970 vagrant