Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
worktree: Do not scan for .gitignore files beyond project root. (#8189)
Piotr Osiewicz94bc216bbd35
diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rsindex de767bea0e5..e3cb5072f0e 100644--- a/crates/project/src/worktree.rs+++ b/crates/project/src/worktree.rs@@ -2252,11 +2252,16 @@ impl LocalSnapshot {fn ignore_stack_for_abs_path(&self, abs_path: &Path, is_dir: bool) -> Arc<IgnoreStack> {let mut new_ignores = Vec::new();- for ancestor in abs_path.ancestors().skip(1) {- if let Some((ignore, _)) = self.ignores_by_parent_abs_path.get(ancestor) {- new_ignores.push((ancestor, Some(ignore.clone())));- } else {- new_ignores.push((ancestor, None));+ for (index, ancestor) in abs_path.ancestors().enumerate() {+ if index > 0 {+ if let Some((ignore, _)) = self.ignores_by_parent_abs_path.get(ancestor) {+ new_ignores.push((ancestor, Some(ignore.clone())));+ } else {+ new_ignores.push((ancestor, None));+ }+ }+ if ancestor.join(&*DOT_GIT).is_dir() {+ break;}}@@ -3319,14 +3324,21 @@ impl BackgroundScanner {// Populate ignores above the root.let root_abs_path = self.state.lock().snapshot.abs_path.clone();- for ancestor in root_abs_path.ancestors().skip(1) {- if let Ok(ignore) = build_gitignore(&ancestor.join(&*GITIGNORE), self.fs.as_ref()).await- {- self.state- .lock()- .snapshot- .ignores_by_parent_abs_path- .insert(ancestor.into(), (ignore.into(), false));+ for (index, ancestor) in root_abs_path.ancestors().enumerate() {+ if index != 0 {+ if let Ok(ignore) =+ build_gitignore(&ancestor.join(&*GITIGNORE), self.fs.as_ref()).await+ {+ self.state+ .lock()+ .snapshot+ .ignores_by_parent_abs_path+ .insert(ancestor.into(), (ignore.into(), false));+ }+ }+ if ancestor.join(&*DOT_GIT).is_dir() {+ // Reached root of git repository.+ break;}}