Add --no-ignore-vcs option

When passed, .gitignore files will not be respected.
This commit is contained in:
ptzz 2017-11-21 22:54:00 +01:00 committed by David Peter
parent c0bfc65d88
commit 9bd1d12c00
7 changed files with 46 additions and 8 deletions

View File

@ -30,9 +30,10 @@ is a simple, fast and user-friendly alternative to
Search hidden files and directories.
.TP
.B \-I, \-\-no\-ignore
Do not respect any
.BR gitignore (5)
files.
Don't respect ignore files (.gitignore, .ignore, etc.)
.TP
.B \-\-no\-ignore\-vcs
Don't respect version control ignore files (e.g., .gitignore).
.TP
.B \-s, \-\-case\-sensitive
Perform a case-sensitive search (default: smart case).

View File

@ -42,6 +42,7 @@ pub fn build_app() -> App<'static, 'static> {
.setting(AppSettings::DeriveDisplayOrder)
.arg(arg("hidden").long("hidden").short("H"))
.arg(arg("no-ignore").long("no-ignore").short("I"))
.arg(arg("no-ignore-vcs").long("no-ignore-vcs"))
.arg(
arg("rg-alias-hidden-ignore")
.short("u")
@ -137,6 +138,10 @@ fn usage() -> HashMap<&'static str, Help> {
, "Do not respect .(git)ignore files"
, "Show search results from files and directories that would otherwise be ignored by \
'.*ignore' files.");
doc!(h, "no-ignore-vcs"
, "Do not respect .gitignore files"
, "Show search results from files and directories that would otherwise be ignored by \
'.gitignore' files.");
doc!(h, "case-sensitive"
, "Case-sensitive search (default: smart case)"
, "Perform a case-sensitive search. By default, fd uses case-insensitive searches, \

View File

@ -37,9 +37,12 @@ pub struct FdOptions {
/// Whether to ignore hidden files and directories (or not).
pub ignore_hidden: bool,
/// Whether to respect VCS ignore files (`.gitignore`, `.ignore`, ..) or not.
/// Whether to respect ignore files (`.gitignore`, `.ignore`, ..) or not.
pub read_ignore: bool,
/// Whether to respect VCS ignore files (`.gitignore`, ..) or not.
pub read_gitignore: bool,
/// Whether to follow symlinks or not.
pub follow_links: bool,

View File

@ -114,6 +114,9 @@ fn main() {
matches.occurrences_of("rg-alias-hidden-ignore") >= 2),
read_ignore: !(matches.is_present("no-ignore") ||
matches.is_present("rg-alias-hidden-ignore")),
read_gitignore: !(matches.is_present("no-ignore") ||
matches.is_present("rg-alias-hidden-ignore") ||
matches.is_present("no-ignore-vcs")),
follow_links: matches.is_present("follow"),
null_separator: matches.is_present("null_separator"),
max_depth: matches.value_of("depth").and_then(|n| {

View File

@ -67,10 +67,10 @@ pub fn scan(root: &Path, pattern: Arc<Regex>, config: Arc<FdOptions>) {
let walker = WalkBuilder::new(root)
.hidden(config.ignore_hidden)
.ignore(config.read_ignore)
.git_ignore(config.read_ignore)
.parents(config.read_ignore)
.git_global(config.read_ignore)
.git_exclude(config.read_ignore)
.git_ignore(config.read_gitignore)
.parents(config.read_ignore || config.read_gitignore)
.git_global(config.read_gitignore)
.git_exclude(config.read_gitignore)
.overrides(overrides)
.follow_links(config.follow_links)
.max_depth(config.max_depth)

View File

@ -50,6 +50,7 @@ fn create_working_directory() -> Result<TempDir, io::Error> {
fs::File::create(root.join("one/two/three/d.foo"))?;
fs::create_dir(root.join("one/two/three/directory_foo"))?;
fs::File::create(root.join("ignored.foo"))?;
fs::File::create(root.join("gitignored.foo"))?;
fs::File::create(root.join(".hidden.foo"))?;
fs::File::create(root.join("e1 e2"))?;
@ -62,6 +63,10 @@ fn create_working_directory() -> Result<TempDir, io::Error> {
fs::File::create(root.join(".ignore"))?.write_all(
b"ignored.foo",
)?;
fs::File::create(root.join(".gitignore"))?.write_all(
b"gitignored.foo",
)?;
}
Ok(temp_dir)

View File

@ -228,6 +228,7 @@ fn test_no_ignore() {
&["--no-ignore", "foo"],
"a.foo
ignored.foo
gitignored.foo
one/b.foo
one/two/c.foo
one/two/C.Foo2
@ -240,6 +241,24 @@ fn test_no_ignore() {
".hidden.foo
a.foo
ignored.foo
gitignored.foo
one/b.foo
one/two/c.foo
one/two/C.Foo2
one/two/three/d.foo
one/two/three/directory_foo",
);
}
/// VCS ignored files (--no-ignore-vcs)
#[test]
fn test_no_ignore_vcs() {
let te = TestEnv::new();
te.assert_output(
&["--no-ignore-vcs", "foo"],
"a.foo
gitignored.foo
one/b.foo
one/two/c.foo
one/two/C.Foo2
@ -257,6 +276,7 @@ fn test_no_ignore_aliases() {
&["-u", "foo"],
"a.foo
ignored.foo
gitignored.foo
one/b.foo
one/two/c.foo
one/two/C.Foo2
@ -269,6 +289,7 @@ fn test_no_ignore_aliases() {
".hidden.foo
a.foo
ignored.foo
gitignored.foo
one/b.foo
one/two/c.foo
one/two/C.Foo2