Skip to content
Myr

Implement --ignore-file

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by David Peter · parent 8c1b037 · Browse files · 5 files+58 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

5 files+58 added−3 removed

  • tests:+22 added−3 removed
  • other:+36 added−0 removed

5 files+58 added−3 removed

modified:src/app.rs+11 added
121 unmodified lines
122 .number_of_values(1)123 .multiple(true),124 )125 .arg(126 arg("ignore-file")127 .long("ignore-file")128 .takes_value(true)129 .value_name("path")130 .number_of_values(1)131 .multiple(true),132 )133 .arg(134 arg("color")135 .long("color")136 .short("c")137 .takes_value(true)
89 unmodified lines
227 doc!(h, "exclude"228 , "Exclude entries that match the given glob pattern"229 , "Exclude files/directories that match the given glob pattern. This overrides any \230 other ignore logic. Multiple exclude patterns can be specified.");231 doc!(h, "ignore-file"232 , "Add a custom ignore-file in .gitignore format"233 , "Add a custom ignore-file in .gitignore format. These files have a low precedence.");234 doc!(h, "color"235 , "When to use colors: never, *auto*, always"236 , "Declare when to use color for the pattern match output:\n \237 'auto': show colors if the output goes to an interactive console (default)\n \
22 unmodified lines
modified:src/internal.rs+4 added
8 unmodified lines
9use std::ffi::OsString;10use std::process;11use std::time;12use std::io::Write;13use std::path::PathBuf;1415use exec::CommandTemplate;16use lscolors::LsColors;17use regex_syntax::Parser;
74 unmodified lines
92 pub command: Option<CommandTemplate>,9394 /// A list of glob patterns that should be excluded from the search.95 pub exclude_patterns: Vec<String>,9697 /// A list of custom ignore files.98 pub ignore_files: Vec<PathBuf>,99}100101/// Print error message to stderr and exit with status `1`.102pub fn error(message: &str) -> ! {
155 unmodified lines
modified:src/main.rs+4 added
189 unmodified lines
190 exclude_patterns: matches191 .values_of("exclude")192 .map(|v| v.map(|p| String::from("!") + p).collect())193 .unwrap_or_else(|| vec![]),194 ignore_files: matches195 .values_of("ignore-file")196 .map(|vs| vs.map(PathBuf::from).collect())197 .unwrap_or_else(|| vec![]),198 };199200 match RegexBuilder::new(&pattern_regex)201 .case_insensitive(!config.case_sensitive)
13 unmodified lines
modified:src/walk.rs+17 added
12 unmodified lines
13use internal::{error, FdOptions, EXITCODE_SIGINT, MAX_BUFFER_LENGTH};14use output;1516use std::process;17use std::error::Error;18use std::path::PathBuf;19use std::sync::{Arc, Mutex};20use std::sync::atomic::{AtomicBool, Ordering};21use std::sync::mpsc::channel;
54 unmodified lines
76 if config.read_fdignore {77 walker.add_custom_ignore_filename(".fdignore");78 }7980 for ignore_file in &config.ignore_files {81 let result = walker.add_ignore(ignore_file);82 if let Some(err) = result {83 match err {84 ignore::Error::Partial(_) => (),85 _ => {86 error(&format!(87 "Error while parsing custom ignore file '{}': {}.",88 ignore_file.to_string_lossy(),89 err.description()90 ));91 }92 }93 }94 }9596 for path_entry in path_iter {97 walker.add(path_entry.as_path());98 }99
182 unmodified lines
modified:tests/tests.rs+22 added-3 removed
295 unmodified lines
296 one/two/three/directory_foo",297 );298}299300/// Custom ignore files300/// .gitignore and .fdignore301#[test]302fn test_custom_ignore() {302fn test_gitignore_and_fdignore() {303 let files = &[304 "ignored-by-nothing",305 "ignored-by-fdignore",306 "ignored-by-gitignore",
27 unmodified lines
334 ignored-by-both",335 );336}337338/// Precedence of custom ignore files338/// Precedence of .fdignore files339#[test]340fn test_custom_ignore_precedence() {341 let dirs = &["inner"];342 let files = &["inner/foo"];
34 unmodified lines
377 one/two/three/directory_foo",378 );379}380381/// Custom ignore files (--ignore-file)382#[test]383fn test_custom_ignore_files() {384 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);385386 // Ignore 'C.Foo2' and everything in 'three'.387 fs::File::create(te.test_root().join("custom.ignore"))388 .unwrap()389 .write_all(b"C.Foo2\nthree")390 .unwrap();391392 te.assert_output(393 &["--ignore-file", "custom.ignore", "foo"],394 "a.foo395 one/b.foo396 one/two/c.foo",397 );398}399400/// Ignored files with ripgrep aliases (-u / -uu)401#[test]402fn test_no_ignore_aliases() {403 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
600 unmodified lines