diff --git a/Cargo.lock b/Cargo.lock index 0dc771b816..8e0a139fa5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11475,6 +11475,7 @@ name = "paths" version = "0.1.0" dependencies = [ "dirs 4.0.0", + "ignore", "util", "workspace-hack", ] diff --git a/crates/paths/Cargo.toml b/crates/paths/Cargo.toml index cf6dabf0e1..f6eadc5a21 100644 --- a/crates/paths/Cargo.toml +++ b/crates/paths/Cargo.toml @@ -13,5 +13,6 @@ path = "src/paths.rs" [dependencies] dirs.workspace = true +ignore.workspace = true util.workspace = true workspace-hack.workspace = true diff --git a/crates/paths/src/paths.rs b/crates/paths/src/paths.rs index 2f3b188980..2f9e136c9d 100644 --- a/crates/paths/src/paths.rs +++ b/crates/paths/src/paths.rs @@ -507,3 +507,16 @@ fn add_vscode_user_data_paths(paths: &mut Vec, product_name: &str) { ); } } + +#[cfg(any(test, feature = "test-support"))] +pub fn global_gitignore_path() -> Option { + Some(Path::new(util::path!("/home/zed/.config/git/ignore")).into()) +} + +#[cfg(not(any(test, feature = "test-support")))] +pub fn global_gitignore_path() -> Option { + static GLOBAL_GITIGNORE_PATH: OnceLock> = OnceLock::new(); + GLOBAL_GITIGNORE_PATH + .get_or_init(|| ::ignore::gitignore::gitconfig_excludes_path()) + .clone() +} diff --git a/crates/project/src/project_tests.rs b/crates/project/src/project_tests.rs index 4ff7234339..fa83d79004 100644 --- a/crates/project/src/project_tests.rs +++ b/crates/project/src/project_tests.rs @@ -29,7 +29,7 @@ use lsp::{ WillRenameFiles, notification::DidRenameFiles, }; use parking_lot::Mutex; -use paths::{config_dir, tasks_file}; +use paths::{config_dir, global_gitignore_path, tasks_file}; use postage::stream::Stream as _; use pretty_assertions::{assert_eq, assert_matches}; use rand::{Rng as _, rngs::StdRng}; @@ -1179,7 +1179,9 @@ async fn test_reporting_fs_changes_to_language_servers(cx: &mut gpui::TestAppCon assert_eq!(fs.read_dir_call_count() - prev_read_dir_count, 5); let mut new_watched_paths = fs.watched_paths(); - new_watched_paths.retain(|path| !path.starts_with(config_dir())); + new_watched_paths.retain(|path| { + !path.starts_with(config_dir()) && !path.starts_with(global_gitignore_path().unwrap()) + }); assert_eq!( &new_watched_paths, &[ diff --git a/crates/util/src/paths.rs b/crates/util/src/paths.rs index 8007e4c696..0d310073d1 100644 --- a/crates/util/src/paths.rs +++ b/crates/util/src/paths.rs @@ -17,7 +17,7 @@ use crate::NumericPrefixWithSuffix; pub fn home_dir() -> &'static PathBuf { static HOME_DIR: OnceLock = OnceLock::new(); HOME_DIR.get_or_init(|| { - if cfg!(test) { + if cfg!(any(test, feature = "test-support")) { PathBuf::from("/home/zed") } else { dirs::home_dir().expect("failed to determine home directory") diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rs index d6a740c3e4..93bdff29bc 100644 --- a/crates/worktree/src/worktree.rs +++ b/crates/worktree/src/worktree.rs @@ -3846,7 +3846,7 @@ impl BackgroundScanner { log::trace!("containing git repository: {containing_git_repository:?}"); - let global_gitignore_path = global_gitignore_path(); + let global_gitignore_path = paths::global_gitignore_path(); self.state.lock().snapshot.global_gitignore = if let Some(global_gitignore_path) = global_gitignore_path.as_ref() { build_gitignore(global_gitignore_path, self.fs.as_ref()) @@ -5708,13 +5708,3 @@ fn discover_git_paths(dot_git_abs_path: &Arc, fs: &dyn Fs) -> (Arc, (repository_dir_abs_path, common_dir_abs_path) } - -#[cfg(test)] -fn global_gitignore_path() -> Option> { - Some(Path::new(util::path!("/home/zed/.config/git/ignore")).into()) -} - -#[cfg(not(test))] -fn global_gitignore_path() -> Option> { - ::ignore::gitignore::gitconfig_excludes_path().map(Into::into) -}