1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-28 09:08:41 +02:00

allow editing remotes

This commit is contained in:
Jesse Duffield 2019-11-17 18:15:32 +11:00
parent 64017cf874
commit cea24c2cf9
4 changed files with 65 additions and 0 deletions

View File

@ -1091,3 +1091,11 @@ func (c *GitCommand) DeleteRemoteBranch(remoteName string, branchName string) er
func (c *GitCommand) SetBranchUpstream(remoteName string, remoteBranchName string, branchName string) error {
return c.OSCommand.RunCommand(fmt.Sprintf("git branch --set-upstream-to=%s/%s %s", remoteName, remoteBranchName, branchName))
}
func (c *GitCommand) RenameRemote(oldRemoteName string, newRemoteName string) error {
return c.OSCommand.RunCommand(fmt.Sprintf("git remote rename %s %s", oldRemoteName, newRemoteName))
}
func (c *GitCommand) UpdateRemoteUrl(remoteName string, updatedUrl string) error {
return c.OSCommand.RunCommand(fmt.Sprintf("git remote set-url %s %s", remoteName, updatedUrl))
}

View File

@ -1030,6 +1030,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.handleRemoveRemote,
Description: gui.Tr.SLocalize("removeRemote"),
},
{
ViewName: "branches",
Contexts: []string{"remotes"},
Key: 'e',
Modifier: gocui.ModNone,
Handler: gui.handleEditRemote,
Description: gui.Tr.SLocalize("editRemote"),
},
{
ViewName: "branches",
Contexts: []string{"remote-branches"},

View File

@ -132,3 +132,43 @@ func (gui *Gui) handleRemoveRemote(g *gocui.Gui, v *gocui.View) error {
}, nil)
}
func (gui *Gui) handleEditRemote(g *gocui.Gui, v *gocui.View) error {
branchesView := gui.getBranchesView()
remote := gui.getSelectedRemote()
if remote == nil {
return nil
}
editNameMessage := gui.Tr.TemplateLocalize(
"editRemoteName",
Teml{
"remoteName": remote.Name,
},
)
return gui.createPromptPanel(g, branchesView, editNameMessage, "", func(g *gocui.Gui, v *gocui.View) error {
updatedRemoteName := gui.trimmedContent(v)
if updatedRemoteName != remote.Name {
if err := gui.GitCommand.RenameRemote(remote.Name, updatedRemoteName); err != nil {
return gui.createErrorPanel(gui.g, err.Error())
}
}
editUrlMessage := gui.Tr.TemplateLocalize(
"editRemoteUrl",
Teml{
"remoteName": updatedRemoteName,
},
)
return gui.createPromptPanel(g, branchesView, editUrlMessage, "", func(g *gocui.Gui, v *gocui.View) error {
updatedRemoteUrl := gui.trimmedContent(v)
if err := gui.GitCommand.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil {
return gui.createErrorPanel(gui.g, err.Error())
}
return gui.refreshRemotes()
})
})
}

View File

@ -855,6 +855,12 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "newRemoteUrl",
Other: `New remote url:`,
}, &i18n.Message{
ID: "editRemoteName",
Other: `Enter updated remote name for {{ .remoteName }}:`,
}, &i18n.Message{
ID: "editRemoteUrl",
Other: `Enter updated remote url for {{ .remoteName }}:`,
}, &i18n.Message{
ID: "removeRemote",
Other: `remove remote`,
@ -876,6 +882,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "SetUpstreamMessage",
Other: "Are you sure you want to set the upstream branch of '{{.checkedOut}}' to '{{.selected}}'",
}, &i18n.Message{
ID: "editRemote",
Other: "edit remote",
},
)
}