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: Add handler to get default branch on remote (#36157)

Alvaro Parker0291db0d78d7
diff --git a/crates/project/src/git_store.rs b/crates/project/src/git_store.rs
index 5d48c833ab0..32deb0dbc4f 100644
--- a/crates/project/src/git_store.rs
+++ b/crates/project/src/git_store.rs
@@ -414,6 +414,7 @@ impl GitStore {
pub fn init(client: &AnyProtoClient) {
client.add_entity_request_handler(Self::handle_get_remotes);
client.add_entity_request_handler(Self::handle_get_branches);
+ client.add_entity_request_handler(Self::handle_get_default_branch);
client.add_entity_request_handler(Self::handle_change_branch);
client.add_entity_request_handler(Self::handle_create_branch);
client.add_entity_request_handler(Self::handle_git_init);
@@ -1894,6 +1895,23 @@ impl GitStore {
.collect::<Vec<_>>(),
})
}
+ async fn handle_get_default_branch(
+ this: Entity<Self>,
+ envelope: TypedEnvelope<proto::GetDefaultBranch>,
+ mut cx: AsyncApp,
+ ) -> Result<proto::GetDefaultBranchResponse> {
+ let repository_id = RepositoryId::from_proto(envelope.payload.repository_id);
+ let repository_handle = Self::repository_for_request(&this, repository_id, &mut cx)?;
+
+ let branch = repository_handle
+ .update(&mut cx, |repository_handle, _| {
+ repository_handle.default_branch()
+ })?
+ .await??
+ .map(Into::into);
+
+ Ok(proto::GetDefaultBranchResponse { branch })
+ }
async fn handle_create_branch(
this: Entity<Self>,
envelope: TypedEnvelope<proto::GitCreateBranch>,