diff --git a/docs/Config.md b/docs/Config.md index cf65be3da..d64a7b94b 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -166,6 +166,7 @@ Default path for the config file: pickBothHunks: 'b' submodules: init: 'i' + update: 'u' ``` ## Platform Defaults diff --git a/pkg/commands/submodules.go b/pkg/commands/submodules.go index 19debf890..1444890f7 100644 --- a/pkg/commands/submodules.go +++ b/pkg/commands/submodules.go @@ -101,7 +101,8 @@ func (c *GitCommand) SubmoduleDelete(submodule *models.SubmoduleConfig) error { } if err := c.OSCommand.RunCommand("git rm --force -r %s", submodule.Path); err != nil { - return err + // if the directory isn't there then that's fine + c.Log.Error(err) } return os.RemoveAll(filepath.Join(c.DotGitDir, "modules", submodule.Path)) @@ -128,3 +129,7 @@ func (c *GitCommand) SubmoduleUpdateUrl(name string, path string, newUrl string) func (c *GitCommand) SubmoduleInit(path string) error { return c.OSCommand.RunCommand("git submodule init %s", path) } + +func (c *GitCommand) SubmoduleUpdate(path string) error { + return c.OSCommand.RunCommand("git submodule update --init %s", path) +} diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index cd13e3bbc..28742c6cf 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -395,6 +395,7 @@ keybinding: pickBothHunks: 'b' submodules: init: 'i' + update: 'u' `) } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 992f32313..5cd794dcc 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1587,19 +1587,18 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Description: gui.Tr.SLocalize("enterSubmodule"), }, { - ViewName: "files", - Contexts: []string{SUBMODULES_CONTEXT_KEY}, - Key: gui.getKey("universal.remove"), - - Handler: gui.forSubmodule(gui.handleRemoveSubmodule), - Description: gui.Tr.SLocalize("removeSubmodule"), + ViewName: "files", + Contexts: []string{SUBMODULES_CONTEXT_KEY}, + Key: gui.getKey("universal.remove"), + Handler: gui.forSubmodule(gui.handleResetRemoveSubmodule), + Description: gui.Tr.SLocalize("viewResetAndRemoveOptions"), }, { ViewName: "files", Contexts: []string{SUBMODULES_CONTEXT_KEY}, - Key: gui.getKey("u"), - Handler: gui.forSubmodule(gui.handleResetSubmodule), - Description: gui.Tr.SLocalize("submoduleStashAndReset"), + Key: gui.getKey("submodules.update"), + Handler: gui.forSubmodule(gui.handleUpdateSubmodule), + Description: gui.Tr.SLocalize("submoduleUpdate"), }, { ViewName: "files", diff --git a/pkg/gui/submodules_panel.go b/pkg/gui/submodules_panel.go index d9951f2f0..c620efbbe 100644 --- a/pkg/gui/submodules_panel.go +++ b/pkg/gui/submodules_panel.go @@ -77,7 +77,7 @@ func (gui *Gui) enterSubmodule(submodule *models.SubmoduleConfig) error { return gui.dispatchSwitchToRepo(submodule.Path) } -func (gui *Gui) handleRemoveSubmodule(submodule *models.SubmoduleConfig) error { +func (gui *Gui) removeSubmodule(submodule *models.SubmoduleConfig) error { return gui.ask(askOpts{ title: gui.Tr.SLocalize("RemoveSubmodule"), prompt: gui.Tr.SLocalizef("RemoveSubmodulePrompt", submodule.Name), @@ -174,3 +174,31 @@ func (gui *Gui) forSubmodule(callback func(*models.SubmoduleConfig) error) func( }, ) } + +func (gui *Gui) handleResetRemoveSubmodule(submodule *models.SubmoduleConfig) error { + menuItems := []*menuItem{ + { + displayString: gui.Tr.SLocalize("submoduleStashAndReset"), + onPress: func() error { + return gui.resetSubmodule(submodule) + }, + }, + { + displayString: gui.Tr.SLocalize("removeSubmodule"), + onPress: func() error { + return gui.removeSubmodule(submodule) + }, + }, + } + + return gui.createMenu(submodule.Name, menuItems, createMenuOptions{showCancel: true}) +} + +func (gui *Gui) handleUpdateSubmodule(submodule *models.SubmoduleConfig) error { + return gui.WithWaitingStatus(gui.Tr.SLocalize("updatingSubmoduleStatus"), func() error { + err := gui.GitCommand.SubmoduleUpdate(submodule.Path) + gui.handleCredentialsPopup(err) + + return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}}) + }) +} diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 2b3e65e4f..4d84326fe 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -1245,6 +1245,15 @@ func addEnglish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "initSubmodule", Other: "initialize submodule", + }, &i18n.Message{ + ID: "viewResetAndRemoveOptions", + Other: "view reset and remove submodule options", + }, &i18n.Message{ + ID: "submoduleUpdate", + Other: "update submodule", + }, &i18n.Message{ + ID: "updatingSubmoduleStatus", + Other: "updating submodule", }, ) }