Extract a helper that joins summary and description into a message

The next commit needs to build a commit message from the commit panel
in git's canonical format too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-11-11 19:51:44 +01:00
co-authored by Claude Opus 5.5
parent fc1443dee4
commit f11e1dca4c
+10 -4
View File
@@ -9,7 +9,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo"
)
type CommitsHelper struct {
@@ -48,6 +47,15 @@ func (self *CommitsHelper) SplitCommitMessageAndDescription(message string) (str
return summary, description
}
// joinCommitMessageAndDescription is the inverse of
// SplitCommitMessageAndDescription.
func (self *CommitsHelper) joinCommitMessageAndDescription(summary string, description string) string {
if len(description) == 0 {
return summary
}
return summary + "\n\n" + description
}
// SplitPreservedCommitMessage splits a message in our preservation format
// (summary and description joined by a single "\n") into summary and description.
// It is lossless: round-tripping through JoinCommitMessageAndUnwrappedDescription
@@ -103,9 +111,7 @@ func TryRemoveHardLineBreaks(message string, autoWrapWidth int) string {
}
func (self *CommitsHelper) SwitchToEditor() error {
message := lo.Ternary(len(self.getCommitDescription()) == 0,
self.getCommitSummary(),
self.getCommitSummary()+"\n\n"+self.getCommitDescription())
message := self.joinCommitMessageAndDescription(self.getCommitSummary(), self.getCommitDescription())
filepath := filepath.Join(self.c.OS().GetTempDir(), self.c.Git().RepoPaths.RepoName(), time.Now().Format("Jan _2 15.04.05.000000000")+".msg")
err := self.c.OS().CreateFileWithContent(filepath, message)
if err != nil {