diff --git a/pkg/gui/context/commit_message_context.go b/pkg/gui/context/commit_message_context.go index 776043abe8c..aa70e60b808 100644 --- a/pkg/gui/context/commit_message_context.go +++ b/pkg/gui/context/commit_message_context.go @@ -30,6 +30,9 @@ type CommitMessageViewModel struct { // if true, then upon escaping from the commit message panel, we will preserve // the message so that it's still shown next time we open the panel preserveMessage bool + // we remember the initial message so that we can tell whether we should preserve + // the message; if it's still identical to the initial message, we don't + initialMessage string // the full preserved message (combined summary and description) preservedMessage string // invoked when pressing enter in the commit message panel @@ -84,6 +87,10 @@ func (self *CommitMessageContext) SetPreservedMessage(message string) { self.viewModel.preservedMessage = message } +func (self *CommitMessageContext) GetInitialMessage() string { + return strings.TrimSpace(self.viewModel.initialMessage) +} + func (self *CommitMessageContext) GetHistoryMessage() string { return self.viewModel.historyMessage } @@ -101,11 +108,13 @@ func (self *CommitMessageContext) SetPanelState( summaryTitle string, descriptionTitle string, preserveMessage bool, + initialMessage string, onConfirm func(string, string) error, onSwitchToEditor func(string) error, ) { self.viewModel.selectedindex = index self.viewModel.preserveMessage = preserveMessage + self.viewModel.initialMessage = initialMessage self.viewModel.onConfirm = onConfirm self.viewModel.onSwitchToEditor = onSwitchToEditor self.GetView().Title = summaryTitle diff --git a/pkg/gui/controllers/helpers/commits_helper.go b/pkg/gui/controllers/helpers/commits_helper.go index b0f954c2ec7..e66071b4d06 100644 --- a/pkg/gui/controllers/helpers/commits_helper.go +++ b/pkg/gui/controllers/helpers/commits_helper.go @@ -143,6 +143,7 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp opts.SummaryTitle, opts.DescriptionTitle, opts.PreserveMessage, + opts.InitialMessage, onConfirm, opts.OnSwitchToEditor, ) @@ -177,8 +178,9 @@ func (self *CommitsHelper) HandleCommitConfirm() error { func (self *CommitsHelper) CloseCommitMessagePanel() { if self.c.Contexts().CommitMessage.GetPreserveMessage() { message := self.JoinCommitMessageAndUnwrappedDescription() - - self.c.Contexts().CommitMessage.SetPreservedMessage(message) + if message != self.c.Contexts().CommitMessage.GetInitialMessage() { + self.c.Contexts().CommitMessage.SetPreservedMessage(message) + } } else { self.SetMessageAndDescriptionInView("") } diff --git a/pkg/integration/tests/commit/commit_with_prefix.go b/pkg/integration/tests/commit/commit_with_prefix.go index c2675f10359..fa49b0baf83 100644 --- a/pkg/integration/tests/commit/commit_with_prefix.go +++ b/pkg/integration/tests/commit/commit_with_prefix.go @@ -10,7 +10,12 @@ var CommitWithPrefix = NewIntegrationTest(NewIntegrationTestArgs{ ExtraCmdArgs: []string{}, Skip: false, SetupConfig: func(cfg *config.AppConfig) { - cfg.GetUserConfig().Git.CommitPrefixes = map[string]config.CommitPrefixConfig{"repo": {Pattern: "^\\w+\\/(\\w+-\\w+).*", Replace: "[$1]: "}} + cfg.GetUserConfig().Git.CommitPrefixes = map[string]config.CommitPrefixConfig{ + "repo": { + Pattern: `^\w+/(\w+-\w+).*`, + Replace: "[$1]: ", + }, + } }, SetupRepo: func(shell *Shell) { shell.NewBranch("feature/TEST-001") @@ -25,6 +30,15 @@ var CommitWithPrefix = NewIntegrationTest(NewIntegrationTestArgs{ PressPrimaryAction(). Press(keys.Files.CommitChanges) + t.ExpectPopup().CommitMessagePanel(). + Title(Equals("Commit summary")). + InitialText(Equals("[TEST-001]: ")). + Cancel() + + t.Views().Files(). + IsFocused(). + Press(keys.Files.CommitChanges) + t.ExpectPopup().CommitMessagePanel(). Title(Equals("Commit summary")). InitialText(Equals("[TEST-001]: ")).