diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2023-03-04 18:11:17 +0100 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2023-04-01 08:16:15 +0200 |
commit | c757063264d5386a67a22d88f6283dbbf1d09223 (patch) | |
tree | 21cefa7d4d3481cc6b9e1e1fd7245138c5d0052a /pkg/gui | |
parent | b24955063c71f6cb600be8636564144c496fe46a (diff) |
Better error message when trying to edit or move a non-todo commit during rebase
Previously we would have tried to do the rebase, resulting in a long and
somewhat cryptic error message from git; now we check ourselves and show a less
intimidating message.
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/controllers/local_commits_controller.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 904dbfd33..348e0e73f 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" @@ -327,6 +328,14 @@ func (self *LocalCommitsController) interactiveRebase(action string) error { // begin a rebase. It then updates the todo file with that action func (self *LocalCommitsController) handleMidRebaseCommand(action string, commit *models.Commit) (bool, error) { if !commit.IsTODO() { + if self.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE { + // If we are in a rebase, the only action that is allowed for + // non-todo commits is rewording the current head commit + if !(action == "reword" && self.isHeadCommit()) { + return true, self.c.ErrorMsg(self.c.Tr.AlreadyRebasing) + } + } + return false, nil } @@ -383,6 +392,10 @@ func (self *LocalCommitsController) moveDown(commit *models.Commit) error { }) } + if self.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE { + return self.c.ErrorMsg(self.c.Tr.AlreadyRebasing) + } + return self.c.WithWaitingStatus(self.c.Tr.MovingStatus, func() error { self.c.LogAction(self.c.Tr.Actions.MoveCommitDown) err := self.git.Rebase.MoveCommitDown(self.model.Commits, index) @@ -417,6 +430,10 @@ func (self *LocalCommitsController) moveUp(commit *models.Commit) error { }) } + if self.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE { + return self.c.ErrorMsg(self.c.Tr.AlreadyRebasing) + } + return self.c.WithWaitingStatus(self.c.Tr.MovingStatus, func() error { self.c.LogAction(self.c.Tr.Actions.MoveCommitUp) err := self.git.Rebase.MoveCommitDown(self.model.Commits, index-1) |