diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-30 22:05:34 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-10-02 08:09:42 +1000 |
commit | 71d4c552aff78fc4095a3fd03b1e250511fbb13f (patch) | |
tree | 4f6a5f17bc13eeeca2446f990f811e55f04b855d | |
parent | d4ab607d0dd94f73eb1dcd4ba9842eb86b6aa0f4 (diff) |
allow updating submodule url
-rw-r--r-- | pkg/commands/submodules.go | 6 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 7 | ||||
-rw-r--r-- | pkg/gui/submodules_panel.go | 24 | ||||
-rw-r--r-- | pkg/i18n/english.go | 9 |
4 files changed, 37 insertions, 9 deletions
diff --git a/pkg/commands/submodules.go b/pkg/commands/submodules.go index 659c2d2d8..493c76eba 100644 --- a/pkg/commands/submodules.go +++ b/pkg/commands/submodules.go @@ -94,7 +94,7 @@ func (c *GitCommand) SubmoduleDelete(submodule *models.SubmoduleConfig) error { return os.RemoveAll(filepath.Join(c.DotGitDir, "modules", submodule.Path)) } -func (c *GitCommand) AddSubmodule(name string, path string, url string) error { +func (c *GitCommand) SubmoduleAdd(name string, path string, url string) error { return c.OSCommand.RunCommand( "git submodule add --force --name %s -- %s %s ", c.OSCommand.Quote(name), @@ -102,3 +102,7 @@ func (c *GitCommand) AddSubmodule(name string, path string, url string) error { c.OSCommand.Quote(path), ) } + +func (c *GitCommand) SubmoduleUpdateUrl(path string, newUrl string) error { + return c.OSCommand.RunCommand("git submodule set-url -- %s %s", path, newUrl) +} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 7ee9cacee..1c1fa6c9a 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1608,6 +1608,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Handler: gui.wrappedHandler(gui.handleAddSubmodule), Description: gui.Tr.SLocalize("addSubmodule"), }, + { + ViewName: "files", + Contexts: []string{SUBMODULES_CONTEXT_KEY}, + Key: gui.getKey("universal.edit"), + Handler: gui.wrappedHandler(gui.handleEditSubmoduleUrl), + Description: gui.Tr.SLocalize("editSubmoduleUrl"), + }, } for _, viewName := range []string{"status", "branches", "files", "commits", "commitFiles", "stash", "menu"} { diff --git a/pkg/gui/submodules_panel.go b/pkg/gui/submodules_panel.go index abc021123..9fc847e7f 100644 --- a/pkg/gui/submodules_panel.go +++ b/pkg/gui/submodules_panel.go @@ -130,20 +130,28 @@ func (gui *Gui) handleAddSubmodule() error { return gui.prompt(gui.Tr.SLocalize("newSubmoduleName"), nameSuggestion, func(submoduleName string) error { return gui.prompt(gui.Tr.SLocalize("newSubmodulePath"), submoduleName, func(submodulePath string) error { return gui.WithWaitingStatus(gui.Tr.SLocalize("addingSubmoduleStatus"), func() error { - err := gui.GitCommand.AddSubmodule(submoduleName, submodulePath, submoduleUrl) + err := gui.GitCommand.SubmoduleAdd(submoduleName, submodulePath, submoduleUrl) gui.handleCredentialsPopup(err) return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}}) }) + }) + }) + }) +} + +func (gui *Gui) handleEditSubmoduleUrl() error { + submodule := gui.getSelectedSubmodule() + if submodule == nil { + return nil + } - // go func() { - // err := gui.GitCommand.AddSubmodule(submoduleName, submodulePath, submoduleUrl) - // gui.handleCredentialsPopup(err) + return gui.prompt(gui.Tr.SLocalizef("updateSubmoduleUrl", submodule.Name), submodule.Url, func(newUrl string) error { + return gui.WithWaitingStatus(gui.Tr.SLocalize("updatingSubmoduleUrlStatus"), func() error { + err := gui.GitCommand.SubmoduleUpdateUrl(submodule.Name, newUrl) + gui.handleCredentialsPopup(err) - // _ = gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}}) - // }() - return nil - }) + return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}}) }) }) } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 25afb72b0..a2ed7afbd 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -1230,6 +1230,15 @@ func addEnglish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "addingSubmoduleStatus", Other: "adding submodule", + }, &i18n.Message{ + ID: "updateSubmoduleUrl", + Other: "update URL for submodule '%s'", + }, &i18n.Message{ + ID: "updatingSubmoduleUrlStatus", + Other: "updating URL", + }, &i18n.Message{ + ID: "editSubmoduleUrl", + Other: "update submodule URL", }, ) } |