Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
worktree: Fix global gitignore on ancestors (#61689)
Dylan Arbourc2db0f1a9784
diff --git a/crates/worktree/src/ignore.rs b/crates/worktree/src/ignore.rsindex 5b0b3da52f1..b1f801afd4e 100644--- a/crates/worktree/src/ignore.rs+++ b/crates/worktree/src/ignore.rs@@ -85,12 +85,14 @@ impl IgnoreStack {IgnoreStackEntry::Global { ignore } => {let combined_path;let abs_path = if let Some(repo_root) = self.repo_root.as_ref() {- if let Ok(relative_path) = abs_path.strip_prefix(repo_root) {- combined_path = ignore.path().join(relative_path);- &combined_path- } else {- abs_path- }+ let Ok(relative_path) = abs_path.strip_prefix(repo_root) else {+ // The provided absolute path is outside of the repository's folderabs_path is outside repo_root and cannot be ignored+ // by this global ignore+ return false;+ };++ combined_path = ignore.path().join(relative_path);+ &combined_path} else {abs_path};diff --git a/crates/worktree/tests/integration/worktree_tests.rs b/crates/worktree/tests/integration/worktree_tests.rsindex 2ef74669b2c..dcd303e5fd2 100644--- a/crates/worktree/tests/integration/worktree_tests.rs+++ b/crates/worktree/tests/integration/worktree_tests.rs@@ -3621,34 +3621,37 @@ async fn test_global_gitignore(executor: BackgroundExecutor, cx: &mut TestAppConinit_test(cx);let home = paths::home_dir();+ let project_path = home.join("example.com").join("project");let fs = FakeFs::new(executor);fs.insert_tree(home,json!({".config": {"git": {- "ignore": "foo\n/bar\nbaz\n"+ "ignore": "foo\n/bar\nbaz\n*.com\n"}},- "project": {- ".git": {},- ".gitignore": "!baz",- "foo": "",- "bar": "",- "sub": {- "bar": "",- },- "subrepo": {+ "example.com": {+ "project": {".git": {},- "bar": ""- },- "baz": ""+ ".gitignore": "!baz",+ "foo": "",+ "bar": "",+ "sub": {+ "bar": "",+ },+ "subrepo": {+ ".git": {},+ "bar": ""+ },+ "baz": ""+ }}}),).await;let worktree = Worktree::local(- home.join("project"),+ project_path.clone(),true,fs.clone(),Arc::default(),@@ -3681,7 +3684,7 @@ async fn test_global_gitignore(executor: BackgroundExecutor, cx: &mut TestAppCon// Ignore statuses are updated when excludesFile changesfs.write(&home.join(".config").join("git").join("ignore"),- "/bar\nbaz\n".as_bytes(),+ "/bar\nbaz\n*.com\n".as_bytes(),).await.unwrap();@@ -3705,7 +3708,7 @@ async fn test_global_gitignore(executor: BackgroundExecutor, cx: &mut TestAppCon// Statuses are updated when .git added/removedfs.remove_dir(- &home.join("project").join("subrepo").join(".git"),+ &project_path.join("subrepo").join(".git"),RemoveOptions {recursive: true,..Default::default()