Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix the ! bug, better test draft

Kirill Bulatovce2cfc60356c
diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs
index 41fd647c9ce..49ba8c93c40 100644
--- a/crates/project/src/worktree.rs
+++ b/crates/project/src/worktree.rs
@@ -2123,7 +2123,7 @@ impl LocalSnapshot {
let mut ignore_stack = IgnoreStack::none();
for (parent_abs_path, ignore) in new_ignores.into_iter().rev() {
- if !ignore_stack.is_abs_path_ignored(parent_abs_path, true) {
+ if ignore_stack.is_abs_path_ignored(parent_abs_path, true) {
ignore_stack = IgnoreStack::all();
break;
} else if let Some(ignore) = ignore {
@@ -2131,7 +2131,7 @@ impl LocalSnapshot {
}
}
- if !ignore_stack.is_abs_path_ignored(abs_path, is_dir) {
+ if ignore_stack.is_abs_path_ignored(abs_path, is_dir) {
ignore_stack = IgnoreStack::all();
}
ignore_stack
diff --git a/crates/project/src/worktree_tests.rs b/crates/project/src/worktree_tests.rs
index 79ac25a1476..74268d2ed50 100644
--- a/crates/project/src/worktree_tests.rs
+++ b/crates/project/src/worktree_tests.rs
@@ -7,7 +7,7 @@ use anyhow::Result;
use client::Client;
use fs::{repository::GitFileStatus, FakeFs, Fs, RealFs, RemoveOptions};
use git::GITIGNORE;
-use gpui::{executor::Deterministic, ModelContext, Task, TestAppContext};
+use gpui::{executor::Deterministic, ModelContext, ModelHandle, Task, TestAppContext};
use parking_lot::Mutex;
use postage::stream::Stream;
use pretty_assertions::assert_eq;
@@ -882,9 +882,13 @@ async fn test_write_file(cx: &mut TestAppContext) {
#[gpui::test]
async fn test_ignore_inclusions_and_exclusions(cx: &mut TestAppContext) {
let dir = temp_tree(json!({
- ".git": {},
+ ".git": {
+ "index": "blah"
+ },
".gitignore": "**/target\n/node_modules\n",
- "target": {},
+ "target": {
+ "index2": "blah2"
+ },
"node_modules": {
".DS_Store": "",
"prettier": {
@@ -928,35 +932,52 @@ async fn test_ignore_inclusions_and_exclusions(cx: &mut TestAppContext) {
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete())
.await;
tree.flush_fs_events(cx).await;
+ check_worktree_entries(
+ &tree,
+ &[
+ "src/foo/foo.rs",
+ "src/foo/another.rs",
+ // TODO kb
+ // "node_modules/.DS_Store",
+ // "src/.DS_Store",
+ // ".DS_Store",
+ ],
+ &[
+ ".git/index",
+ "target/index2",
+ "node_modules/prettier/package.json",
+ ],
+ &["src/lib.rs", "src/bar/bar.rs", ".gitignore"],
+ cx,
+ );
- // tree.update(cx, |tree, cx| {
- // tree.as_local().unwrap().write_file(
- // Path::new("tracked-dir/file.txt"),
- // "hello".into(),
- // Default::default(),
- // cx,
- // )
- // })
- // .await
- // .unwrap();
- // tree.update(cx, |tree, cx| {
- // tree.as_local().unwrap().write_file(
- // Path::new("ignored-dir/file.txt"),
- // "world".into(),
- // Default::default(),
- // cx,
- // )
- // })
- // .await
- // .unwrap();
-
- // tree.read_with(cx, |tree, _| {
- // let tracked = tree.entry_for_path("tracked-dir/file.txt").unwrap();
- // let ignored = tree.entry_for_path("ignored-dir/file.txt").unwrap();
- // assert!(!tracked.is_ignored);
- // assert!(ignored.is_ignored);
- // });
- dbg!("!!!!!!!!!!!!");
+ cx.update(|cx| {
+ cx.update_global::<SettingsStore, _, _>(|store, cx| {
+ store.update_user_settings::<ProjectSettings>(cx, |project_settings| {
+ project_settings.scan_exclude_files = Some(vec!["**/node_modules/**".to_string()]);
+ });
+ });
+ });
+ tree.flush_fs_events(cx).await;
+ cx.foreground().run_until_parked();
+ check_worktree_entries(
+ &tree,
+ &[
+ "node_modules/prettier/package.json",
+ "node_modules/.DS_Store",
+ ],
+ &[".git/index", "target/index2"],
+ &[
+ ".gitignore",
+ "src/lib.rs",
+ "src/bar/bar.rs",
+ "src/foo/foo.rs",
+ "src/foo/another.rs",
+ "src/.DS_Store",
+ ".DS_Store",
+ ],
+ cx,
+ );
}
#[gpui::test(iterations = 30)]
@@ -2221,3 +2242,35 @@ fn git_status(repo: &git2::Repository) -> collections::HashMap<String, git2::Sta
.map(|status| (status.path().unwrap().to_string(), status.status()))
.collect()
}
+
+fn check_worktree_entries(
+ tree: &ModelHandle<Worktree>,
+ expected_excluded_paths: &[&str],
+ expected_ignored_paths: &[&str],
+ expected_tracked_paths: &[&str],
+ cx: &mut TestAppContext,
+) {
+ tree.read_with(cx, |tree, _| {
+ for path in expected_excluded_paths {
+ let entry = tree.entry_for_path(path);
+ assert!(
+ entry.is_none(),
+ "expected path '{path}' to be excluded, but got entry: {entry:?}",
+ );
+ }
+ for path in expected_ignored_paths {
+ let entry = tree.entry_for_path(path).unwrap();
+ assert!(
+ entry.is_ignored,
+ "expected path '{path}' to be ignored, but got entry: {entry:?}",
+ );
+ }
+ for path in expected_tracked_paths {
+ let entry = tree.entry_for_path(path).unwrap();
+ assert!(
+ !entry.is_ignored,
+ "expected path '{path}' to be tracked, but got entry: {entry:?}",
+ );
+ }
+ });
+}