Skip to content

Commit

Permalink
ripgrep: add --no-ignore-global flag
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BurntSushi committed Jul 22, 2018
1 parent e65ca21 commit 560dffd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ Feature enhancements:
* [FEATURE #924](https://github.com/BurntSushi/ripgrep/issues/924):
`termcolor` has moved to its own repository:
https://github.com/BurntSushi/termcolor
* [FEATURE #934](https://github.com/BurntSushi/ripgrep/issues/934):
Add a new flag, `--no-ignore-global`, that permits disabling global
gitignores.
* [FEATURE #967](https://github.com/BurntSushi/ripgrep/issues/967):
Rename `--maxdepth` to `--max-depth` for consistency. We retain `--maxdepth`
as a synonym for backwards compatibility.
Rename `--maxdepth` to `--max-depth` for consistency. Keep `--maxdepth` for
backwards compatibility.
* [FEATURE #978](https://github.com/BurntSushi/ripgrep/issues/978):
Add a `--pre` option to filter inputs with an arbitrary program.
* [FEATURE fca9709d](https://github.com/BurntSushi/ripgrep/commit/fca9709d):
Expand Down Expand Up @@ -84,8 +87,8 @@ Bug fixes:
* [BUG #934](https://github.com/BurntSushi/ripgrep/issues/934):
Don't respect gitignore files when searching outside git repositories.
* [BUG #948](https://github.com/BurntSushi/ripgrep/issues/948):
ripgrep now uses an exit code of 2 to indicate an error, and uses an exit
code of 1 to indicate that no matches were found.
Use exit code 2 to indicate error, and use exit code 1 to indicate no
matches.
* [BUG #951](https://github.com/BurntSushi/ripgrep/issues/951):
Add stdin example to ripgrep usage documentation.
* [BUG #955](https://github.com/BurntSushi/ripgrep/issues/955):
Expand Down
8 changes: 6 additions & 2 deletions complete/_rg
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ _rg() {
$no"--no-hidden[don't search hidden files and directories]"

+ '(ignore)' # Ignore-file options
"(--no-ignore-parent --no-ignore-vcs)--no-ignore[don't respect ignore files]"
$no'(--ignore-parent --ignore-vcs)--ignore[respect ignore files]'
"(--no-ignore-global --no-ignore-parent --no-ignore-vcs)--no-ignore[don't respect ignore files]"
$no'(--ignore-global --ignore-parent --ignore-vcs)--ignore[respect ignore files]'

+ '(ignore-global)' # Global ignore-file options
"--no-ignore-global[don't respect global ignore files]"
$no'--ignore-global[respect global ignore files]'

+ '(ignore-parent)' # Parent ignore-file options
"--no-ignore-parent[don't respect ignore files in parent directories]"
Expand Down
21 changes: 21 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
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);
Expand Down Expand Up @@ -1230,6 +1231,26 @@ This flag can be disabled with the --ignore flag.
args.push(arg);
}

fn flag_no_ignore_global(args: &mut Vec<RGArg>) {
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<RGArg>) {
const SHORT: &str = "Suppress gitignore parse error messages.";
const LONG: &str = long!("\
Expand Down
11 changes: 10 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub struct Args {
max_filesize: Option<u64>,
mmap: bool,
no_ignore: bool,
no_ignore_global: bool,
no_ignore_messages: bool,
no_ignore_parent: bool,
no_ignore_vcs: bool,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 560dffd

Please sign in to comment.