mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
support deleting remote branches
This commit is contained in:
@ -1085,3 +1085,7 @@ func (c *GitCommand) IsHeadDetached() bool {
|
|||||||
err := c.OSCommand.RunCommand("git symbolic-ref -q HEAD")
|
err := c.OSCommand.RunCommand("git symbolic-ref -q HEAD")
|
||||||
return err != nil
|
return err != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *GitCommand) DeleteRemoteBranch(remoteName string, branchName string) error {
|
||||||
|
return c.OSCommand.RunCommand(fmt.Sprintf("git push %s --delete %s", remoteName, branchName))
|
||||||
|
}
|
||||||
|
@ -1073,6 +1073,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Handler: gui.handleMergeRemoteBranch,
|
Handler: gui.handleMergeRemoteBranch,
|
||||||
Description: gui.Tr.SLocalize("mergeIntoCurrentBranch"),
|
Description: gui.Tr.SLocalize("mergeIntoCurrentBranch"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ViewName: "branches",
|
||||||
|
Contexts: []string{"remote-branches"},
|
||||||
|
Key: 'd',
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handleDeleteRemoteBranch,
|
||||||
|
Description: gui.Tr.SLocalize("deleteBranch"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ViewName: "commits",
|
ViewName: "commits",
|
||||||
Key: gocui.MouseLeft,
|
Key: gocui.MouseLeft,
|
||||||
|
@ -97,3 +97,20 @@ func (gui *Gui) handleMergeRemoteBranch(g *gocui.Gui, v *gocui.View) error {
|
|||||||
selectedBranchName := gui.getSelectedRemoteBranch().Name
|
selectedBranchName := gui.getSelectedRemoteBranch().Name
|
||||||
return gui.mergeBranchIntoCheckedOutBranch(selectedBranchName)
|
return gui.mergeBranchIntoCheckedOutBranch(selectedBranchName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleDeleteRemoteBranch(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
remoteBranch := gui.getSelectedRemoteBranch()
|
||||||
|
if remoteBranch == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
message := fmt.Sprintf("%s '%s/%s'?", gui.Tr.SLocalize("DeleteRemoteBranchMessage"), remoteBranch.RemoteName, remoteBranch.Name)
|
||||||
|
return gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("DeleteRemoteBranch"), message, func(*gocui.Gui, *gocui.View) error {
|
||||||
|
return gui.WithWaitingStatus(gui.Tr.SLocalize("DeletingStatus"), func() error {
|
||||||
|
if err := gui.GitCommand.DeleteRemoteBranch(remoteBranch.RemoteName, remoteBranch.Name); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.refreshRemotes()
|
||||||
|
})
|
||||||
|
}, nil)
|
||||||
|
}
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
func (gui *Gui) getSelectedRemote() *commands.Remote {
|
func (gui *Gui) getSelectedRemote() *commands.Remote {
|
||||||
selectedLine := gui.State.Panels.Remotes.SelectedLine
|
selectedLine := gui.State.Panels.Remotes.SelectedLine
|
||||||
if selectedLine == -1 {
|
if selectedLine == -1 || len(gui.State.Remotes) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +53,8 @@ func (gui *Gui) handleRemoteSelect(g *gocui.Gui, v *gocui.View) error {
|
|||||||
// gui.refreshStatus is called at the end of this because that's when we can
|
// gui.refreshStatus is called at the end of this because that's when we can
|
||||||
// be sure there is a state.Remotes array to pick the current remote from
|
// be sure there is a state.Remotes array to pick the current remote from
|
||||||
func (gui *Gui) refreshRemotes() error {
|
func (gui *Gui) refreshRemotes() error {
|
||||||
|
prevSelectedRemote := gui.getSelectedRemote()
|
||||||
|
|
||||||
remotes, err := gui.GitCommand.GetRemotes()
|
remotes, err := gui.GitCommand.GetRemotes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
return gui.createErrorPanel(gui.g, err.Error())
|
||||||
@ -60,8 +62,22 @@ func (gui *Gui) refreshRemotes() error {
|
|||||||
|
|
||||||
gui.State.Remotes = remotes
|
gui.State.Remotes = remotes
|
||||||
|
|
||||||
if gui.getBranchesView().Context == "remotes" {
|
// we need to ensure our selected remote branches aren't now outdated
|
||||||
|
if prevSelectedRemote != nil && gui.State.RemoteBranches != nil {
|
||||||
|
// find remote now
|
||||||
|
for _, remote := range remotes {
|
||||||
|
if remote.Name == prevSelectedRemote.Name {
|
||||||
|
gui.State.RemoteBranches = remote.Branches
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: see if this works for deleting remote branches
|
||||||
|
switch gui.getBranchesView().Context {
|
||||||
|
case "remotes":
|
||||||
return gui.renderRemotesWithSelection()
|
return gui.renderRemotesWithSelection()
|
||||||
|
case "remote-branches":
|
||||||
|
return gui.renderRemoteBranchesWithSelection()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -864,6 +864,12 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "removeRemotePrompt",
|
ID: "removeRemotePrompt",
|
||||||
Other: "Are you sure you want to remove remote",
|
Other: "Are you sure you want to remove remote",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "DeleteRemoteBranch",
|
||||||
|
Other: "Delete Remote Branch",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "DeleteRemoteBranchMessage",
|
||||||
|
Other: "Are you sure you want to delete remote branch",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user