From 9bd1d12c005c0d858acab663fdba954ba92239d8 Mon Sep 17 00:00:00 2001 From: ptzz Date: Tue, 21 Nov 2017 22:54:00 +0100 Subject: [PATCH] Add --no-ignore-vcs option When passed, .gitignore files will not be respected. --- doc/fd.1 | 7 ++++--- src/app.rs | 5 +++++ src/internal.rs | 5 ++++- src/main.rs | 3 +++ src/walk.rs | 8 ++++---- tests/testenv/mod.rs | 5 +++++ tests/tests.rs | 21 +++++++++++++++++++++ 7 files changed, 46 insertions(+), 8 deletions(-) diff --git a/doc/fd.1 b/doc/fd.1 index 1916e48..02c5426 100644 --- a/doc/fd.1 +++ b/doc/fd.1 @@ -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). diff --git a/src/app.rs b/src/app.rs index cef5274..9eadbd8 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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, \ diff --git a/src/internal.rs b/src/internal.rs index 604d18e..699aeac 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -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, diff --git a/src/main.rs b/src/main.rs index bfdbe91..57e2a29 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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| { diff --git a/src/walk.rs b/src/walk.rs index 874d41b..4737787 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -67,10 +67,10 @@ pub fn scan(root: &Path, pattern: Arc, config: Arc) { 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) diff --git a/tests/testenv/mod.rs b/tests/testenv/mod.rs index 6fdf447..ceed8fe 100644 --- a/tests/testenv/mod.rs +++ b/tests/testenv/mod.rs @@ -50,6 +50,7 @@ fn create_working_directory() -> Result { 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 { 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) diff --git a/tests/tests.rs b/tests/tests.rs index fd137bb..975a91b 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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