From f11e1dca4c17634a76bcf22eb32f1a74906d9709 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 11 Nov 2026 09:10:55 +0100 Subject: [PATCH] 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 --- pkg/gui/controllers/helpers/commits_helper.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/gui/controllers/helpers/commits_helper.go b/pkg/gui/controllers/helpers/commits_helper.go index 3f0b64036..6a9b0861f 100644 --- a/pkg/gui/controllers/helpers/commits_helper.go +++ b/pkg/gui/controllers/helpers/commits_helper.go @@ -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 {