1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

allow updating submodule

This commit is contained in:
Jesse Duffield 2020-10-01 09:04:09 +10:00
parent da3e00823f
commit 86dd9d87dd
6 changed files with 54 additions and 11 deletions

View File

@ -166,6 +166,7 @@ Default path for the config file:
pickBothHunks: 'b'
submodules:
init: 'i'
update: 'u'
```
## Platform Defaults

View File

@ -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)
}

View File

@ -395,6 +395,7 @@ keybinding:
pickBothHunks: 'b'
submodules:
init: 'i'
update: 'u'
`)
}

View File

@ -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",

View File

@ -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}})
})
}

View File

@ -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",
},
)
}