1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-19 00:28:03 +02:00

reset patch builder when we've escaped from the building phase and nothing has been added

This commit is contained in:
Jesse Duffield
2019-11-10 15:24:20 +11:00
parent d0d92c7697
commit cd17b46b55
4 changed files with 24 additions and 9 deletions

View File

@ -214,6 +214,16 @@ func (p *PatchManager) Reset() {
p.fileInfoMap = map[string]*fileInfo{} p.fileInfoMap = map[string]*fileInfo{}
} }
func (p *PatchManager) IsEmpty() bool { func (p *PatchManager) CommitSelected() bool {
return p != nil && (p.CommitSha == "" || len(p.fileInfoMap) == 0) return p.CommitSha != ""
}
func (p *PatchManager) IsEmpty() bool {
for _, fileInfo := range p.fileInfoMap {
if fileInfo.mode == WHOLE || (fileInfo.mode == PART && len(fileInfo.includedLineIndices) > 0) {
return false
}
}
return true
} }

View File

@ -136,7 +136,7 @@ func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error {
} }
toggleTheFile := func() error { toggleTheFile := func() error {
if gui.GitCommand.PatchManager.IsEmpty() { if !gui.GitCommand.PatchManager.CommitSelected() {
if err := gui.startPatchManager(); err != nil { if err := gui.startPatchManager(); err != nil {
return err return err
} }
@ -147,7 +147,7 @@ func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error {
return gui.refreshCommitFilesView() return gui.refreshCommitFilesView()
} }
if !gui.GitCommand.PatchManager.IsEmpty() && gui.GitCommand.PatchManager.CommitSha != commitFile.Sha { if gui.GitCommand.PatchManager.CommitSelected() && gui.GitCommand.PatchManager.CommitSha != commitFile.Sha {
return gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("DiscardPatch"), gui.Tr.SLocalize("DiscardPatchConfirm"), func(g *gocui.Gui, v *gocui.View) error { return gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("DiscardPatch"), gui.Tr.SLocalize("DiscardPatchConfirm"), func(g *gocui.Gui, v *gocui.View) error {
gui.GitCommand.PatchManager.Reset() gui.GitCommand.PatchManager.Reset()
return toggleTheFile() return toggleTheFile()
@ -187,7 +187,7 @@ func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error {
} }
enterTheFile := func() error { enterTheFile := func() error {
if gui.GitCommand.PatchManager.IsEmpty() { if !gui.GitCommand.PatchManager.CommitSelected() {
if err := gui.startPatchManager(); err != nil { if err := gui.startPatchManager(); err != nil {
return err return err
} }
@ -202,7 +202,7 @@ func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error {
return gui.refreshPatchBuildingPanel() return gui.refreshPatchBuildingPanel()
} }
if !gui.GitCommand.PatchManager.IsEmpty() && gui.GitCommand.PatchManager.CommitSha != commitFile.Sha { if gui.GitCommand.PatchManager.CommitSelected() && gui.GitCommand.PatchManager.CommitSha != commitFile.Sha {
return gui.createConfirmationPanel(g, v, false, gui.Tr.SLocalize("DiscardPatch"), gui.Tr.SLocalize("DiscardPatchConfirm"), func(g *gocui.Gui, v *gocui.View) error { return gui.createConfirmationPanel(g, v, false, gui.Tr.SLocalize("DiscardPatch"), gui.Tr.SLocalize("DiscardPatchConfirm"), func(g *gocui.Gui, v *gocui.View) error {
gui.GitCommand.PatchManager.Reset() gui.GitCommand.PatchManager.Reset()
return enterTheFile() return enterTheFile()

View File

@ -5,7 +5,7 @@ import (
) )
func (gui *Gui) refreshPatchBuildingPanel() error { func (gui *Gui) refreshPatchBuildingPanel() error {
if gui.GitCommand.PatchManager.IsEmpty() { if !gui.GitCommand.PatchManager.CommitSelected() {
return gui.handleEscapePatchBuildingPanel(gui.g, nil) return gui.handleEscapePatchBuildingPanel(gui.g, nil)
} }
@ -87,11 +87,16 @@ func (gui *Gui) handleEscapePatchBuildingPanel(g *gocui.Gui, v *gocui.View) erro
gui.State.Panels.LineByLine = nil gui.State.Panels.LineByLine = nil
gui.State.Contexts["main"] = "normal" gui.State.Contexts["main"] = "normal"
if gui.GitCommand.PatchManager.IsEmpty() {
gui.GitCommand.PatchManager.Reset()
gui.State.SplitMainPanel = false
}
return gui.switchFocus(gui.g, nil, gui.getCommitFilesView()) return gui.switchFocus(gui.g, nil, gui.getCommitFilesView())
} }
func (gui *Gui) refreshSecondaryPatchPanel() error { func (gui *Gui) refreshSecondaryPatchPanel() error {
if !gui.GitCommand.PatchManager.IsEmpty() { if gui.GitCommand.PatchManager.CommitSelected() {
gui.State.SplitMainPanel = true gui.State.SplitMainPanel = true
secondaryView := gui.getSecondaryView() secondaryView := gui.getSecondaryView()
secondaryView.Highlight = true secondaryView.Highlight = true

View File

@ -17,7 +17,7 @@ func (o *patchMenuOption) GetDisplayStrings(isFocused bool) []string {
} }
func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error {
if gui.GitCommand.PatchManager.IsEmpty() { if !gui.GitCommand.PatchManager.CommitSelected() {
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoPatchError")) return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoPatchError"))
} }