mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-17 22:32:58 +02:00
Don't preserve commit message when it's unchanged from initial message
Sometimes we populate the commit message panel with a pre-created commit message. The two cases where this happens is: - you type `w` to commit, in which case we put the skipHookPrefix in the subject - you have a commitPrefix pattern, in which case we match it against the branch name and populate the subject with the replacement string if it matches In either case, if you have a preserved commit message, we use that. Now, when you use either of these and then cancel, we preserve that initial, unchanged message and reuse it the next time you commit. This has two problems: it strips spaces, which is a problem for the commitPrefix patterns, which often end with a space. And also, when you change your config to experiment with commitPrefix patterns, the change seemingly doesn't take effect, which can be very confusing. To fix both of these problems, only preserve the commit message when it is not identical to the initial message.
This commit is contained in:
parent
ec92d92bf4
commit
3a30211099
@ -30,6 +30,9 @@ type CommitMessageViewModel struct {
|
|||||||
// if true, then upon escaping from the commit message panel, we will preserve
|
// 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
|
// the message so that it's still shown next time we open the panel
|
||||||
preserveMessage bool
|
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)
|
// the full preserved message (combined summary and description)
|
||||||
preservedMessage string
|
preservedMessage string
|
||||||
// invoked when pressing enter in the commit message panel
|
// invoked when pressing enter in the commit message panel
|
||||||
@ -84,6 +87,10 @@ func (self *CommitMessageContext) SetPreservedMessage(message string) {
|
|||||||
self.viewModel.preservedMessage = message
|
self.viewModel.preservedMessage = message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *CommitMessageContext) GetInitialMessage() string {
|
||||||
|
return strings.TrimSpace(self.viewModel.initialMessage)
|
||||||
|
}
|
||||||
|
|
||||||
func (self *CommitMessageContext) GetHistoryMessage() string {
|
func (self *CommitMessageContext) GetHistoryMessage() string {
|
||||||
return self.viewModel.historyMessage
|
return self.viewModel.historyMessage
|
||||||
}
|
}
|
||||||
@ -101,11 +108,13 @@ func (self *CommitMessageContext) SetPanelState(
|
|||||||
summaryTitle string,
|
summaryTitle string,
|
||||||
descriptionTitle string,
|
descriptionTitle string,
|
||||||
preserveMessage bool,
|
preserveMessage bool,
|
||||||
|
initialMessage string,
|
||||||
onConfirm func(string, string) error,
|
onConfirm func(string, string) error,
|
||||||
onSwitchToEditor func(string) error,
|
onSwitchToEditor func(string) error,
|
||||||
) {
|
) {
|
||||||
self.viewModel.selectedindex = index
|
self.viewModel.selectedindex = index
|
||||||
self.viewModel.preserveMessage = preserveMessage
|
self.viewModel.preserveMessage = preserveMessage
|
||||||
|
self.viewModel.initialMessage = initialMessage
|
||||||
self.viewModel.onConfirm = onConfirm
|
self.viewModel.onConfirm = onConfirm
|
||||||
self.viewModel.onSwitchToEditor = onSwitchToEditor
|
self.viewModel.onSwitchToEditor = onSwitchToEditor
|
||||||
self.GetView().Title = summaryTitle
|
self.GetView().Title = summaryTitle
|
||||||
|
@ -143,6 +143,7 @@ func (self *CommitsHelper) OpenCommitMessagePanel(opts *OpenCommitMessagePanelOp
|
|||||||
opts.SummaryTitle,
|
opts.SummaryTitle,
|
||||||
opts.DescriptionTitle,
|
opts.DescriptionTitle,
|
||||||
opts.PreserveMessage,
|
opts.PreserveMessage,
|
||||||
|
opts.InitialMessage,
|
||||||
onConfirm,
|
onConfirm,
|
||||||
opts.OnSwitchToEditor,
|
opts.OnSwitchToEditor,
|
||||||
)
|
)
|
||||||
@ -177,8 +178,9 @@ func (self *CommitsHelper) HandleCommitConfirm() error {
|
|||||||
func (self *CommitsHelper) CloseCommitMessagePanel() {
|
func (self *CommitsHelper) CloseCommitMessagePanel() {
|
||||||
if self.c.Contexts().CommitMessage.GetPreserveMessage() {
|
if self.c.Contexts().CommitMessage.GetPreserveMessage() {
|
||||||
message := self.JoinCommitMessageAndUnwrappedDescription()
|
message := self.JoinCommitMessageAndUnwrappedDescription()
|
||||||
|
if message != self.c.Contexts().CommitMessage.GetInitialMessage() {
|
||||||
self.c.Contexts().CommitMessage.SetPreservedMessage(message)
|
self.c.Contexts().CommitMessage.SetPreservedMessage(message)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
self.SetMessageAndDescriptionInView("")
|
self.SetMessageAndDescriptionInView("")
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,8 @@ var CommitWithPrefix = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
|
|
||||||
t.ExpectPopup().CommitMessagePanel().
|
t.ExpectPopup().CommitMessagePanel().
|
||||||
Title(Equals("Commit summary")).
|
Title(Equals("Commit summary")).
|
||||||
/* EXPECTED:
|
|
||||||
InitialText(Equals("[TEST-001]: ")).
|
InitialText(Equals("[TEST-001]: ")).
|
||||||
Type("my commit message").
|
Type("my commit message").
|
||||||
ACTUAL: */
|
|
||||||
InitialText(Equals("[TEST-001]:")).
|
|
||||||
Type(" my commit message").
|
|
||||||
Cancel()
|
Cancel()
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
|
Loading…
x
Reference in New Issue
Block a user