Skip to content

Clear preserved commit message when entering CommitEditorPanel #4558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ChrisMcD1
Copy link
Contributor

  • PR Description

Pretty basic implementation of this fix. The one thing I considered doing that I didn't was to rename OnCommitSuccess, since now 2 out of 4 call sites invoke it prior to make the commit message (and one does it here to invoke a tag, which might be a separate bug)

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})

The implementation of OnCommitSuccess also leaves me a bit confused. I'm not sure why it doesn't clear the message every time. By checking with the CommitMessageViewModel.preserveMessage, we only open up the option that we don't clear an existing message should that be false. Is there some world where this is desired? I figure if they are opening the window without the intent to save the message, it would be even more okay to throw away any potential message stored there.

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("")
}
}

Fixes #4557

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@jesseduffield jesseduffield added the bug Something isn't working label May 13, 2025
@stefanhaller
Copy link
Collaborator

Pretty basic implementation of this fix.

Looks good to me.

The one thing I considered doing that I didn't was to rename OnCommitSuccess,

I'd be in favor of doing that. Maybe ClearPreservedCommitMessage or something like that.

and one does it here to invoke a tag, which might be a separate bug)

I don't think that's a bug, but this call could be removed, because it does nothing (since we are opening the tags panel with preserveMessage=false, see below). Could be another, separate cleanup commit.

The implementation of OnCommitSuccess also leaves me a bit confused. I'm not sure why it doesn't clear the message every time. By checking with the CommitMessageViewModel.preserveMessage, we only open up the option that we don't clear an existing message should that be false. Is there some world where this is desired?

Yes. I think the idea is that creating tags doesn't take part in the remember-my-partial-commit-message business. I'm not sure how relevant this really is in practice, but something like:

  • start to make a commit, begin typing a message, cancel halfway through
  • create a tag; neither uses nor clears the preserved message
  • press c again to continue your commit. Message is still there.

Chris McDonnell added 3 commits May 14, 2025 21:51
It was actually called several times prior to a commit success in cases
where the commit success would happen on a background process, and it
only cleared the preserved commit message, so this makes sense.
The implementation of ClearPreservedCommitMessage was designed to
protect against clearing in this scenario. We can remove that check if
we just remove this callsite.
Ever since we removed the other functionality of this function, we have
been slowly chipping away at its usages, in commits like
41a7afb. With the commit prior to this,
now all usages are from call sites that actually want to clear the
message because they have preserveMessage: true in their upstream, so we
don't need to check if preserveMessage is true before clearing.
@ChrisMcD1
Copy link
Contributor Author

I'd be in favor of doing that. Maybe ClearPreservedCommitMessage or something like that.

Stole your name because naming is hard 😆

I don't think that's a bug, but this call could be removed

Yeah, I misused the word "bug" there, I just meant "This is weird code". I have removed that call

I'm not sure how relevant this really is in practice

I have done some research and I believe this is now never relevant in practice. So I added a commit removing the check. With previous commits like 41a7afb we have been whittling down the usages of OnCommitSuccess, and at this point there are 3 call sites:

  1. working_tree_helper.handleCommit https://github.com/ChrisMcD1/lazygit/blob/2988df76aaa5fd1e0d31b57c7749984bc7ae328a/pkg/gui/controllers/helpers/working_tree_helper.go#L115
  2. working_tree_helper.HandleCommitEditorPress https://github.com/ChrisMcD1/lazygit/blob/2988df76aaa5fd1e0d31b57c7749984bc7ae328a/pkg/gui/controllers/helpers/working_tree_helper.go#L141
  3. working_tree.switchFromCommitMessagePanelToEditor https://github.com/ChrisMcD1/lazygit/blob/2988df76aaa5fd1e0d31b57c7749984bc7ae328a/pkg/gui/controllers/helpers/working_tree_helper.go#L127

which tracking their upstream leads to:

  1. handleCommit and switchFromCommitMessgePanelToEditor share the same singular callsite has preserveMessage: true https://github.com/ChrisMcD1/lazygit/blob/2988df76aaa5fd1e0d31b57c7749984bc7ae328a/pkg/gui/controllers/helpers/working_tree_helper.go#L94-L97
  2. HandleCommitEditorPress (this is the upstream)

^ This is the method we are adding this clearing to in this PR, and I'm thinking it should clear the preserved message regardless of the previous state of preserveMessage. If you begin a partial commit message with c, switch and create a tag with T, you have now made preserveMessage = false, so when you go back to committing, create a full commit message with C, you don't end up clearing the partial commit message. This feels less intuitive to me than "When I create a commit with C, I clear my partial message"

(But now that I've put the whole paragraph into words, I'm actually less convinced than when it was an idea floating around in my head. I'm open to reverting this last commit if people want)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preserved Commit Message not cleared when exiting git editor
3 participants