Skip to content
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
12 changes: 10 additions & 2 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,20 @@ impl WorkerState {
fn build_overrides(&self, paths: &[PathBuf]) -> Result<Override> {
let first_path = &paths[0];
let config = &self.config;

let mut builder = OverrideBuilder::new(first_path);

for pattern in &config.exclude_patterns {
// pattern is "!<glob>". If the glob contains "/" the ignore crate
// would anchor it to first_path, which is wrong for --exclude.
// Always make such patterns unanchored with a "**/" prefix.
let glob = &pattern[1..]; // strip leading "!"
let normalized = if glob.contains('/') && !glob.starts_with("**/") {
format!("!**/{}", glob)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will significantly change the behavior. That means that if you exclude something like "/a/b" that will now start also excluding

"foo/a/b" from the base directory.

I'll put some more thoughts on how we could approach solving this on the issue itself, but I don't thik this is a good solution for this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we could add a special case for root paths, or try to implement a different gitignore root for each given search path

} else {
pattern.clone()
};
builder
.add(pattern)
.add(&normalized)
.map_err(|e| anyhow!("Malformed exclude pattern: {}", e))?;
}

Expand Down