From 41d5f4dbb5571db2b8812e9000af78cfab0e7d05 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 23 Jan 2024 17:03:29 +1100 Subject: [PATCH] Disallow updating non-standard TODO lines when rebasing --- .../controllers/local_commits_controller.go | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index e1d20b554..2062907f0 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -1028,7 +1028,7 @@ func (self *LocalCommitsController) midRebaseCommandEnabled(selectedCommits []*m return &types.DisabledReason{Text: self.c.Tr.MustSelectTodoCommits} } - if commit.Action == models.ActionConflict { + if !isChangeOfRebaseTodoAllowed(commit.Action) { return &types.DisabledReason{Text: self.c.Tr.ChangingThisActionIsNotAllowed} } } @@ -1036,6 +1036,24 @@ func (self *LocalCommitsController) midRebaseCommandEnabled(selectedCommits []*m return nil } +// These actions represent standard things you might want to do with a commit, +// as opposed to TODO actions like 'merge', 'update-ref', etc. +var standardActions = []todo.TodoCommand{ + todo.Pick, + todo.Drop, + todo.Edit, + todo.Fixup, + todo.Squash, + todo.Reword, +} + +func isChangeOfRebaseTodoAllowed(oldAction todo.TodoCommand) bool { + // Only allow updating a standard action, meaning we disallow + // updating a merge commit or update ref commit (until we decide what would be sensible + // to do in those cases) + return lo.Contains(standardActions, oldAction) +} + func (self *LocalCommitsController) pickEnabled(selectedCommits []*models.Commit, startIdx int, endIdx int) *types.DisabledReason { if !self.isRebasing() { // if not rebasing, we're going to do a pull so we don't care about the selection