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
+18 -3
View File
@@ -346,6 +346,7 @@ pub trait GitRepository: Send + Sync {
fn change_branch(&self, name: String) -> BoxFuture<'_, Result<()>>;
fn create_branch(&self, name: String) -> BoxFuture<'_, Result<()>>;
fn rename_branch(&self, branch: String, new_name: String) -> BoxFuture<'_, Result<()>>;
fn reset(
&self,
@@ -1095,11 +1096,11 @@ impl GitRepository for RealGitRepository {
let (_, branch_name) = name.split_once("/").context("Unexpected branch format")?;
let revision = revision.get();
let branch_commit = revision.peel_to_commit()?;
let mut branch = repo.branch(branch_name, &branch_commit, false)?;
let mut branch = repo.branch(&branch_name, &branch_commit, false)?;
branch.set_upstream(Some(&name))?;
branch
} else {
anyhow::bail!("Branch not found");
anyhow::bail!("Branch '{}' not found", name);
};
Ok(branch
@@ -1115,7 +1116,6 @@ impl GitRepository for RealGitRepository {
GitBinary::new(git_binary_path, working_directory?, executor)
.run(&["checkout", &branch])
.await?;
anyhow::Ok(())
})
.boxed()
@@ -1133,6 +1133,21 @@ impl GitRepository for RealGitRepository {
.boxed()
}
fn rename_branch(&self, branch: String, new_name: String) -> BoxFuture<'_, Result<()>> {
let git_binary_path = self.git_binary_path.clone();
let working_directory = self.working_directory();
let executor = self.executor.clone();
self.executor
.spawn(async move {
GitBinary::new(git_binary_path, working_directory?, executor)
.run(&["branch", "-m", &branch, &new_name])
.await?;
anyhow::Ok(())
})
.boxed()
}
fn blame(&self, path: RepoPath, content: Rope) -> BoxFuture<'_, Result<crate::blame::Blame>> {
let working_directory = self.working_directory();
let git_binary_path = self.git_binary_path.clone();