Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions pkg/commands/git_commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down
22 changes: 18 additions & 4 deletions pkg/gui/controllers/helpers/fixup_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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", "--"}

Expand Down
6 changes: 3 additions & 3 deletions pkg/integration/tests/commit/find_base_commit_for_fixup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
".*3rd commit\n" +
".*2nd commit"),
).
Confirm()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down