From c16b4b1d2e9022069eaee7ebeeb0e41ece56ec2e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 27 Nov 2025 10:59:15 +0100 Subject: [PATCH 1/3] Make find_base_commit_for_fixup tests more specific We want to test the order in which the commits are listed in the error message. For one of the tests the order is already as we want it, but for the other it's not (we want them to show up in log order). We'll fix this in the next commit. --- .../tests/commit/find_base_commit_for_fixup.go | 6 +++--- .../commit/find_base_commit_for_fixup_only_added_lines.go | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) 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 4440932e9..22b6b4ed9 100644 --- a/pkg/integration/tests/commit/find_base_commit_for_fixup.go +++ b/pkg/integration/tests/commit/find_base_commit_for_fixup.go @@ -36,9 +36,9 @@ var FindBaseCommitForFixup = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectPopup().Alert(). Title(Equals("Error")). Content( - Contains("Multiple base commits found"). - Contains("2nd commit"). - Contains("3rd commit"), + MatchesRegexp("Multiple base commits found.*\n\n" + + ".*2nd commit\n" + + ".*3rd commit"), ). Confirm() diff --git a/pkg/integration/tests/commit/find_base_commit_for_fixup_only_added_lines.go b/pkg/integration/tests/commit/find_base_commit_for_fixup_only_added_lines.go index 281fe72f9..6b1c96150 100644 --- a/pkg/integration/tests/commit/find_base_commit_for_fixup_only_added_lines.go +++ b/pkg/integration/tests/commit/find_base_commit_for_fixup_only_added_lines.go @@ -39,9 +39,11 @@ var FindBaseCommitForFixupOnlyAddedLines = NewIntegrationTest(NewIntegrationTest t.ExpectPopup().Alert(). Title(Equals("Error")). Content( - Contains("Multiple base commits found"). - Contains("3rd commit"). - Contains("4th commit"), + MatchesRegexp( + "Multiple base commits found.*\n\n" + + ".*4th commit\n" + + ".*3rd commit", + ), ). Confirm() From e2b3601c571213e4cc153d2c0dd4f31bbe95edb3 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 26 Nov 2025 18:55:16 +0100 Subject: [PATCH 2/3] 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() From 26453b26cf0b49eed5e435008a2a56af2a8e5daa Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 26 Nov 2025 21:44:21 +0100 Subject: [PATCH 3/3] Remove unused function GetHashesAndCommitMessagesFirstLine --- pkg/commands/git_commands/commit.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 89063be82..40d2b7319 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -217,20 +217,6 @@ func (self *CommitCommands) GetCommitMessagesFirstLine(hashes []string) (string, return self.cmd.New(cmdArgs).DontLog().RunWithOutput() } -// Example output: -// -// cd50c79ae Preserve the commit message correctly even if the description has blank lines -// 3ebba5f32 Add test demonstrating a bug with preserving the commit message -// 9a423c388 Remove unused function -func (self *CommitCommands) GetHashesAndCommitMessagesFirstLine(hashes []string) (string, error) { - cmdArgs := NewGitCmd("show"). - Arg("--no-patch", "--pretty=format:%h %s"). - Arg(hashes...). - ToArgv() - - return self.cmd.New(cmdArgs).DontLog().RunWithOutput() -} - func (self *CommitCommands) GetCommitsOneline(hashes []string) (string, error) { cmdArgs := NewGitCmd("show"). Arg("--no-patch", "--oneline").