diff --git a/src/walk.rs b/src/walk.rs index b37cc835e..2261efb97 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -330,12 +330,20 @@ impl WorkerState { fn build_overrides(&self, paths: &[PathBuf]) -> Result { let first_path = &paths[0]; let config = &self.config; - let mut builder = OverrideBuilder::new(first_path); for pattern in &config.exclude_patterns { + // pattern is "!". 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) + } else { + pattern.clone() + }; builder - .add(pattern) + .add(&normalized) .map_err(|e| anyhow!("Malformed exclude pattern: {}", e))?; }