From e2b3601c571213e4cc153d2c0dd4f31bbe95edb3 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 26 Nov 2025 18:55:16 +0100 Subject: [PATCH] Fix order of fixup base commits shown in ctrl-f error message --- pkg/gui/controllers/helpers/fixup_helper.go | 22 +++++++++++++++---- .../commit/find_base_commit_for_fixup.go | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index c082becc2..c53fa0245 100644 --- a/pkg/gui/controllers/helpers/fixup_helper.go +++ b/pkg/gui/controllers/helpers/fixup_helper.go @@ -114,10 +114,7 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error { // If there are multiple commits that could be the base commit, list // them in the error message. But only the candidates from the current // branch, not including any that are already merged. - subjects, err := self.c.Git().Commit.GetHashesAndCommitMessagesFirstLine(hashGroups[NOT_MERGED]) - if err != nil { - return err - } + subjects := self.getHashesAndSubjects(commits, hashGroups[NOT_MERGED]) message := lo.Ternary(hasStagedChanges, self.c.Tr.MultipleBaseCommitsFoundStaged, self.c.Tr.MultipleBaseCommitsFoundUnstaged) @@ -146,6 +143,23 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error { }) } +func (self *FixupHelper) getHashesAndSubjects(commits []*models.Commit, hashes []string) string { + // This is called only for the NOT_MERGED commits, and we know that all of them are contained in + // the commits slice. + commitsSet := set.NewFromSlice(hashes) + subjects := make([]string, 0, len(hashes)) + for _, c := range commits { + if commitsSet.Includes(c.Hash()) { + subjects = append(subjects, fmt.Sprintf("%s %s", c.ShortRefName(), c.Name)) + commitsSet.Remove(c.Hash()) + if commitsSet.Len() == 0 { + break + } + } + } + return strings.Join(subjects, "\n") +} + func (self *FixupHelper) getDiff() (string, bool, error) { args := []string{"-U0", "--ignore-submodules=all", "HEAD", "--"} diff --git a/pkg/integration/tests/commit/find_base_commit_for_fixup.go b/pkg/integration/tests/commit/find_base_commit_for_fixup.go index 22b6b4ed9..d7915abb3 100644 --- a/pkg/integration/tests/commit/find_base_commit_for_fixup.go +++ b/pkg/integration/tests/commit/find_base_commit_for_fixup.go @@ -37,8 +37,8 @@ var FindBaseCommitForFixup = NewIntegrationTest(NewIntegrationTestArgs{ Title(Equals("Error")). Content( MatchesRegexp("Multiple base commits found.*\n\n" + - ".*2nd commit\n" + - ".*3rd commit"), + ".*3rd commit\n" + + ".*2nd commit"), ). Confirm()