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

checks for if we're in a normal working tree state

This commit is contained in:
Jesse Duffield 2019-11-05 11:53:01 +11:00
parent 1fc120de2d
commit 0ffccbd3ee
3 changed files with 31 additions and 3 deletions

View File

@ -64,6 +64,10 @@ func (gui *Gui) handleCheckoutCommitFile(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) handleDiscardOldFileChange(g *gocui.Gui, v *gocui.View) error {
if ok, err := gui.validateNormalWorkingTreeState(); !ok {
return err
}
fileName := gui.State.CommitFiles[gui.State.Panels.CommitFiles.SelectedLine].Name
return gui.createConfirmationPanel(gui.g, v, gui.Tr.SLocalize("DiscardFileChangesTitle"), gui.Tr.SLocalize("DiscardFileChangesPrompt"), func(g *gocui.Gui, v *gocui.View) error {
@ -110,6 +114,10 @@ func (gui *Gui) handleOpenOldCommitFile(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error {
if ok, err := gui.validateNormalWorkingTreeState(); !ok {
return err
}
commitFile := gui.getSelectedCommitFile(g)
if commitFile == nil {
return gui.renderString(g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
@ -157,6 +165,10 @@ func (gui *Gui) createPatchManager() error {
}
func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error {
if ok, err := gui.validateNormalWorkingTreeState(); !ok {
return err
}
commitFile := gui.getSelectedCommitFile(g)
if commitFile == nil {
return gui.renderString(g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))

View File

@ -54,7 +54,9 @@ func (gui *Gui) getPatchCommitIndex() int {
}
func (gui *Gui) handleDeletePatchFromCommit() error {
// TODO: deal with when we're already rebasing
if ok, err := gui.validateNormalWorkingTreeState(); !ok {
return err
}
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()
@ -64,7 +66,9 @@ func (gui *Gui) handleDeletePatchFromCommit() error {
}
func (gui *Gui) handleMovePatchToSelectedCommit() error {
// TODO: deal with when we're already rebasing
if ok, err := gui.validateNormalWorkingTreeState(); !ok {
return err
}
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()
@ -73,8 +77,17 @@ func (gui *Gui) handleMovePatchToSelectedCommit() error {
})
}
func (gui *Gui) validateNormalWorkingTreeState() (bool, error) {
if gui.State.WorkingTreeState != "normal" {
return false, gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantPatchWhileRebasingError"))
}
return true, nil
}
func (gui *Gui) handlePullPatchIntoWorkingTree() error {
// TODO: deal with when we're already rebasing
if ok, err := gui.validateNormalWorkingTreeState(); !ok {
return err
}
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()

View File

@ -800,6 +800,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "DiscardPatchConfirm",
Other: "You can only build a patch from one commit at a time. Discard current patch?",
}, &i18n.Message{
ID: "CantPatchWhileRebasingError",
Other: "You cannot build a patch or run patch commands while in a merging or rebasing state",
}, &i18n.Message{
ID: "toggleAddToPatch",
Other: "toggle file included in patch",