Correctly identify remote branches
This commit is contained in:
parent
85e468a995
commit
b29d5fbfc1
1 changed files with 29 additions and 4 deletions
33
src/main.rs
33
src/main.rs
|
|
@ -69,10 +69,35 @@ impl Delete {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.try_m_unwrap_or_else(|| Ok(¤t_branch))?;
|
.try_m_unwrap_or_else(|| Ok(¤t_branch))?;
|
||||||
|
|
||||||
let has_remote = git_cd(&["rev-parse", "@{u}"]).is_ok();
|
if !self.local_only
|
||||||
if has_remote && !self.local_only {
|
&& let Ok(remote) = git_cd(&[
|
||||||
println!("Removing branch from remote repository");
|
"rev-parse",
|
||||||
git_cd(&["push", "-d", "origin", branch])?;
|
"--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 == ¤t_branch {
|
if branch == ¤t_branch {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue