git: Don't consider $HOME as containing git repository unless it's opened directly (#25948)

When a worktree is created, we walk up the ancestors of the root path
trying to find a git repository. In particular, if your `$HOME` is a git
repository and you open some subdirectory of `$HOME` that's *not* a git
repository, we end up scanning `$HOME` and everything under it looking
for changed and untracked files, which is often pretty slow. Consistency
here is not very useful and leads to a bad experience.

This PR adds a special case to not consider `$HOME` as a containing git
repository, unless you ask for it by doing the equivalent of `zed ~`.

Release Notes:

- Changed the behavior of git features to not treat `$HOME` as a git
repository unless opened directly
This commit is contained in:
Cole Miller 2025-03-03 15:33:02 -05:00 committed by GitHub
parent 9e2b7bc5dc
commit dc3158c8ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 87 additions and 1 deletions

View file

@ -135,6 +135,7 @@ pub trait Fs: Send + Sync {
Arc<dyn Watcher>,
);
fn home_dir(&self) -> Option<PathBuf>;
fn open_repo(&self, abs_dot_git: &Path) -> Option<Arc<dyn GitRepository>>;
fn is_fake(&self) -> bool;
async fn is_case_sensitive(&self) -> Result<bool>;
@ -813,6 +814,10 @@ impl Fs for RealFs {
temp_dir.close()?;
case_sensitive
}
fn home_dir(&self) -> Option<PathBuf> {
Some(paths::home_dir().clone())
}
}
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
@ -846,6 +851,7 @@ struct FakeFsState {
metadata_call_count: usize,
read_dir_call_count: usize,
moves: std::collections::HashMap<u64, PathBuf>,
home_dir: Option<PathBuf>,
}
#[cfg(any(test, feature = "test-support"))]
@ -1031,6 +1037,7 @@ impl FakeFs {
read_dir_call_count: 0,
metadata_call_count: 0,
moves: Default::default(),
home_dir: None,
}),
});
@ -1524,6 +1531,10 @@ impl FakeFs {
fn simulate_random_delay(&self) -> impl futures::Future<Output = ()> {
self.executor.simulate_random_delay()
}
pub fn set_home_dir(&self, home_dir: PathBuf) {
self.state.lock().home_dir = Some(home_dir);
}
}
#[cfg(any(test, feature = "test-support"))]
@ -2079,6 +2090,10 @@ impl Fs for FakeFs {
fn as_fake(&self) -> Arc<FakeFs> {
self.this.upgrade().unwrap()
}
fn home_dir(&self) -> Option<PathBuf> {
self.state.lock().home_dir.clone()
}
}
fn chunks(rope: &Rope, line_ending: LineEnding) -> impl Iterator<Item = &str> {