1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-12 04:23:03 +02:00
lazygit/pkg/gui/discard_changes_menu_panel.go

77 lines
2.0 KiB
Go
Raw Normal View History

2020-02-14 13:07:56 +02:00
package gui
import (
"github.com/jesseduffield/gocui"
2020-09-28 01:14:32 +02:00
"github.com/jesseduffield/lazygit/pkg/commands"
2020-02-14 13:07:56 +02:00
)
2020-09-28 01:14:32 +02:00
func (gui *Gui) submoduleFromFile(file *commands.File) *commands.SubmoduleConfig {
for _, config := range gui.State.SubmoduleConfigs {
if config.Name == file.Name {
return config
}
}
return nil
}
2020-02-14 13:07:56 +02:00
func (gui *Gui) handleCreateDiscardMenu(g *gocui.Gui, v *gocui.View) error {
2020-08-16 09:45:12 +02:00
file := gui.getSelectedFile()
if file == nil {
2020-02-14 13:07:56 +02:00
return nil
}
2020-09-28 01:14:32 +02:00
var menuItems []*menuItem
2020-09-28 00:21:53 +02:00
2020-09-28 01:14:32 +02:00
submoduleConfigs := gui.State.SubmoduleConfigs
if file.IsSubmodule(submoduleConfigs) {
submoduleConfig := file.SubmoduleConfig(submoduleConfigs)
menuItems = []*menuItem{
{
displayString: gui.Tr.SLocalize("submoduleStashAndReset"),
onPress: func() error {
if err := gui.GitCommand.UnStageFile(file.Name, file.Tracked); err != nil {
return gui.surfaceError(err)
}
if err := gui.GitCommand.SubmoduleStash(submoduleConfig); err != nil {
return gui.surfaceError(err)
}
if err := gui.GitCommand.SubmoduleReset(submoduleConfig); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{FILES}})
},
2020-02-14 13:07:56 +02:00
},
2020-09-28 01:14:32 +02:00
}
} else {
menuItems = []*menuItem{
{
displayString: gui.Tr.SLocalize("discardAllChanges"),
onPress: func() error {
if err := gui.GitCommand.DiscardAllFileChanges(file); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{FILES}})
},
},
}
2020-02-14 13:07:56 +02:00
2020-09-28 01:14:32 +02:00
if file.HasStagedChanges && file.HasUnstagedChanges {
menuItems = append(menuItems, &menuItem{
displayString: gui.Tr.SLocalize("discardUnstagedChanges"),
onPress: func() error {
if err := gui.GitCommand.DiscardUnstagedFileChanges(file); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{FILES}})
},
})
}
2020-02-14 13:07:56 +02:00
}
2020-02-14 14:39:02 +02:00
return gui.createMenu(file.Name, menuItems, createMenuOptions{showCancel: true})
2020-02-14 13:07:56 +02:00
}