Merge pull request #1852 from fischman/1727-ignore-contain
Before adoption: this commit came in with the history the project adopted, so no landing records it.
`--ignore-contain`: ignore directories containing a named entry.
authored by Thayne McCombs · committed by GitHub · parents 9508153, f3a8bb7 · Browse files · 7 files·+77 added−3 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+77 added−3 removed
- tests:+51 added−0 removed
- other:+26 added−3 removed
Provenance
- Commit
bf81fb9- Tree
87cf089- Author
Thayne McCombs <astrothayne@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
9508153- Parent 2
f3a8bb7
7 files changed+77 added−3 removed
modified:doc/fd.1+4 added
263 unmodified lines264 Examples:265 \-\-exclude '*.pyc'266 \-\-exclude node_modules267 .TP268+.BI "\-\-ignore-contain " name269+Exclude directories that (directly) contain the given name.270+This option can be specified multiple times.271+.TP272 .BI "\-\-ignore-file " path273 Add a custom ignore-file in '.gitignore' format.274 These files have a low precedence.275 .TP303 unmodified linesmodified:src/cli.rs+4 added
526 unmodified lines527 help = "Add hyperlinks to output paths"528 )]529 pub hyperlink: HyperlinkWhen,530 531+ /// Ignore directories containing the named entry.532+ #[arg(long, value_name = "name")]533+ pub ignore_contain: Vec<String>,534+535 /// Set number of threads to use for searching & executing (default: number536 /// of available CPU cores)537 #[arg(long, short = 'j', value_name = "num", hide_short_help = true, value_parser = str::parse::<NonZeroUsize>)]538 pub threads: Option<NonZeroUsize>,407 unmodified linesmodified:src/config.rs+3 added
128 unmodified lines129 pub strip_cwd_prefix: bool,130 131 /// Whether or not to use hyperlinks on paths132 pub hyperlink: bool,133+134+ /// Names that should stop traversal down their parent. (e.g. https://bford.info/cachedir/).135+ pub ignore_contain: Vec<String>,136 }137 138 impl Config {139 /// Check whether results are being printed.4 unmodified linesmodified:src/main.rs+1 added
324 unmodified lines325 path_separator,326 actual_path_separator,327 max_results: opts.max_results(),328 strip_cwd_prefix: opts.strip_cwd_prefix(|| !(opts.null_separator || has_command)),329+ ignore_contain: opts.ignore_contain,330 })331 }332 333 fn extract_command(opts: &mut Opts, colored_output: bool) -> Result<Option<CommandSet>> {159 unmodified linesmodified:src/walk.rs+13 added-2 removed
459 unmodified lines460 if quit_flag.load(Ordering::Relaxed) {461 return WalkState::Quit;462 }463 464- let entry = match entry {465- Ok(ref e) if e.depth() == 0 => {464+ if let Ok(e) = &entry {465+ let entry_path = e.path();466+ if entry_path.is_dir()467+ && config468+ .ignore_contain469+ .iter()470+ .any(|ic| entry_path.join(ic).exists())471+ {472+ return WalkState::Skip;473+ }474+ if e.depth() == 0 {475 // Skip the root directory entry.476 return WalkState::Continue;477 }478+ }479+ let entry = match entry {480 Ok(e) => DirEntry::normal(e),481 Err(ignore::Error::WithPath {482 path,483 err: inner_err,197 unmodified linesmodified:tests/tests.rs+51 added
2705 unmodified lines2706 );2707 2708 te.assert_output(&["--hyperlink=always", "a.foo"], &expected);2709 }2710+2711+#[test]2712+fn test_ignore_contain() {2713+ let te = TestEnv::new(2714+ &["include", "exclude", "exclude/sub", "other"],2715+ &[2716+ "top",2717+ "include/foo",2718+ "exclude/CACHEDIR.TAG",2719+ "exclude/sub/nope",2720+ "other/ignoremyparent",2721+ ],2722+ );2723+ let expected = "include/2724+ include/foo2725+ symlink2726+ top";2727+ te.assert_output(2728+ &[2729+ "--ignore-contain=CACHEDIR.TAG",2730+ "--ignore-contain=ignoremyparent",2731+ ".",2732+ ],2733+ expected,2734+ );2735+}2736+2737+#[test]2738+fn test_ignore_contain_precedence_over_depth_check() {2739+ let te = TestEnv::new(2740+ &["include", "exclude", "exclude/sub"],2741+ &[2742+ "top",2743+ "include/foo",2744+ "exclude/CACHEDIR.TAG",2745+ "exclude/sub/nope",2746+ ],2747+ );2748+ let expected = "include/foo";2749+ te.assert_output(2750+ &["--ignore-contain=CACHEDIR.TAG", "--min-depth=2", "."],2751+ expected,2752+ );2753+}2754+2755+#[test]2756+fn test_ignore_contain_precedence_over_root_check() {2757+ let te = TestEnv::new(&["include"], &["CACHEDIR.TAG", "top", "include/foo"]);2758+ let expected = "";2759+ te.assert_output(&["--ignore-contain=CACHEDIR.TAG", "."], expected);2760+}modified:CHANGELOG.md+1 added-1 removed
1 # Upcoming release2 3 ## Features4+- Add `--ignore-contain` option to ignore directories containing a named entry (e.g. to ignore [`CACHEDIR.TAG`](https://bford.info/cachedir/)); see #1727 (@fischman).5 5-6 ## Bugfixes7 8 - Fix Windows hyperlink generation for paths with spaces. (#1872)9 833 unmodified lines