From 26e58b8def2b981143fe902e05c9a4bb23a95dd1 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Wed, 14 May 2025 21:56:31 -0400 Subject: [PATCH 1/4] Remove the call to OnCommitSuccess from tag creation This is no change in behavior because OnCommitSuccess only clears the message when the commit message panel was opened with preserveMessage=true, which it isn't in the case of creating a tag. And this is in fact the desired behavior, because we don't want creating a tag to interfere with preserving commit messages in any way. --- pkg/gui/controllers/helpers/tags_helper.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/gui/controllers/helpers/tags_helper.go b/pkg/gui/controllers/helpers/tags_helper.go index dccc26e00..022b7969b 100644 --- a/pkg/gui/controllers/helpers/tags_helper.go +++ b/pkg/gui/controllers/helpers/tags_helper.go @@ -34,7 +34,6 @@ func (self *TagsHelper) OpenCreateTagPrompt(ref string, onCreate func()) error { } return self.gpg.WithGpgHandling(command, git_commands.TagGpgSign, self.c.Tr.CreatingTag, func() error { - self.commitsHelper.OnCommitSuccess() return nil }, []types.RefreshableView{types.COMMITS, types.TAGS}) } From 04bacbf9cef59cbd9a126f18445a554be765f250 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Thu, 15 May 2025 18:30:45 +0200 Subject: [PATCH 2/4] Remove the if statement from OnCommitSuccess Previously it would only clear the message if the panel had been opened with preserveMessage=true; we don't need this check, because callers know how they opened the panel, and whether they want to clear the message. --- pkg/gui/controllers/helpers/commits_helper.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/gui/controllers/helpers/commits_helper.go b/pkg/gui/controllers/helpers/commits_helper.go index 9d2fcd164..188e9d60a 100644 --- a/pkg/gui/controllers/helpers/commits_helper.go +++ b/pkg/gui/controllers/helpers/commits_helper.go @@ -159,9 +159,7 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp func (self *CommitsHelper) OnCommitSuccess() { // if we have a preserved message we want to clear it on success - if self.c.Contexts().CommitMessage.GetPreserveMessage() { - self.c.Contexts().CommitMessage.SetPreservedMessageAndLogError("") - } + self.c.Contexts().CommitMessage.SetPreservedMessageAndLogError("") } func (self *CommitsHelper) HandleCommitConfirm() error { From 47f1d847f19ac0184fa6ed84f6bff306c51b1b91 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Thu, 15 May 2025 18:27:53 +0200 Subject: [PATCH 3/4] Rename OnCommitSuccess to ClearPreservedCommitMessage In one case it was actually called *before* making a commit (when switching from the commit message panel to committing in the editor). And clearing the preserved message is the only thing it does, so name it after what it does rather than when it's called. --- pkg/gui/controllers/helpers/commits_helper.go | 3 +-- pkg/gui/controllers/helpers/working_tree_helper.go | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/gui/controllers/helpers/commits_helper.go b/pkg/gui/controllers/helpers/commits_helper.go index 188e9d60a..5404ac5c5 100644 --- a/pkg/gui/controllers/helpers/commits_helper.go +++ b/pkg/gui/controllers/helpers/commits_helper.go @@ -157,8 +157,7 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp self.c.Context().Push(self.c.Contexts().CommitMessage, types.OnFocusOpts{}) } -func (self *CommitsHelper) OnCommitSuccess() { - // if we have a preserved message we want to clear it on success +func (self *CommitsHelper) ClearPreservedCommitMessage() { self.c.Contexts().CommitMessage.SetPreservedMessageAndLogError("") } diff --git a/pkg/gui/controllers/helpers/working_tree_helper.go b/pkg/gui/controllers/helpers/working_tree_helper.go index 4d0d1e9da..69d5fa23f 100644 --- a/pkg/gui/controllers/helpers/working_tree_helper.go +++ b/pkg/gui/controllers/helpers/working_tree_helper.go @@ -112,7 +112,7 @@ func (self *WorkingTreeHelper) handleCommit(summary string, description string, self.c.LogAction(self.c.Tr.Actions.Commit) return self.gpgHelper.WithGpgHandling(cmdObj, git_commands.CommitGpgSign, self.c.Tr.CommittingStatus, func() error { - self.commitsHelper.OnCommitSuccess() + self.commitsHelper.ClearPreservedCommitMessage() return nil }, nil) } @@ -124,7 +124,7 @@ func (self *WorkingTreeHelper) switchFromCommitMessagePanelToEditor(filepath str // access to the last message that the user typed, and it might be very // different from what was last in the commit panel. So the best we can do // here is to always clear the remembered commit message. - self.commitsHelper.OnCommitSuccess() + self.commitsHelper.ClearPreservedCommitMessage() self.c.LogAction(self.c.Tr.Actions.Commit) return self.c.RunSubprocessAndRefresh( From 3bd8a923eea1c35ded11542fdb1f4b78fac8aa69 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Thu, 15 May 2025 18:29:14 +0200 Subject: [PATCH 4/4] Clear preserved commit message when entering CommitEditorPanel --- pkg/gui/controllers/helpers/working_tree_helper.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/gui/controllers/helpers/working_tree_helper.go b/pkg/gui/controllers/helpers/working_tree_helper.go index 69d5fa23f..9bff3dbc7 100644 --- a/pkg/gui/controllers/helpers/working_tree_helper.go +++ b/pkg/gui/controllers/helpers/working_tree_helper.go @@ -136,6 +136,10 @@ func (self *WorkingTreeHelper) switchFromCommitMessagePanelToEditor(filepath str // their editor rather than via the popup panel func (self *WorkingTreeHelper) HandleCommitEditorPress() error { return self.WithEnsureCommittableFiles(func() error { + // See reasoning in switchFromCommitMessagePanelToEditor for why it makes sense + // to clear this message before calling into the editor + self.commitsHelper.ClearPreservedCommitMessage() + self.c.LogAction(self.c.Tr.Actions.Commit) return self.c.RunSubprocessAndRefresh( self.c.Git().Commit.CommitEditorCmdObj(),