mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-04 03:48:07 +02:00
bulk submodule menu
This commit is contained in:
parent
9125e3c0c6
commit
2dc848506c
@ -167,6 +167,7 @@ Default path for the config file:
|
||||
submodules:
|
||||
init: 'i'
|
||||
update: 'u'
|
||||
bulkMenu: 'b'
|
||||
```
|
||||
|
||||
## Platform Defaults
|
||||
|
@ -251,13 +251,7 @@ func (c *GitCommand) ResetAndClean() error {
|
||||
}
|
||||
|
||||
if len(submoduleConfigs) > 0 {
|
||||
for _, config := range submoduleConfigs {
|
||||
if err := c.SubmoduleStash(config); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := c.SubmoduleUpdateAll(); err != nil {
|
||||
if err := c.ResetSubmodules(submoduleConfigs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +123,15 @@ func (c *GitCommand) SubmoduleUpdateUrl(name string, path string, newUrl string)
|
||||
return err
|
||||
}
|
||||
|
||||
return c.OSCommand.RunCommand("git submodule sync %s", path)
|
||||
if err := c.OSCommand.RunCommand("git submodule sync %s", path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.OSCommand.RunCommand("git submodule update --init %s", path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *GitCommand) SubmoduleInit(path string) error {
|
||||
@ -133,3 +141,29 @@ func (c *GitCommand) SubmoduleInit(path string) error {
|
||||
func (c *GitCommand) SubmoduleUpdate(path string) error {
|
||||
return c.OSCommand.RunCommand("git submodule update --init %s", path)
|
||||
}
|
||||
|
||||
func (c *GitCommand) SubmoduleBulkInitCmdStr() string {
|
||||
return "git submodule init"
|
||||
}
|
||||
|
||||
func (c *GitCommand) SubmoduleBulkUpdateCmdStr() string {
|
||||
return "git submodule update"
|
||||
}
|
||||
|
||||
func (c *GitCommand) SubmoduleForceBulkUpdateCmdStr() string {
|
||||
return "git submodule update --force"
|
||||
}
|
||||
|
||||
func (c *GitCommand) SubmoduleBulkDeinitCmdStr() string {
|
||||
return "git submodule deinit --all --force"
|
||||
}
|
||||
|
||||
func (c *GitCommand) ResetSubmodules(submodules []*models.SubmoduleConfig) error {
|
||||
for _, submodule := range submodules {
|
||||
if err := c.SubmoduleStash(submodule); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return c.SubmoduleUpdateAll()
|
||||
}
|
||||
|
@ -396,6 +396,7 @@ keybinding:
|
||||
submodules:
|
||||
init: 'i'
|
||||
update: 'u'
|
||||
bulkMenu: 'b'
|
||||
`)
|
||||
}
|
||||
|
||||
|
@ -244,6 +244,10 @@ func (gui *Gui) createErrorPanel(message string) error {
|
||||
}
|
||||
|
||||
func (gui *Gui) surfaceError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, sentinelError := range gui.sentinelErrorsArr() {
|
||||
if err == sentinelError {
|
||||
return err
|
||||
|
@ -1621,6 +1621,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
||||
Handler: gui.forSubmodule(gui.handleSubmoduleInit),
|
||||
Description: gui.Tr.SLocalize("initSubmodule"),
|
||||
},
|
||||
{
|
||||
ViewName: "files",
|
||||
Contexts: []string{SUBMODULES_CONTEXT_KEY},
|
||||
Key: gui.getKey("submodules.bulkMenu"),
|
||||
Handler: gui.wrappedHandler(gui.handleBulkSubmoduleActionsMenu),
|
||||
Description: gui.Tr.SLocalize("viewBulkSubmoduleOptions"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, viewName := range []string{"status", "branches", "files", "commits", "commitFiles", "stash", "menu"} {
|
||||
|
@ -194,6 +194,61 @@ func (gui *Gui) handleResetRemoveSubmodule(submodule *models.SubmoduleConfig) er
|
||||
return gui.createMenu(submodule.Name, menuItems, createMenuOptions{showCancel: true})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleBulkSubmoduleActionsMenu() error {
|
||||
menuItems := []*menuItem{
|
||||
{
|
||||
displayStrings: []string{gui.Tr.SLocalize("bulkInitSubmodules"), utils.ColoredString(gui.GitCommand.SubmoduleBulkInitCmdStr(), color.FgGreen)},
|
||||
onPress: func() error {
|
||||
return gui.WithWaitingStatus(gui.Tr.SLocalize("runningCommand"), func() error {
|
||||
if err := gui.OSCommand.RunCommand(gui.GitCommand.SubmoduleBulkInitCmdStr()); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
|
||||
return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}})
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
displayStrings: []string{gui.Tr.SLocalize("bulkUpdateSubmodules"), utils.ColoredString(gui.GitCommand.SubmoduleBulkUpdateCmdStr(), color.FgYellow)},
|
||||
onPress: func() error {
|
||||
return gui.WithWaitingStatus(gui.Tr.SLocalize("runningCommand"), func() error {
|
||||
if err := gui.OSCommand.RunCommand(gui.GitCommand.SubmoduleBulkUpdateCmdStr()); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
|
||||
return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}})
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
displayStrings: []string{gui.Tr.SLocalize("submoduleStashAndReset"), utils.ColoredString(fmt.Sprintf("git stash in each submodule && %s", gui.GitCommand.SubmoduleForceBulkUpdateCmdStr()), color.FgRed)},
|
||||
onPress: func() error {
|
||||
return gui.WithWaitingStatus(gui.Tr.SLocalize("runningCommand"), func() error {
|
||||
if err := gui.GitCommand.ResetSubmodules(gui.State.Submodules); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
|
||||
return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}})
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
displayStrings: []string{gui.Tr.SLocalize("bulkDeinitSubmodules"), utils.ColoredString(gui.GitCommand.SubmoduleBulkDeinitCmdStr(), color.FgRed)},
|
||||
onPress: func() error {
|
||||
return gui.WithWaitingStatus(gui.Tr.SLocalize("runningCommand"), func() error {
|
||||
if err := gui.OSCommand.RunCommand(gui.GitCommand.SubmoduleBulkDeinitCmdStr()); err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
|
||||
return gui.refreshSidePanels(refreshOptions{scope: []int{SUBMODULES}})
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return gui.createMenu(gui.Tr.SLocalize("bulkSubmoduleOptions"), 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)
|
||||
|
@ -1193,7 +1193,7 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
||||
Other: "running custom command",
|
||||
}, &i18n.Message{
|
||||
ID: "submoduleStashAndReset",
|
||||
Other: "stash uncommitted submodule changes and reset",
|
||||
Other: "stash uncommitted submodule changes and update",
|
||||
}, &i18n.Message{
|
||||
ID: "andResetSubmodules",
|
||||
Other: "and reset submodules",
|
||||
@ -1254,6 +1254,24 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
||||
}, &i18n.Message{
|
||||
ID: "updatingSubmoduleStatus",
|
||||
Other: "updating submodule",
|
||||
}, &i18n.Message{
|
||||
ID: "bulkInitSubmodules",
|
||||
Other: "bulk init submodules",
|
||||
}, &i18n.Message{
|
||||
ID: "bulkUpdateSubmodules",
|
||||
Other: "bulk update submodules",
|
||||
}, &i18n.Message{
|
||||
ID: "bulkDeinitSubmodules",
|
||||
Other: "bulk deinit submodules",
|
||||
}, &i18n.Message{
|
||||
ID: "viewBulkSubmoduleOptions",
|
||||
Other: "view bulk submodule options",
|
||||
}, &i18n.Message{
|
||||
ID: "bulkSubmoduleOptions",
|
||||
Other: "bulk submodule options",
|
||||
}, &i18n.Message{
|
||||
ID: "runningCommand",
|
||||
Other: "running command",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user