-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Preserve pending commit message when closing/re-opening #4191
Preserve pending commit message when closing/re-opening #4191
Conversation
b643d5e
to
c3b8e04
Compare
@jesseduffield @stefanhaller - I gave a shot to the approach of storing the pending commit message in a custom file placed in the Also, I created two commits so that we could ensure that the original commit persistence test ran correctly before updating it. |
Nice, I'll give this a test today |
This looks mostly good, and I tested it and it works great. I also like the decision to store the message in a file in I only have a concern about error handling; I don't like it that so many functions now return an error that previously didn't. For example, The problem with this is that we now have two different classes of errors, really important ones and then these less important ones when storing the commit message fails (which, let's be honest, will never fail in practice). And this is a problem because it makes error handling more complex; for a function that first runs a git operation and then closes the panel, it now has to check if the git operation failed, and if so return that error (even if the closePanel function also returned one). This is cumbersome and error-prone, so I'd prefer it if these minor, unimportant failures were not reported through error return values, but maybe only logged (like we do for |
bec599c
to
5789d9c
Compare
@stefanhaller - I refactored the branch to log errors instead of handling them when setting or getting the persisted commit message, as you suggested (it honestly makes sense - I wasn't aware that pattern was already part of the codebase). Let me know if this version works better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better, looks great to me now. Just two small things below.
One word about this convention of prefixing commit messages with feat:
or test:
(again): I really don't like it, and I wish we wouldn't use it here. It looks ugly and provides no value to me; on the contrary, it constantly makes me go and verify whether the prefixes are really correct. I find this distracting. If the goal is that this helps you make sure you separate refactorings from adding features, then I do this anyway all the time, and I don't need those prefixes for that.
} | ||
if pendingCommitExists && len(message) == 0 { | ||
return self.c.Fs.Remove(preservedFilePath) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the logic of this method a bit unnecessarily complicated, and pushed a fixup to simplify it (6f07e2c). Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stefanhaller - happy to accept your suggestion, we don't really need to distinguish between presence vs deletion errors. I'll rebase-squash, thanks.
@@ -86,7 +86,7 @@ func (self *CommitMessageContext) GetPreserveMessage() bool { | |||
return self.viewModel.preserveMessage | |||
} | |||
|
|||
func (self *CommitMessageContext) GetPreservedMessage() (string, error) { | |||
func (self *CommitMessageContext) getPreservedMessage() (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really see a reason why this shouldn't be squashed into the first commit of the branch.
6f07e2c
to
471ba9d
Compare
I'm used to conventional commits since they allow us to automate the creation of release messages, but since we don't use it that way, I'm happy to drop it. In this specific case, I created a test-specific commit so that we could ensure that the test was working with the new code before updating it. In other circumstances, I would have used a single commit to keep the feature + its test(s) in the same place. @stefanhaller - I rebased the branch on the current master, squashed your fixup and modified the commits to strip the conventional commits prefixes. |
471ba9d
to
6065908
Compare
Yes, I noticed that and I support the decision. Still, I think the conventional commits prefixes don't help with understanding that. (Personally, I would have mentioned this rationale in the commit message body of the second commit.) |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.45.2` -> `v0.47.1` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary> ### [`v0.47.1`](https://github.com/jesseduffield/lazygit/releases/tag/v0.47.1) [Compare Source](jesseduffield/lazygit@v0.46.0...v0.47.1) <!-- Release notes generated using configuration in .github/release.yml at v0.47.1 --> #### What's Changed ##### Maintenance ⚙️ - Fix race condition with reselecting the focused branch and rendering by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4268 **Full Changelog**: jesseduffield/lazygit@v0.47.0...v0.47.1 ### [`v0.46.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.46.0) [Compare Source](jesseduffield/lazygit@v0.45.2...v0.46.0) It's time for another Lazygit release! Thanks to all who contributed to this release. #### What's Changed ##### Enhancements 🔥 - Preserve pending commit message when closing/re-opening by [@​AzraelSec](https://github.com/AzraelSec) in jesseduffield/lazygit#4191 - Swap position of checkout-commit and checkout-branch menu items by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4238 - In a previous release we had made it so that when you press space on a commit, the first option in the menu was to check out the corresponding branch, rather than the commit itself. We've made it so that now the first option is to check out the commit itself, for the sake of everybody's muscle memory. - Allow user to filter the files view to only show untracked files by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4226 - Expose {{.SelectedCommitRange}} to custom commands by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4204 - Show background fetch status in bottom line by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4215 - Support copying tags to clipboard by [@​brunofjesus](https://github.com/brunofjesus) in jesseduffield/lazygit#4218 - Add option to delete local and remote tag by [@​AnvarU](https://github.com/AnvarU) in jesseduffield/lazygit#4217 - Show confirmation menu when trying to amend changes while there are conflicts by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4222 - Improve error reporting on config migration by [@​kas2020-commits](https://github.com/kas2020-commits) in jesseduffield/lazygit#4210 - Show files filter status by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4230 - Improve contrast of highlighted search results by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4242 ##### Fixes 🔧 - Don't try killing processes if we already know the command finished by [@​brandondong](https://github.com/brandondong) in jesseduffield/lazygit#4231 - We believe this was causing all sorts of problems for windows users. - Add '--' to 'git rev-list' to disambiguate branch name from path by [@​efussi](https://github.com/efussi) in jesseduffield/lazygit#4185 - Fix adding blank line at end of commit message by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4182 - Fix checking out a different branch while pushing a branch for the first time by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4214 - Fix tag being truncated when copying to clipboard by [@​brunofjesus](https://github.com/brunofjesus) in jesseduffield/lazygit#4232 - Disable staging and unstaging lines or hunks when the diff context size is 0 by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4235 - Fix incorrect stash diff after rename by [@​brandondong](https://github.com/brandondong) in jesseduffield/lazygit#4213 - Fix possible crash when deleting a branch while filtering is active by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4195 - Fix pasting multi-line text into commit message panel by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4234 - fix: properly detect icon for BAZEL and WORKSPACE files by [@​PeterCardenas](https://github.com/PeterCardenas) in jesseduffield/lazygit#4252 - Fix json schema for context of CustomCommand by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4255 ##### Maintenance ⚙️ - Bump go-deadlock version to fix crash with go 1.23 in debug mode by [@​ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4248 - Fix auto-release workflow by [@​jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4265 ##### I18n 🌎 - Update translations; includes a new Portuguese translation by [@​stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4250 #### New Contributors - [@​efussi](https://github.com/efussi) made their first contribution in jesseduffield/lazygit#4185 - [@​brunofjesus](https://github.com/brunofjesus) made their first contribution in jesseduffield/lazygit#4218 - [@​AnvarU](https://github.com/AnvarU) made their first contribution in jesseduffield/lazygit#4217 - [@​kas2020-commits](https://github.com/kas2020-commits) made their first contribution in jesseduffield/lazygit#4210 - [@​ChrisMcD1](https://github.com/ChrisMcD1) made their first contribution in jesseduffield/lazygit#4248 - [@​PeterCardenas](https://github.com/PeterCardenas) made their first contribution in jesseduffield/lazygit#4252 **Full Changelog**: jesseduffield/lazygit@v0.45.2...v0.46.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xNzAuMSIsInVwZGF0ZWRJblZlciI6IjM5LjE3Ni40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Hello! I just wanted to chime in here and say that this feature is really appreciated! I just noticed after updating Lazygit. 👍🏻 I don't know how many times i had to reword my commit message after i had to close it. Great work guys! ⭐ |
This PR allows lazygit to preserve the commit messages when the commit popup gets closed.
While discussing the feature as part of its issue, two approaches were taken into consideration:
.git
folderI opted for the second approach to avoid worrying about associating each preserved message to the worktree it belongs to. I am happy to reconsider this and opt for the alternative approach, but I wanted to discuss this with the maintainers before deciding.
Note: The preserving file (
.git/LAZYGIT_PENDING_COMMIT
) is deleted when the commit is finalized or when the commit content becomes empty.go generate ./...
)