Skip to content

Commit

Permalink
✨ Update: branch rm can delete remote branches
Browse files Browse the repository at this point in the history
Using git, branch rm can delete the remote branch with "git push <remote> --delete <branch>"
It only runs if git is installed and only one remote is in the repo
  • Loading branch information
julien040 committed Jan 30, 2023
1 parent 26b4db4 commit 4667cb9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/controller/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func BranchDelete(cmd *cobra.Command, args []string) {
return
}

res, err := prompt.InputBool("Are you sure you want to delete the branch "+branchName+"?", false)
res, err := prompt.InputBool("Are you sure you want to delete the local branch "+branchName+"?", false)
if err != nil {
exitOnError("Sorry, I can't get your answer", err)
}
Expand All @@ -116,5 +116,29 @@ func BranchDelete(cmd *cobra.Command, args []string) {
exitOnError("I can't delete the branch", err)
}

// Delete the remote branch
installed := executor.IsGitInstalled()
if installed {
// Check if there is one remote
remotes, err := executor.ListRemote(wd)
if err != nil {
exitOnError("I can't list the remotes", err)
}
if len(remotes) == 1 {
remote := remotes[0]
res, err := prompt.InputBool("Do you want to delete the remote branch "+remote.Name+"/"+branchName+"?", false)
if err != nil {
exitOnError("Sorry, I can't get your answer", err)
}
if res {
err := executor.GitDeleteRemoteBranch(remote.Name, branchName)
if err != nil {
exitOnError("I can't delete the remote branch", err)
}
}

}
}

print.Message("The branch has been deleted", print.Success)
}
5 changes: 5 additions & 0 deletions src/executor/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,8 @@ func GitDiffRef(ref1 string, ref2 string) (bool, error) {
return output == "", runCommandWithStdin("git", "diff", ref1, ref2)

}

// Delete a remote branch
func GitDeleteRemoteBranch(remote string, branch string) error {
return runCommand("git", "push", remote, "--delete", branch)
}

0 comments on commit 4667cb9

Please sign in to comment.