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
+14 -1
View File
@@ -1,5 +1,5 @@
use crate::{FakeFs, FakeFsEntry, Fs};
use anyhow::{Context as _, Result};
use anyhow::{Context as _, Result, bail};
use collections::{HashMap, HashSet};
use futures::future::{self, BoxFuture, join_all};
use git::{
@@ -354,6 +354,19 @@ impl GitRepository for FakeGitRepository {
})
}
fn rename_branch(&self, branch: String, new_name: String) -> BoxFuture<'_, Result<()>> {
self.with_state_async(true, move |state| {
if !state.branches.remove(&branch) {
bail!("no such branch: {branch}");
}
state.branches.insert(new_name.clone());
if state.current_branch_name == Some(branch) {
state.current_branch_name = Some(new_name);
}
Ok(())
})
}
fn blame(&self, path: RepoPath, _content: Rope) -> BoxFuture<'_, Result<git::blame::Blame>> {
self.with_state_async(false, move |state| {
state