Get the test to failing,,, correctly
This commit is contained in:
parent
6ac9308a03
commit
c8e63d76a4
7 changed files with 68 additions and 34 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -6359,6 +6359,8 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"futures",
|
"futures",
|
||||||
|
"git2",
|
||||||
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
|
@ -54,6 +54,7 @@ toml = "0.5"
|
||||||
rocksdb = "0.18"
|
rocksdb = "0.18"
|
||||||
git2 = { version = "0.15", default-features = false }
|
git2 = { version = "0.15", default-features = false }
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
client = { path = "../client", features = ["test-support"] }
|
client = { path = "../client", features = ["test-support"] }
|
||||||
collections = { path = "../collections", features = ["test-support"] }
|
collections = { path = "../collections", features = ["test-support"] }
|
||||||
|
|
|
@ -11,6 +11,7 @@ pub trait GitRepository: Send + Sync {
|
||||||
fn git_dir_path(&self) -> &Path;
|
fn git_dir_path(&self) -> &Path;
|
||||||
fn last_scan_id(&self) -> usize;
|
fn last_scan_id(&self) -> usize;
|
||||||
fn set_scan_id(&mut self, scan_id: usize);
|
fn set_scan_id(&mut self, scan_id: usize);
|
||||||
|
fn with_repo(&mut self, f: Box<dyn FnOnce(&mut git2::Repository)>);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -70,6 +71,11 @@ impl GitRepository for RealGitRepository {
|
||||||
fn set_scan_id(&mut self, scan_id: usize) {
|
fn set_scan_id(&mut self, scan_id: usize) {
|
||||||
self.last_scan_id = scan_id;
|
self.last_scan_id = scan_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn with_repo(&mut self, f: Box<dyn FnOnce(&mut git2::Repository)>) {
|
||||||
|
let mut git2 = self.libgit_repository.lock();
|
||||||
|
f(&mut git2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for &Box<dyn GitRepository> {
|
impl PartialEq for &Box<dyn GitRepository> {
|
||||||
|
@ -129,4 +135,8 @@ impl GitRepository for FakeGitRepository {
|
||||||
fn set_scan_id(&mut self, scan_id: usize) {
|
fn set_scan_id(&mut self, scan_id: usize) {
|
||||||
self.last_scan_id = scan_id;
|
self.last_scan_id = scan_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn with_repo(&mut self, _: Box<dyn FnOnce(&mut git2::Repository)>) {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ use language::{
|
||||||
proto::{deserialize_version, serialize_line_ending, serialize_version},
|
proto::{deserialize_version, serialize_line_ending, serialize_version},
|
||||||
Buffer, DiagnosticEntry, LineEnding, PointUtf16, Rope,
|
Buffer, DiagnosticEntry, LineEnding, PointUtf16, Rope,
|
||||||
};
|
};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use postage::{
|
use postage::{
|
||||||
prelude::{Sink as _, Stream as _},
|
prelude::{Sink as _, Stream as _},
|
||||||
|
@ -50,12 +49,7 @@ use std::{
|
||||||
time::{Duration, SystemTime},
|
time::{Duration, SystemTime},
|
||||||
};
|
};
|
||||||
use sum_tree::{Bias, Edit, SeekTarget, SumTree, TreeMap, TreeSet};
|
use sum_tree::{Bias, Edit, SeekTarget, SumTree, TreeMap, TreeSet};
|
||||||
use util::{ResultExt, TryFutureExt};
|
use util::{ResultExt, TryFutureExt, DOT_GIT, GITIGNORE};
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref DOT_GIT: &'static OsStr = OsStr::new(".git");
|
|
||||||
static ref GITIGNORE: &'static OsStr = OsStr::new(".gitignore");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
|
||||||
pub struct WorktreeId(usize);
|
pub struct WorktreeId(usize);
|
||||||
|
@ -1317,6 +1311,13 @@ impl LocalSnapshot {
|
||||||
&self,
|
&self,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
) -> Option<Box<dyn GitRepository>> {
|
) -> Option<Box<dyn GitRepository>> {
|
||||||
|
let repos = self
|
||||||
|
.git_repositories
|
||||||
|
.iter()
|
||||||
|
.map(|repo| repo.content_path().to_str().unwrap().to_string())
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
dbg!(repos);
|
||||||
|
|
||||||
self.git_repositories
|
self.git_repositories
|
||||||
.iter()
|
.iter()
|
||||||
.rev() //git_repository is ordered lexicographically
|
.rev() //git_repository is ordered lexicographically
|
||||||
|
@ -1437,6 +1438,7 @@ impl LocalSnapshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_entry(&mut self, mut entry: Entry, fs: &dyn Fs) -> Entry {
|
fn insert_entry(&mut self, mut entry: Entry, fs: &dyn Fs) -> Entry {
|
||||||
|
dbg!(&entry.path);
|
||||||
if entry.is_file() && entry.path.file_name() == Some(&GITIGNORE) {
|
if entry.is_file() && entry.path.file_name() == Some(&GITIGNORE) {
|
||||||
let abs_path = self.abs_path.join(&entry.path);
|
let abs_path = self.abs_path.join(&entry.path);
|
||||||
match smol::block_on(build_gitignore(&abs_path, fs)) {
|
match smol::block_on(build_gitignore(&abs_path, fs)) {
|
||||||
|
@ -1455,6 +1457,8 @@ impl LocalSnapshot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if entry.path.file_name() == Some(&DOT_GIT) {
|
} else if entry.path.file_name() == Some(&DOT_GIT) {
|
||||||
|
dbg!(&entry.path);
|
||||||
|
|
||||||
let abs_path = self.abs_path.join(&entry.path);
|
let abs_path = self.abs_path.join(&entry.path);
|
||||||
let content_path: Arc<Path> = entry.path.parent().unwrap().into();
|
let content_path: Arc<Path> = entry.path.parent().unwrap().into();
|
||||||
if let Err(ix) = self
|
if let Err(ix) = self
|
||||||
|
@ -2223,6 +2227,7 @@ impl BackgroundScanner {
|
||||||
if ignore_stack.is_all() {
|
if ignore_stack.is_all() {
|
||||||
if let Some(mut root_entry) = snapshot.root_entry().cloned() {
|
if let Some(mut root_entry) = snapshot.root_entry().cloned() {
|
||||||
root_entry.is_ignored = true;
|
root_entry.is_ignored = true;
|
||||||
|
dbg!("scan dirs entry");
|
||||||
snapshot.insert_entry(root_entry, self.fs.as_ref());
|
snapshot.insert_entry(root_entry, self.fs.as_ref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2445,6 +2450,7 @@ impl BackgroundScanner {
|
||||||
snapshot.root_char_bag,
|
snapshot.root_char_bag,
|
||||||
);
|
);
|
||||||
fs_entry.is_ignored = ignore_stack.is_all();
|
fs_entry.is_ignored = ignore_stack.is_all();
|
||||||
|
dbg!("process_events entry");
|
||||||
snapshot.insert_entry(fs_entry, self.fs.as_ref());
|
snapshot.insert_entry(fs_entry, self.fs.as_ref());
|
||||||
|
|
||||||
let mut ancestor_inodes = snapshot.ancestor_inodes_for_path(&path);
|
let mut ancestor_inodes = snapshot.ancestor_inodes_for_path(&path);
|
||||||
|
@ -3145,50 +3151,46 @@ mod tests {
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_git_repository_for_path(cx: &mut TestAppContext) {
|
async fn test_git_repository_for_path(cx: &mut TestAppContext) {
|
||||||
let fs = FakeFs::new(cx.background());
|
let root = temp_tree(json!({
|
||||||
|
"dir1": {
|
||||||
fs.insert_tree(
|
".git": {},
|
||||||
"/root",
|
"deps": {
|
||||||
json!({
|
"dep1": {
|
||||||
"dir1": {
|
".git": {},
|
||||||
".git": {
|
"src": {
|
||||||
"HEAD": "abc"
|
"a.txt": ""
|
||||||
},
|
|
||||||
"deps": {
|
|
||||||
"dep1": {
|
|
||||||
".git": {},
|
|
||||||
"src": {
|
|
||||||
"a.txt": ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"src": {
|
|
||||||
"b.txt": ""
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"c.txt": ""
|
"src": {
|
||||||
}),
|
"b.txt": ""
|
||||||
)
|
}
|
||||||
.await;
|
},
|
||||||
|
"c.txt": ""
|
||||||
|
}));
|
||||||
|
|
||||||
let http_client = FakeHttpClient::with_404_response();
|
let http_client = FakeHttpClient::with_404_response();
|
||||||
let client = Client::new(http_client);
|
let client = Client::new(http_client);
|
||||||
let tree = Worktree::local(
|
let tree = Worktree::local(
|
||||||
client,
|
client,
|
||||||
Arc::from(Path::new("/root")),
|
root.path(),
|
||||||
true,
|
true,
|
||||||
fs.clone(),
|
Arc::new(RealFs),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
&mut cx.to_async(),
|
&mut cx.to_async(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
cx.foreground().run_until_parked();
|
cx.read(|cx| tree.read(cx).as_local().unwrap().scan_complete())
|
||||||
|
.await;
|
||||||
|
tree.flush_fs_events(cx).await;
|
||||||
|
|
||||||
tree.read_with(cx, |tree, cx| {
|
tree.read_with(cx, |tree, _cx| {
|
||||||
let tree = tree.as_local().unwrap();
|
let tree = tree.as_local().unwrap();
|
||||||
|
|
||||||
|
dbg!(tree);
|
||||||
|
|
||||||
assert!(tree
|
assert!(tree
|
||||||
.git_repository_for_file_path("c.txt".as_ref())
|
.git_repository_for_file_path("c.txt".as_ref())
|
||||||
.is_none());
|
.is_none());
|
||||||
|
|
|
@ -7,17 +7,21 @@ edition = "2021"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
test-support = ["rand", "serde_json", "tempdir"]
|
test-support = ["rand", "serde_json", "tempdir", "git2"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
log = { version = "0.4.16", features = ["kv_unstable_serde"] }
|
log = { version = "0.4.16", features = ["kv_unstable_serde"] }
|
||||||
|
lazy_static = "1.4.0"
|
||||||
rand = { version = "0.8", optional = true }
|
rand = { version = "0.8", optional = true }
|
||||||
tempdir = { version = "0.3.7", optional = true }
|
tempdir = { version = "0.3.7", optional = true }
|
||||||
serde_json = { version = "1.0", features = ["preserve_order"], optional = true }
|
serde_json = { version = "1.0", features = ["preserve_order"], optional = true }
|
||||||
|
git2 = { version = "0.15", default-features = false, optional = true }
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = { version = "0.8" }
|
rand = { version = "0.8" }
|
||||||
tempdir = { version = "0.3.7" }
|
tempdir = { version = "0.3.7" }
|
||||||
serde_json = { version = "1.0", features = ["preserve_order"] }
|
serde_json = { version = "1.0", features = ["preserve_order"] }
|
||||||
|
git2 = { version = "0.15", default-features = false }
|
||||||
|
|
|
@ -2,13 +2,20 @@
|
||||||
pub mod test;
|
pub mod test;
|
||||||
|
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
|
ffi::OsStr,
|
||||||
ops::AddAssign,
|
ops::AddAssign,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref DOT_GIT: &'static OsStr = OsStr::new(".git");
|
||||||
|
pub static ref GITIGNORE: &'static OsStr = OsStr::new(".gitignore");
|
||||||
|
}
|
||||||
|
|
||||||
pub fn truncate(s: &str, max_chars: usize) -> &str {
|
pub fn truncate(s: &str, max_chars: usize) -> &str {
|
||||||
match s.char_indices().nth(max_chars) {
|
match s.char_indices().nth(max_chars) {
|
||||||
None => s,
|
None => s,
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
mod assertions;
|
mod assertions;
|
||||||
mod marked_text;
|
mod marked_text;
|
||||||
|
|
||||||
|
use git2;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use tempdir::TempDir;
|
use tempdir::TempDir;
|
||||||
|
|
||||||
pub use assertions::*;
|
pub use assertions::*;
|
||||||
pub use marked_text::*;
|
pub use marked_text::*;
|
||||||
|
|
||||||
|
use crate::DOT_GIT;
|
||||||
|
|
||||||
pub fn temp_tree(tree: serde_json::Value) -> TempDir {
|
pub fn temp_tree(tree: serde_json::Value) -> TempDir {
|
||||||
let dir = TempDir::new("").unwrap();
|
let dir = TempDir::new("").unwrap();
|
||||||
write_tree(dir.path(), tree);
|
write_tree(dir.path(), tree);
|
||||||
|
@ -24,6 +27,11 @@ fn write_tree(path: &Path, tree: serde_json::Value) {
|
||||||
match contents {
|
match contents {
|
||||||
Value::Object(_) => {
|
Value::Object(_) => {
|
||||||
fs::create_dir(&path).unwrap();
|
fs::create_dir(&path).unwrap();
|
||||||
|
|
||||||
|
if path.file_name() == Some(&DOT_GIT) {
|
||||||
|
git2::Repository::init(&path.parent().unwrap()).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
write_tree(&path, contents);
|
write_tree(&path, contents);
|
||||||
}
|
}
|
||||||
Value::Null => {
|
Value::Null => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue