Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support absolute path in exclude #1609

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,23 @@ fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result<Config
.map(crate::fmt::FormatTemplate::parse),
command: command.map(Arc::new),
batch_size: opts.batch_size,
exclude_patterns: opts.exclude.iter().map(|p| String::from("!") + p).collect(),
exclude_patterns: opts
.exclude
.iter()
.map(|p| {
let path = Path::new(p);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't a path, it's a pattern.

What if there is a glob that occurs between the root and the search path?

let relative_path = if path.is_absolute() {
let cwd = env::current_dir().unwrap_or("".into());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if one or more search paths is given to fd, since it needs to be relative to the search path, which may not be the current directory.

path.strip_prefix(cwd)
.unwrap()
.to_string_lossy()
.to_string()
} else {
p.to_string()
};
String::from("!") + &relative_path
})
.collect(),
ignore_files: std::mem::take(&mut opts.ignore_file),
size_constraints: size_limits,
time_constraints,
Expand Down