From bd0d9ef25911129846012baeb81005ec5f254710 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 30 Nov 2024 15:28:07 +0100 Subject: [PATCH] Disable fixup/squash for merge commits --- pkg/gui/controllers/local_commits_controller.go | 6 +++++- pkg/i18n/english.go | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 306a7173a..b7744788f 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -1358,11 +1358,15 @@ func (self *LocalCommitsController) canFindCommitForSquashFixupsInCurrentBranch( return nil } -func (self *LocalCommitsController) canSquashOrFixup(_selectedCommits []*models.Commit, startIdx int, endIdx int) *types.DisabledReason { +func (self *LocalCommitsController) canSquashOrFixup(selectedCommits []*models.Commit, startIdx int, endIdx int) *types.DisabledReason { if endIdx >= len(self.c.Model().Commits)-1 { return &types.DisabledReason{Text: self.c.Tr.CannotSquashOrFixupFirstCommit} } + if lo.SomeBy(selectedCommits, func(c *models.Commit) bool { return c.IsMerge() }) { + return &types.DisabledReason{Text: self.c.Tr.CannotSquashOrFixupMergeCommit} + } + return nil } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 0d2af423f..2813a1a5f 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -140,6 +140,7 @@ type TranslationSet struct { Quit string SquashTooltip string CannotSquashOrFixupFirstCommit string + CannotSquashOrFixupMergeCommit string Fixup string FixupTooltip string SureFixupThisCommit string @@ -1135,6 +1136,7 @@ func EnglishTranslationSet() *TranslationSet { UpdateRefHere: "Update branch '{{.ref}}' here", ExecCommandHere: "Execute the following command here:", CannotSquashOrFixupFirstCommit: "There's no commit below to squash into", + CannotSquashOrFixupMergeCommit: "Cannot squash or fixup a merge commit", Fixup: "Fixup", SureFixupThisCommit: "Are you sure you want to 'fixup' the selected commit(s) into the commit below?", SureSquashThisCommit: "Are you sure you want to squash the selected commit(s) into the commit below?",