Skip to content
Myr

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

7 files+77 added−3 removed

modified:doc/fd.1+4 added
263 unmodified lines
264Examples:265 \-\-exclude '*.pyc'266 \-\-exclude node_modules267.TP268.BI "\-\-ignore-contain " name269Exclude directories that (directly) contain the given name.270This option can be specified multiple times.271.TP272.BI "\-\-ignore-file " path273Add a custom ignore-file in '.gitignore' format.274These files have a low precedence.275.TP
303 unmodified lines
modified:src/cli.rs+4 added
526 unmodified lines
527 help = "Add hyperlinks to output paths"528 )]529 pub hyperlink: HyperlinkWhen,530531 /// Ignore directories containing the named entry.532 #[arg(long, value_name = "name")]533 pub ignore_contain: Vec<String>,534535 /// 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 lines
modified:src/config.rs+3 added
128 unmodified lines
129 pub strip_cwd_prefix: bool,130131 /// Whether or not to use hyperlinks on paths132 pub hyperlink: bool,133134 /// Names that should stop traversal down their parent. (e.g. https://bford.info/cachedir/).135 pub ignore_contain: Vec<String>,136}137138impl Config {139 /// Check whether results are being printed.
4 unmodified lines
modified:src/main.rs+1 added
324 unmodified lines
325 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}332333fn extract_command(opts: &mut Opts, colored_output: bool) -> Result<Option<CommandSet>> {
159 unmodified lines
modified:src/walk.rs+13 added-2 removed
459 unmodified lines
460 if quit_flag.load(Ordering::Relaxed) {461 return WalkState::Quit;462 }463464 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 lines
modified:tests/tests.rs+51 added
2705 unmodified lines
2706 );27072708 te.assert_output(&["--hyperlink=always", "a.foo"], &expected);2709}27102711#[test]2712fn 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}27362737#[test]2738fn 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}27542755#[test]2756fn 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 release23## 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).556## Bugfixes78- Fix Windows hyperlink generation for paths with spaces. (#1872)9
833 unmodified lines