From e189546acb8f36ee1fc2f7aa23538f768054a400 Mon Sep 17 00:00:00 2001 From: Andrew Hynes Date: Wed, 27 Jul 2022 17:43:24 -0230 Subject: [PATCH] refactor: move checks for clean working tree --- pkg/gui/controllers/files_controller.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 19c296562..50ef448c9 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -758,6 +758,9 @@ func (self *FilesController) createStashMenu() error { { Label: self.c.Tr.LcStashAllChanges, OnPress: func() error { + if !self.helpers.WorkingTree.IsWorkingTreeDirty() { + return self.c.ErrorMsg(self.c.Tr.NoFilesToStash) + } return self.handleStashSave(self.git.Stash.Save, self.c.Tr.Actions.StashAllChanges, self.c.Tr.NoFilesToStash) }, Key: 'a', @@ -765,6 +768,9 @@ func (self *FilesController) createStashMenu() error { { Label: self.c.Tr.LcStashAllChangesKeepIndex, OnPress: func() error { + if !self.helpers.WorkingTree.IsWorkingTreeDirty() { + return self.c.ErrorMsg(self.c.Tr.NoFilesToStash) + } // if there are no staged files it behaves the same as Stash.Save return self.handleStashSave(self.git.Stash.StashAndKeepIndex, self.c.Tr.Actions.StashAllChangesKeepIndex, self.c.Tr.NoFilesToStash) }, @@ -791,6 +797,9 @@ func (self *FilesController) createStashMenu() error { { Label: self.c.Tr.LcStashUnstagedChanges, OnPress: func() error { + if !self.helpers.WorkingTree.IsWorkingTreeDirty() { + return self.c.ErrorMsg(self.c.Tr.NoFilesToStash) + } if self.helpers.WorkingTree.AnyStagedFiles() { return self.handleStashSave(self.git.Stash.StashUnstagedChanges, self.c.Tr.Actions.StashUnstagedChanges, self.c.Tr.NoFilesToStash) } @@ -833,9 +842,6 @@ func (self *FilesController) toggleTreeView() error { } func (self *FilesController) handleStashSave(stashFunc func(message string) error, action string, errorMsg string) error { - if action != self.c.Tr.Actions.StashIncludeUntrackedChanges && !self.helpers.WorkingTree.IsWorkingTreeDirty() { - return self.c.ErrorMsg(errorMsg) - } return self.c.Prompt(types.PromptOpts{ Title: self.c.Tr.StashChanges,