Add branch rename action to Git panel (#38273)

Reopening #35136, cc @launay12u

Release Notes:

- git: added `git: rename branch` action to rename a branch (`git branch
-m`)

---------

Co-authored-by: Guillaume Launay <guillaume.launay@paylead.fr>
Co-authored-by: Peter Tripp <petertripp@gmail.com>
This commit is contained in:
Cole Miller
2025-09-18 18:17:13 +00:00
committed by GitHub
co-authored by Guillaume Launay Peter Tripp
parent df50b5c14a
commit 439d31e2d4
8 changed files with 238 additions and 8 deletions
+50
View File
@@ -398,6 +398,7 @@ impl GitStore {
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_rename_branch);
client.add_entity_request_handler(Self::handle_git_init);
client.add_entity_request_handler(Self::handle_push);
client.add_entity_request_handler(Self::handle_pull);
@@ -1944,6 +1945,25 @@ impl GitStore {
Ok(proto::Ack {})
}
async fn handle_rename_branch(
this: Entity<Self>,
envelope: TypedEnvelope<proto::GitRenameBranch>,
mut cx: AsyncApp,
) -> Result<proto::Ack> {
let repository_id = RepositoryId::from_proto(envelope.payload.repository_id);
let repository_handle = Self::repository_for_request(&this, repository_id, &mut cx)?;
let branch = envelope.payload.branch;
let new_name = envelope.payload.new_name;
repository_handle
.update(&mut cx, |repository_handle, _| {
repository_handle.rename_branch(branch, new_name)
})?
.await??;
Ok(proto::Ack {})
}
async fn handle_show(
this: Entity<Self>,
envelope: TypedEnvelope<proto::GitShow>,
@@ -4331,6 +4351,36 @@ impl Repository {
)
}
pub fn rename_branch(
&mut self,
branch: String,
new_name: String,
) -> oneshot::Receiver<Result<()>> {
let id = self.id;
self.send_job(
Some(format!("git branch -m {branch} {new_name}").into()),
move |repo, _cx| async move {
match repo {
RepositoryState::Local { backend, .. } => {
backend.rename_branch(branch, new_name).await
}
RepositoryState::Remote { project_id, client } => {
client
.request(proto::GitRenameBranch {
project_id: project_id.0,
repository_id: id.to_proto(),
branch,
new_name,
})
.await?;
Ok(())
}
}
},
)
}
pub fn check_for_pushed_commits(&mut self) -> oneshot::Receiver<Result<Vec<SharedString>>> {
let id = self.id;
self.send_job(None, move |repo, _cx| async move {