1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2024-12-07 11:13:17 +02:00

config: add --no-ignore-dot flag

This flag causes ripgrep to ignore `.ignore` files.

Closes #1138
This commit is contained in:
Andrew Gallant 2019-01-26 13:40:12 -05:00
parent 9d703110cf
commit 12a6ca45f9
No known key found for this signature in database
GPG Key ID: B2E3A4923F8B0D44
5 changed files with 53 additions and 10 deletions

View File

@ -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.

View File

@ -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]"

View File

@ -586,6 +586,7 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
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<RGArg>) {
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<RGArg>) {
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<RGArg>) {
const SHORT: &str = "Don't respect global ignore files.";
const LONG: &str = long!("\

View File

@ -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()

View File

@ -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());
});