mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-05-19 09:40:22 -07:00
Add --no-ignore-vcs flag.
This flag will respect .ignore but not .gitignore. Closes #68.
This commit is contained in:
parent
423f2a1927
commit
8eeb0c0b60
6
doc/rg.1
6
doc/rg.1
@ -227,6 +227,12 @@ Don\[aq]t respect ignore files in parent directories.
|
|||||||
.RS
|
.RS
|
||||||
.RE
|
.RE
|
||||||
.TP
|
.TP
|
||||||
|
.B \-\-no\-ignore\-vcs
|
||||||
|
Don\[aq]t respect version control ignore files (e.g., .gitignore).
|
||||||
|
Note that .ignore files will continue to be respected.
|
||||||
|
.RS
|
||||||
|
.RE
|
||||||
|
.TP
|
||||||
.B \-p, \-\-pretty
|
.B \-p, \-\-pretty
|
||||||
Alias for \-\-color=always \-\-heading \-n.
|
Alias for \-\-color=always \-\-heading \-n.
|
||||||
.RS
|
.RS
|
||||||
|
@ -147,6 +147,10 @@ the raw speed of grep.
|
|||||||
--no-ignore-parent
|
--no-ignore-parent
|
||||||
: Don't respect ignore files in parent directories.
|
: Don't respect ignore files in parent directories.
|
||||||
|
|
||||||
|
--no-ignore-vcs
|
||||||
|
: Don't respect version control ignore files (e.g., .gitignore).
|
||||||
|
Note that .ignore files will continue to be respected.
|
||||||
|
|
||||||
-p, --pretty
|
-p, --pretty
|
||||||
: Alias for --color=always --heading -n.
|
: Alias for --color=always --heading -n.
|
||||||
|
|
||||||
|
10
src/args.rs
10
src/args.rs
@ -147,6 +147,10 @@ Less common options:
|
|||||||
--no-ignore-parent
|
--no-ignore-parent
|
||||||
Don't respect ignore files in parent directories.
|
Don't respect ignore files in parent directories.
|
||||||
|
|
||||||
|
--no-ignore-vcs
|
||||||
|
Don't respect version control ignore files (e.g., .gitignore).
|
||||||
|
Note that .ignore files will continue to be respected.
|
||||||
|
|
||||||
-p, --pretty
|
-p, --pretty
|
||||||
Alias for --color=always --heading -n.
|
Alias for --color=always --heading -n.
|
||||||
|
|
||||||
@ -205,6 +209,7 @@ pub struct RawArgs {
|
|||||||
flag_no_heading: bool,
|
flag_no_heading: bool,
|
||||||
flag_no_ignore: bool,
|
flag_no_ignore: bool,
|
||||||
flag_no_ignore_parent: bool,
|
flag_no_ignore_parent: bool,
|
||||||
|
flag_no_ignore_vcs: bool,
|
||||||
flag_no_line_number: bool,
|
flag_no_line_number: bool,
|
||||||
flag_no_mmap: bool,
|
flag_no_mmap: bool,
|
||||||
flag_no_filename: bool,
|
flag_no_filename: bool,
|
||||||
@ -250,6 +255,7 @@ pub struct Args {
|
|||||||
mmap: bool,
|
mmap: bool,
|
||||||
no_ignore: bool,
|
no_ignore: bool,
|
||||||
no_ignore_parent: bool,
|
no_ignore_parent: bool,
|
||||||
|
no_ignore_vcs: bool,
|
||||||
quiet: bool,
|
quiet: bool,
|
||||||
replace: Option<Vec<u8>>,
|
replace: Option<Vec<u8>>,
|
||||||
text: bool,
|
text: bool,
|
||||||
@ -374,6 +380,9 @@ impl RawArgs {
|
|||||||
no_ignore_parent:
|
no_ignore_parent:
|
||||||
// --no-ignore implies --no-ignore-parent
|
// --no-ignore implies --no-ignore-parent
|
||||||
self.flag_no_ignore_parent || no_ignore,
|
self.flag_no_ignore_parent || no_ignore,
|
||||||
|
no_ignore_vcs:
|
||||||
|
// --no-ignore implies --no-ignore-vcs
|
||||||
|
self.flag_no_ignore_vcs || no_ignore,
|
||||||
quiet: self.flag_quiet,
|
quiet: self.flag_quiet,
|
||||||
replace: self.flag_replace.clone().map(|s| s.into_bytes()),
|
replace: self.flag_replace.clone().map(|s| s.into_bytes()),
|
||||||
text: text,
|
text: text,
|
||||||
@ -639,6 +648,7 @@ impl Args {
|
|||||||
let mut ig = Ignore::new();
|
let mut ig = Ignore::new();
|
||||||
ig.ignore_hidden(!self.hidden);
|
ig.ignore_hidden(!self.hidden);
|
||||||
ig.no_ignore(self.no_ignore);
|
ig.no_ignore(self.no_ignore);
|
||||||
|
ig.no_ignore_vcs(self.no_ignore_vcs);
|
||||||
ig.add_types(self.types.clone());
|
ig.add_types(self.types.clone());
|
||||||
if !self.no_ignore_parent {
|
if !self.no_ignore_parent {
|
||||||
try!(ig.push_parents(path));
|
try!(ig.push_parents(path));
|
||||||
|
@ -89,9 +89,11 @@ pub struct Ignore {
|
|||||||
types: Types,
|
types: Types,
|
||||||
/// Whether to ignore hidden files or not.
|
/// Whether to ignore hidden files or not.
|
||||||
ignore_hidden: bool,
|
ignore_hidden: bool,
|
||||||
/// When true, don't look at .gitignore or .agignore files for ignore
|
/// When true, don't look at .gitignore or .ignore files for ignore
|
||||||
/// rules.
|
/// rules.
|
||||||
no_ignore: bool,
|
no_ignore: bool,
|
||||||
|
/// When true, don't look at .gitignore files for ignore rules.
|
||||||
|
no_ignore_vcs: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ignore {
|
impl Ignore {
|
||||||
@ -104,6 +106,7 @@ impl Ignore {
|
|||||||
types: Types::empty(),
|
types: Types::empty(),
|
||||||
ignore_hidden: true,
|
ignore_hidden: true,
|
||||||
no_ignore: false,
|
no_ignore: false,
|
||||||
|
no_ignore_vcs: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,6 +122,12 @@ impl Ignore {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// When set, VCS ignore files are ignored.
|
||||||
|
pub fn no_ignore_vcs(&mut self, yes: bool) -> &mut Ignore {
|
||||||
|
self.no_ignore_vcs = yes;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Add a set of globs that overrides all other match logic.
|
/// Add a set of globs that overrides all other match logic.
|
||||||
pub fn add_override(&mut self, gi: Gitignore) -> &mut Ignore {
|
pub fn add_override(&mut self, gi: Gitignore) -> &mut Ignore {
|
||||||
self.overrides = Overrides::new(Some(gi));
|
self.overrides = Overrides::new(Some(gi));
|
||||||
@ -143,6 +152,9 @@ impl Ignore {
|
|||||||
let mut path = &*path;
|
let mut path = &*path;
|
||||||
let mut saw_git = path.join(".git").is_dir();
|
let mut saw_git = path.join(".git").is_dir();
|
||||||
let mut ignore_names = IGNORE_NAMES.to_vec();
|
let mut ignore_names = IGNORE_NAMES.to_vec();
|
||||||
|
if self.no_ignore_vcs {
|
||||||
|
ignore_names.retain(|&name| name != ".gitignore");
|
||||||
|
}
|
||||||
let mut ignore_dir_results = vec![];
|
let mut ignore_dir_results = vec![];
|
||||||
while let Some(parent) = path.parent() {
|
while let Some(parent) = path.parent() {
|
||||||
if self.no_ignore {
|
if self.no_ignore {
|
||||||
@ -173,10 +185,13 @@ impl Ignore {
|
|||||||
pub fn push<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error> {
|
pub fn push<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error> {
|
||||||
if self.no_ignore {
|
if self.no_ignore {
|
||||||
self.stack.push(IgnoreDir::empty(path));
|
self.stack.push(IgnoreDir::empty(path));
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
} else if self.no_ignore_vcs {
|
||||||
|
self.push_ignore_dir(IgnoreDir::without_vcs(path))
|
||||||
|
} else {
|
||||||
self.push_ignore_dir(IgnoreDir::new(path))
|
self.push_ignore_dir(IgnoreDir::new(path))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Pushes the result of building a directory matcher on to the stack.
|
/// Pushes the result of building a directory matcher on to the stack.
|
||||||
///
|
///
|
||||||
@ -305,13 +320,18 @@ pub struct IgnoreDir {
|
|||||||
|
|
||||||
impl IgnoreDir {
|
impl IgnoreDir {
|
||||||
/// Create a new matcher for the given directory.
|
/// Create a new matcher for the given directory.
|
||||||
///
|
|
||||||
/// If no ignore glob patterns could be found in the directory then `None`
|
|
||||||
/// is returned.
|
|
||||||
pub fn new<P: AsRef<Path>>(path: P) -> Result<IgnoreDir, Error> {
|
pub fn new<P: AsRef<Path>>(path: P) -> Result<IgnoreDir, Error> {
|
||||||
IgnoreDir::with_ignore_names(path, IGNORE_NAMES.iter())
|
IgnoreDir::with_ignore_names(path, IGNORE_NAMES.iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new matcher for the given directory.
|
||||||
|
///
|
||||||
|
/// Don't respect VCS ignore files.
|
||||||
|
pub fn without_vcs<P: AsRef<Path>>(path: P) -> Result<IgnoreDir, Error> {
|
||||||
|
let names = IGNORE_NAMES.iter().filter(|name| **name != ".gitignore");
|
||||||
|
IgnoreDir::with_ignore_names(path, names)
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new IgnoreDir that never matches anything with the given path.
|
/// Create a new IgnoreDir that never matches anything with the given path.
|
||||||
pub fn empty<P: AsRef<Path>>(path: P) -> IgnoreDir {
|
pub fn empty<P: AsRef<Path>>(path: P) -> IgnoreDir {
|
||||||
IgnoreDir {
|
IgnoreDir {
|
||||||
|
@ -687,6 +687,18 @@ be, to a very large extent, the result of luck. Sherlock Holmes
|
|||||||
assert_eq!(lines, expected);
|
assert_eq!(lines, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// See: https://github.com/BurntSushi/ripgrep/issues/68
|
||||||
|
clean!(feature_68, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
||||||
|
wd.create(".gitignore", "foo");
|
||||||
|
wd.create(".ignore", "bar");
|
||||||
|
wd.create("foo", "test");
|
||||||
|
wd.create("bar", "test");
|
||||||
|
cmd.arg("--no-ignore-vcs");
|
||||||
|
|
||||||
|
let lines: String = wd.stdout(&mut cmd);
|
||||||
|
assert_eq!(lines, "foo:test\n");
|
||||||
|
});
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn binary_nosearch() {
|
fn binary_nosearch() {
|
||||||
let wd = WorkDir::new("binary_nosearch");
|
let wd = WorkDir::new("binary_nosearch");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user