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.

git: Use fast access check for repository in git panel (#59514)

Lukas Geigere4f6742a996e
diff --git a/crates/git/src/repository.rs b/crates/git/src/repository.rs
index 8547462e8ed..f077390375b 100644
--- a/crates/git/src/repository.rs
+++ b/crates/git/src/repository.rs
@@ -841,6 +841,10 @@ pub trait GitRepository: Send + Sync {
fn stash_entries(&self) -> BoxFuture<'static, Result<GitStash>>;
+ fn check_access(&self) -> BoxFuture<'_, Result<()>> {
+ async move { Ok(()) }.boxed()
+ }
+
fn branches(&self) -> BoxFuture<'_, Result<BranchesScanResult>>;
fn change_branch(&self, name: String) -> BoxFuture<'_, Result<()>>;
@@ -1813,6 +1817,16 @@ impl GitRepository for RealGitRepository {
})
}
+ fn check_access(&self) -> BoxFuture<'_, Result<()>> {
+ let git = self.git_binary_in_worktree();
+ self.executor
+ .spawn(async move {
+ git?.run(&["rev-parse"]).await?;
+ Ok(())
+ })
+ .boxed()
+ }
+
fn diff_tree(&self, request: DiffTreeType) -> BoxFuture<'_, Result<TreeDiff>> {
let git = self.git_binary_in_worktree();
@@ -3947,6 +3961,25 @@ mod tests {
);
}
+ #[gpui::test]
+ async fn test_check_access(cx: &mut TestAppContext) {
+ disable_git_global_config();
+ cx.executor().allow_parking();
+
+ let repo_dir = tempfile::tempdir().unwrap();
+ let repository = RealGitRepository::new(
+ &repo_dir.path().join(".git"),
+ None,
+ Some("git".into()),
+ cx.executor(),
+ )
+ .unwrap();
+
+ assert!(repository.check_access().await.is_err());
+ git_init_repo(repo_dir.path());
+ assert!(repository.check_access().await.is_ok());
+ }
+
#[gpui::test]
async fn test_real_git_repository_new_resolves_linked_worktree_paths(cx: &mut TestAppContext) {
disable_git_global_config();
diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs
index d7c0e73c9f4..1266f6f87ea 100644
--- a/crates/project/src/git_store.rs
+++ b/crates/project/src/git_store.rs
@@ -8793,7 +8793,7 @@ impl Repository {
// directory. For now we just return `GitAccess::Yes` so that
// remoting continues working as expected.
RepositoryState::Remote(..) => GitAccess::Yes,
- RepositoryState::Local(state) => match state.backend.status(&[]).await {
+ RepositoryState::Local(state) => match state.backend.check_access().await {
Ok(_) => GitAccess::Yes,
Err(_) => GitAccess::No,
},