Correctly identify remote branches

This commit is contained in:
Quentin Boyer 2025-09-16 17:55:15 +02:00
parent 85e468a995
commit b29d5fbfc1

View file

@ -69,10 +69,35 @@ impl Delete {
.as_ref()
.try_m_unwrap_or_else(|| Ok(&current_branch))?;
let has_remote = git_cd(&["rev-parse", "@{u}"]).is_ok();
if has_remote && !self.local_only {
println!("Removing branch from remote repository");
git_cd(&["push", "-d", "origin", branch])?;
if !self.local_only
&& let Ok(remote) = git_cd(&[
"rev-parse",
"--symbolic-full-name",
&format!("{branch}@{{u}}"),
])
{
let mut components = remote.split("/");
let refs = components
.next()
.ok_or_else(|| miette!("Missing `refs` component in {remote}"))?;
miette::ensure!(refs == "refs", "Unexepected {refs} component in `{remote}`");
let remotes = components
.next()
.ok_or_else(|| miette!("Missing `remotes` in {remote}"))?;
miette::ensure!(
remotes == "remotes",
"Unexepected {remotes} component in `{remote}`"
);
let remote_name = components
.next()
.ok_or_else(|| miette!("Missing remote name in {remote}"))?;
let remote_branch_name = components
.next()
.ok_or_else(|| miette!("Missing remote branch name in {remote}"))?;
println!("Removing branch {remote_branch_name} from remote repository ({remote_name})");
git_cd(&["push", "-d", remote_name, remote_branch_name])?;
}
if branch == &current_branch {