From 560dffd2476f16b4b296aae6aca7aec0f0c6ba1c Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sun, 22 Jul 2018 10:42:32 -0400 Subject: ripgrep: add --no-ignore-global flag This commit adds a new --no-ignore-global flag that permits disabling the use of global gitignore filtering. Global gitignores are generally found in `$HOME/.config/git/ignore`, but its location can be configured via git's `core.excludesFile` option. Closes #934 --- src/app.rs | 21 +++++++++++++++++++++ src/args.rs | 11 ++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/app.rs b/src/app.rs index 402bef5e..4bdf5bf4 100644 --- a/src/app.rs +++ b/src/app.rs @@ -527,6 +527,7 @@ pub fn all_args_and_flags() -> Vec { flag_mmap(&mut args); flag_no_config(&mut args); flag_no_ignore(&mut args); + flag_no_ignore_global(&mut args); flag_no_ignore_messages(&mut args); flag_no_ignore_parent(&mut args); flag_no_ignore_vcs(&mut args); @@ -1230,6 +1231,26 @@ This flag can be disabled with the --ignore flag. args.push(arg); } +fn flag_no_ignore_global(args: &mut Vec) { + const SHORT: &str = "Don't respect global ignore files."; + const LONG: &str = long!("\ +Don't respect ignore files that come from \"global\" sources such as git's +`core.excludesFile` configuration option (which defaults to +`$HOME/.config/git/ignore). + +This flag can be disabled with the --ignore-global flag. +"); + let arg = RGArg::switch("no-ignore-global") + .help(SHORT).long_help(LONG) + .overrides("ignore-global"); + args.push(arg); + + let arg = RGArg::switch("ignore-global") + .hidden() + .overrides("no-ignore-global"); + args.push(arg); +} + fn flag_no_ignore_messages(args: &mut Vec) { const SHORT: &str = "Suppress gitignore parse error messages."; const LONG: &str = long!("\ diff --git a/src/args.rs b/src/args.rs index 7100fc5c..1d7d1a8e 100644 --- a/src/args.rs +++ b/src/args.rs @@ -62,6 +62,7 @@ pub struct Args { max_filesize: Option, mmap: bool, no_ignore: bool, + no_ignore_global: bool, no_ignore_messages: bool, no_ignore_parent: bool, no_ignore_vcs: bool, @@ -351,7 +352,9 @@ impl Args { wd.max_filesize(self.max_filesize); wd.overrides(self.glob_overrides.clone()); wd.types(self.types.clone()); - wd.git_global(!self.no_ignore && !self.no_ignore_vcs); + wd.git_global( + !self.no_ignore && !self.no_ignore_vcs && !self.no_ignore_global + ); wd.git_ignore(!self.no_ignore && !self.no_ignore_vcs); wd.git_exclude(!self.no_ignore && !self.no_ignore_vcs); wd.ignore(!self.no_ignore); @@ -413,6 +416,7 @@ impl<'a> ArgMatches<'a> { max_filesize: self.max_filesize()?, mmap: mmap, no_ignore: self.no_ignore(), + no_ignore_global: self.no_ignore_global(), no_ignore_messages: self.is_present("no-ignore-messages"), no_ignore_parent: self.no_ignore_parent(), no_ignore_vcs: self.no_ignore_vcs(), @@ -1019,6 +1023,11 @@ impl<'a> ArgMatches<'a> { || self.occurrences_of("unrestricted") >= 1 } + /// Returns true if global ignore files should be ignored. + fn no_ignore_global(&self) -> bool { + self.is_present("no-ignore-global") || self.no_ignore() + } + /// Returns true if parent ignore files should be ignored. fn no_ignore_parent(&self) -> bool { self.is_present("no-ignore-parent") || self.no_ignore() -- cgit v1.2.3