Fix the ! bug, better test draft

This commit is contained in:
Kirill Bulatov 2023-11-15 10:15:50 +02:00
parent 26f7e66b49
commit ce2cfc6035
2 changed files with 86 additions and 33 deletions

View file

@ -2123,7 +2123,7 @@ impl LocalSnapshot {
let mut ignore_stack = IgnoreStack::none(); let mut ignore_stack = IgnoreStack::none();
for (parent_abs_path, ignore) in new_ignores.into_iter().rev() { 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(); ignore_stack = IgnoreStack::all();
break; break;
} else if let Some(ignore) = ignore { } 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 = IgnoreStack::all();
} }
ignore_stack ignore_stack

View file

@ -7,7 +7,7 @@ use anyhow::Result;
use client::Client; use client::Client;
use fs::{repository::GitFileStatus, FakeFs, Fs, RealFs, RemoveOptions}; use fs::{repository::GitFileStatus, FakeFs, Fs, RealFs, RemoveOptions};
use git::GITIGNORE; use git::GITIGNORE;
use gpui::{executor::Deterministic, ModelContext, Task, TestAppContext}; use gpui::{executor::Deterministic, ModelContext, ModelHandle, Task, TestAppContext};
use parking_lot::Mutex; use parking_lot::Mutex;
use postage::stream::Stream; use postage::stream::Stream;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
@ -882,9 +882,13 @@ async fn test_write_file(cx: &mut TestAppContext) {
#[gpui::test] #[gpui::test]
async fn test_ignore_inclusions_and_exclusions(cx: &mut TestAppContext) { async fn test_ignore_inclusions_and_exclusions(cx: &mut TestAppContext) {
let dir = temp_tree(json!({ let dir = temp_tree(json!({
".git": {}, ".git": {
"index": "blah"
},
".gitignore": "**/target\n/node_modules\n", ".gitignore": "**/target\n/node_modules\n",
"target": {}, "target": {
"index2": "blah2"
},
"node_modules": { "node_modules": {
".DS_Store": "", ".DS_Store": "",
"prettier": { "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()) cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete())
.await; .await;
tree.flush_fs_events(cx).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| { cx.update(|cx| {
// tree.as_local().unwrap().write_file( cx.update_global::<SettingsStore, _, _>(|store, cx| {
// Path::new("tracked-dir/file.txt"), store.update_user_settings::<ProjectSettings>(cx, |project_settings| {
// "hello".into(), project_settings.scan_exclude_files = Some(vec!["**/node_modules/**".to_string()]);
// Default::default(), });
// cx, });
// ) });
// }) tree.flush_fs_events(cx).await;
// .await cx.foreground().run_until_parked();
// .unwrap(); check_worktree_entries(
// tree.update(cx, |tree, cx| { &tree,
// tree.as_local().unwrap().write_file( &[
// Path::new("ignored-dir/file.txt"), "node_modules/prettier/package.json",
// "world".into(), "node_modules/.DS_Store",
// Default::default(), ],
// cx, &[".git/index", "target/index2"],
// ) &[
// }) ".gitignore",
// .await "src/lib.rs",
// .unwrap(); "src/bar/bar.rs",
"src/foo/foo.rs",
// tree.read_with(cx, |tree, _| { "src/foo/another.rs",
// let tracked = tree.entry_for_path("tracked-dir/file.txt").unwrap(); "src/.DS_Store",
// let ignored = tree.entry_for_path("ignored-dir/file.txt").unwrap(); ".DS_Store",
// assert!(!tracked.is_ignored); ],
// assert!(ignored.is_ignored); cx,
// }); );
dbg!("!!!!!!!!!!!!");
} }
#[gpui::test(iterations = 30)] #[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())) .map(|status| (status.path().unwrap().to_string(), status.status()))
.collect() .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:?}",
);
}
});
}