Add --no-ignore-vcs option
Before adoption: this commit came in with the history the project adopted, so no landing records it.
When passed, .gitignore files will not be respected.
authored by ptzz · committed by David Peter · parent c0bfc65 · Browse files · 7 files·+46 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+46 added−8 removed
- tests:+26 added−0 removed
- other:+20 added−8 removed
Provenance
- Commit
9bd1d12- Tree
fe8951c- Author
ptzz <ptzzptzzp@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
c0bfc65
7 files changed+46 added−8 removed
modified:doc/fd.1+4 added-3 removed
28 unmodified lines29 .B \-H, \-\-hidden30 Search hidden files and directories.31 .TP32 .B \-I, \-\-no\-ignore33-Do not respect any34-.BR gitignore (5)35-files.33+Don't respect ignore files (.gitignore, .ignore, etc.)34 .TP35+.B \-\-no\-ignore\-vcs36+Don't respect version control ignore files (e.g., .gitignore).37+.TP38 .B \-s, \-\-case\-sensitive39 Perform a case-sensitive search (default: smart case).40 .TP41 .B \-i, \-\-ignore\-case96 unmodified linesmodified:src/app.rs+5 added
40 unmodified lines41 .setting(AppSettings::ColoredHelp)42 .setting(AppSettings::DeriveDisplayOrder)43 .arg(arg("hidden").long("hidden").short("H"))44 .arg(arg("no-ignore").long("no-ignore").short("I"))45+ .arg(arg("no-ignore-vcs").long("no-ignore-vcs"))46 .arg(47 arg("rg-alias-hidden-ignore")48 .short("u")49 .multiple(true)87 unmodified lines137 doc!(h, "no-ignore"138 , "Do not respect .(git)ignore files"139 , "Show search results from files and directories that would otherwise be ignored by \140 '.*ignore' files.");141+ doc!(h, "no-ignore-vcs"142+ , "Do not respect .gitignore files"143+ , "Show search results from files and directories that would otherwise be ignored by \144+ '.gitignore' files.");145 doc!(h, "case-sensitive"146 , "Case-sensitive search (default: smart case)"147 , "Perform a case-sensitive search. By default, fd uses case-insensitive searches, \148 unless the pattern contains an uppercase character (smart case).");74 unmodified linesmodified:src/internal.rs+4 added-1 removed
35 unmodified lines36 37 /// Whether to ignore hidden files and directories (or not).38 pub ignore_hidden: bool,39 40- /// Whether to respect VCS ignore files (`.gitignore`, `.ignore`, ..) or not.40+ /// Whether to respect ignore files (`.gitignore`, `.ignore`, ..) or not.41 pub read_ignore: bool,42 43+ /// Whether to respect VCS ignore files (`.gitignore`, ..) or not.44+ pub read_gitignore: bool,45+46 /// Whether to follow symlinks or not.47 pub follow_links: bool,48 49 /// Whether elements of output should be separated by a null character68 unmodified linesmodified:src/main.rs+3 added
112 unmodified lines113 ignore_hidden: !(matches.is_present("hidden") ||114 matches.occurrences_of("rg-alias-hidden-ignore") >= 2),115 read_ignore: !(matches.is_present("no-ignore") ||116 matches.is_present("rg-alias-hidden-ignore")),117+ read_gitignore: !(matches.is_present("no-ignore") ||118+ matches.is_present("rg-alias-hidden-ignore") ||119+ matches.is_present("no-ignore-vcs")),120 follow_links: matches.is_present("follow"),121 null_separator: matches.is_present("null_separator"),122 max_depth: matches.value_of("depth").and_then(|n| {123 usize::from_str_radix(n, 10).ok()39 unmodified linesmodified:src/walk.rs+4 added-4 removed
65 unmodified lines66 67 let walker = WalkBuilder::new(root)68 .hidden(config.ignore_hidden)69 .ignore(config.read_ignore)70- .git_ignore(config.read_ignore)71- .parents(config.read_ignore)72- .git_global(config.read_ignore)73- .git_exclude(config.read_ignore)70+ .git_ignore(config.read_gitignore)71+ .parents(config.read_ignore || config.read_gitignore)72+ .git_global(config.read_gitignore)73+ .git_exclude(config.read_gitignore)74 .overrides(overrides)75 .follow_links(config.follow_links)76 .max_depth(config.max_depth)77 .threads(threads)164 unmodified linesmodified:tests/testenv/mod.rs+5 added
48 unmodified lines49 fs::File::create(root.join("one/two/C.Foo2"))?;50 fs::File::create(root.join("one/two/three/d.foo"))?;51 fs::create_dir(root.join("one/two/three/directory_foo"))?;52 fs::File::create(root.join("ignored.foo"))?;53+ fs::File::create(root.join("gitignored.foo"))?;54 fs::File::create(root.join(".hidden.foo"))?;55 fs::File::create(root.join("e1 e2"))?;56 57 #[cfg(unix)] unix::fs::symlink(root.join("one/two"), root.join("symlink"))?;4 unmodified lines62 63 fs::File::create(root.join(".ignore"))?.write_all(64 b"ignored.foo",65 )?;66+67+ fs::File::create(root.join(".gitignore"))?.write_all(68+ b"gitignored.foo",69+ )?;70 }71 72 Ok(temp_dir)73 }124 unmodified linesmodified:tests/tests.rs+21 added
226 unmodified lines227 te.assert_output(228 &["--no-ignore", "foo"],229 "a.foo230 ignored.foo231+ gitignored.foo232 one/b.foo233 one/two/c.foo234 one/two/C.Foo2235 one/two/three/d.foo4 unmodified lines240 &["--hidden", "--no-ignore", "foo"],241 ".hidden.foo242 a.foo243 ignored.foo244+ gitignored.foo245 one/b.foo246 one/two/c.foo247 one/two/C.Foo2248 one/two/three/d.foo249 one/two/three/directory_foo",250 );251 }252 253+/// VCS ignored files (--no-ignore-vcs)254+#[test]255+fn test_no_ignore_vcs() {256+ let te = TestEnv::new();257+258+ te.assert_output(259+ &["--no-ignore-vcs", "foo"],260+ "a.foo261+ gitignored.foo262+ one/b.foo263+ one/two/c.foo264+ one/two/C.Foo2265+ one/two/three/d.foo266+ one/two/three/directory_foo",267+ );268+}269+270 /// Ignored files with ripgrep aliases (-u / -uu)271 #[test]272 fn test_no_ignore_aliases() {273 let te = TestEnv::new();1 unmodified line275 te.assert_output(276 &["-u", "foo"],277 "a.foo278 ignored.foo279+ gitignored.foo280 one/b.foo281 one/two/c.foo282 one/two/C.Foo2283 one/two/three/d.foo4 unmodified lines288 &["-uu", "foo"],289 ".hidden.foo290 a.foo291 ignored.foo292+ gitignored.foo293 one/b.foo294 one/two/c.foo295 one/two/C.Foo2296 one/two/three/d.foo398 unmodified lines