From 12a6ca45f9dad30864715dfecd917bb571b687d4 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 26 Jan 2019 13:40:12 -0500 Subject: [PATCH] config: add --no-ignore-dot flag This flag causes ripgrep to ignore `.ignore` files. Closes #1138 --- CHANGELOG.md | 2 ++ complete/_rg | 8 ++++++-- src/app.rs | 21 ++++++++++++++++++++- src/args.rs | 16 +++++++++------- tests/feature.rs | 16 ++++++++++++++++ 5 files changed, 53 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 080c58de1..4bf45c8ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ Feature enhancements: * [FEATURE #1099](https://github.com/BurntSushi/ripgrep/pull/1099): Add support for Brotli and Zstd to the `-z/--search-zip` flag. +* [FEATURE #1138](https://github.com/BurntSushi/ripgrep/pull/1138): + Add `--no-ignore-dot` flag for ignoring `.ignore` files. * [FEATURE #1170](https://github.com/BurntSushi/ripgrep/pull/1170): Add `--ignore-file-case-insensitive` for case insensitive .ignore globs. diff --git a/complete/_rg b/complete/_rg index f48c09981..2e5c1937a 100644 --- a/complete/_rg +++ b/complete/_rg @@ -112,8 +112,8 @@ _rg() { $no"--no-hidden[don't search hidden files and directories]" + '(ignore)' # Ignore-file options - "(--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]' + "(--no-ignore-global --no-ignore-parent --no-ignore-vcs --no-ignore-dot)--no-ignore[don't respect ignore files]" + $no'(--ignore-global --ignore-parent --ignore-vcs --ignore-dot)--ignore[respect ignore files]' + '(ignore-file-case-insensitive)' # Ignore-file case sensitivity options '--ignore-file-case-insensitive[process ignore files case insensitively]' @@ -131,6 +131,10 @@ _rg() { "--no-ignore-vcs[don't respect version control ignore files]" $no'--ignore-vcs[respect version control ignore files]' + + '(ignore-dot)' # .ignore-file options + "--no-ignore-dot[don't respect .ignore files]" + $no'--ignore-dot[respect .ignore files]' + + '(json)' # JSON options '--json[output results in JSON Lines format]' $no"--no-json[don't output results in JSON Lines format]" diff --git a/src/app.rs b/src/app.rs index 8639262f3..989e6dcbc 100644 --- a/src/app.rs +++ b/src/app.rs @@ -586,6 +586,7 @@ pub fn all_args_and_flags() -> Vec { flag_multiline_dotall(&mut args); flag_no_config(&mut args); flag_no_ignore(&mut args); + flag_no_ignore_dot(&mut args); flag_no_ignore_global(&mut args); flag_no_ignore_messages(&mut args); flag_no_ignore_parent(&mut args); @@ -1558,7 +1559,7 @@ fn flag_no_ignore(args: &mut Vec) { const SHORT: &str = "Don't respect ignore files."; const LONG: &str = long!("\ Don't respect ignore files (.gitignore, .ignore, etc.). This implies ---no-ignore-parent and --no-ignore-vcs. +--no-ignore-parent, --no-ignore-dot and --no-ignore-vcs. This flag can be disabled with the --ignore flag. "); @@ -1573,6 +1574,24 @@ This flag can be disabled with the --ignore flag. args.push(arg); } +fn flag_no_ignore_dot(args: &mut Vec) { + const SHORT: &str = "Don't respect .ignore files."; + const LONG: &str = long!("\ +Don't respect .ignore files. + +This flag can be disabled with the --ignore-dot flag. +"); + let arg = RGArg::switch("no-ignore-dot") + .help(SHORT).long_help(LONG) + .overrides("ignore-dot"); + args.push(arg); + + let arg = RGArg::switch("ignore-dot") + .hidden() + .overrides("no-ignore-dot"); + args.push(arg); +} + fn flag_no_ignore_global(args: &mut Vec) { const SHORT: &str = "Don't respect global ignore files."; const LONG: &str = long!("\ diff --git a/src/args.rs b/src/args.rs index 914a2a7c7..e2a5a09f1 100644 --- a/src/args.rs +++ b/src/args.rs @@ -791,13 +791,10 @@ impl ArgMatches { .types(self.types()?) .hidden(!self.hidden()) .parents(!self.no_ignore_parent()) - .ignore(!self.no_ignore()) - .git_global( - !self.no_ignore() - && !self.no_ignore_vcs() - && !self.no_ignore_global()) - .git_ignore(!self.no_ignore() && !self.no_ignore_vcs()) - .git_exclude(!self.no_ignore() && !self.no_ignore_vcs()) + .ignore(!self.no_ignore_dot()) + .git_global(!self.no_ignore_vcs() && !self.no_ignore_global()) + .git_ignore(!self.no_ignore_vcs()) + .git_exclude(!self.no_ignore_vcs()) .ignore_case_insensitive(self.ignore_file_case_insensitive()); if !self.no_ignore() { builder.add_custom_ignore_filename(".rgignore"); @@ -1103,6 +1100,11 @@ impl ArgMatches { self.is_present("no-ignore") || self.unrestricted_count() >= 1 } + /// Returns true if .ignore files should be ignored. + fn no_ignore_dot(&self) -> bool { + self.is_present("no-ignore-dot") || self.no_ignore() + } + /// Returns true if global ignore files should be ignored. fn no_ignore_global(&self) -> bool { self.is_present("no-ignore-global") || self.no_ignore() diff --git a/tests/feature.rs b/tests/feature.rs index d27fbf2f7..1e7ecc486 100644 --- a/tests/feature.rs +++ b/tests/feature.rs @@ -629,3 +629,19 @@ rgtest!(f993_null_data, |dir: Dir, mut cmd: TestCommand| { let expected = "foo\x00bar\x00baz\x00"; eqnice!(expected, cmd.stdout()); }); + +// See: https://github.com/BurntSushi/ripgrep/issues/1138 +rgtest!(f1138_no_ignore_dot, |dir: Dir, mut cmd: TestCommand| { + dir.create_dir(".git"); + dir.create(".gitignore", "foo"); + dir.create(".ignore", "bar"); + dir.create(".fzf-ignore", "quux"); + dir.create("foo", ""); + dir.create("bar", ""); + dir.create("quux", ""); + + cmd.arg("--sort").arg("path").arg("--files"); + eqnice!("quux\n", cmd.stdout()); + eqnice!("bar\nquux\n", cmd.arg("--no-ignore-dot").stdout()); + eqnice!("bar\n", cmd.arg("--ignore-file").arg(".fzf-ignore").stdout()); +});