Revamp commit message window#2390
Conversation
acf6fb4 to
4099305
Compare
|
Few things: I would leave the second panel visible at all times, there's no need to toggle it, we don't gain anything by doing that. We should have a tooltip somewhere (if popups like that can have tooltips) that pressing I'd also expect that rewording an existing commit (pressing Other than that, looks great, well done! :) |
jesseduffield
left a comment
There was a problem hiding this comment.
Looking great so far! I've left some comments.
Also, see pkg/gui/commit_message_panel.go: we'll need to update handleCommitMessageFocused now that you can't enter a newline from the summary panel.
Lemme know if you have any questions
|
Is there really a case where we want to enter the same commit message as a previous commit? I can still understand if it works like history of shell. |
|
@Ryooooooga we would rarely enter the exact same message but if you're creating a sequence of commits with a pattern to them it's easier to start with the previous one and tweak it than to start from scratch |
Enter? No. |
7b938cb to
df231a1
Compare
|
@jesseduffield @mark2185 I've addressed the initial comments and implemented these features since you last had a look:
Before making the PR ready for review I just wanted to get your thoughts on how I'm handling the switching between summary/description. This has been implemented mostly in this commit. I'm just pushing to the panels to context every time we hit tab, and when closing the panels I added a new function that deactivates all popups. Is this a feasible solution? It seems to work fine, but I'm not sure if maybe I'm missing something! |
jesseduffield
left a comment
There was a problem hiding this comment.
Nice work, we're getting there! I've left some comments.
A couple things extra things:
- Whenever we bring up the commit message panel we should also show the commit description panel at the same time, rather than only showing it upon the user pressing 'tab'
- Currently if you go to write a commit message, type some stuff, then escape out, then open and close the same panel via the reword flow, we lose the stuff you originally typed. So we should store the message/description outside the view (when not rewording) and just clear the view itself whenever we close it. Then we can restore the message/description if we're opening the panel in the context of a non-reword commit.
Lemme know if you need any clarification/pointers
b10cd60 to
6471c51
Compare
0d7d9e9 to
bb03c19
Compare
|
@jesseduffield thanks for the tips! I've made the changes you suggested and it's looking better now! Would be great if you could take a look 🙂 |
|
If it's worth anything - I like it! Looks pretty good! :) |
|
Uffizzi Preview |
|
Hey, i think it's still time to suggest somethings, based on what i've just wrote in #2423, and was pointed here, for almost the same being done already:
|
That seems simple enough to be added in this PR as well.
This would maybe be better as a separate PR on top of this one since the commit window revamp is a big change in and of itself. |
|
I agree with @mark2185 , this PR is already pretty big (much bigger than I initially expected 😆 ). So we should add those extra features in a separate PR to avoid scope creep I like the |
|
Just noting that the |
|
@seand52 I'm in the process of testing this out locally: so far so good! BTW: one of the linting failures is resolved on master so if you rebase onto master it'll be fixed |
I was fixing some comments that @Ryooooooga left in the PR and changed quite a bit of stuff to fix this #2390 (comment). In addition to that, I've also noticed that when a commit fails it seems to clear the context and the message is not preserved 😢 . I haven't figured out why this is the case yet but I was going to work on that tomorrow as well. I have my changes locally though, and was going to push tomorrow. Maybe you can hold off on the testing until I do that ? |
|
@seand52 that's fine with me :) |
baa7ac8 to
9b4fb9c
Compare
pkg/gui/view_helpers.go
Outdated
| func (gui *Gui) resizePopupPanel(v *gocui.View, content string) error { | ||
| x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(v.Wrap, content) | ||
| _, err := gui.g.SetView(v.Name(), x0, y0, x1, y1, 0) | ||
| x0, y0, _, y1 := v.Dimensions() |
There was a problem hiding this comment.
There's currently an issue with the resizing when we have the setup of commit message panel and description below it. When we cycle through commits the resizing of the description goes wrong because it can't seem to calculate the correct height (see video).
This workaround works for this particular usecase because with the new setup we don't have to resize the height vertically (still resizes horizontally though). I don't know if this will be an issue with other popups though, what do you suggest we do here?
simplescreenrecorder-2023-02-11_15.12.49.mov
There was a problem hiding this comment.
We can't rely on the existing function because we need to resize the message and description view independently, but I still would like us to have code for making the commit description view taller if there's more content there. I would have a separate function specifically for resizing both the message and description views. We can also say within resizeCurrentPopupPanel that if the current view is the message or description view then we call our new resize method
| } | ||
|
|
||
| func (self *CommitsHelper) UpdateCommitPanelView(message string, description string) { | ||
| // first try the passed in message, if not fallback to context -> view in that order |
There was a problem hiding this comment.
This function is called from the files controller/local commits controller before opening the panel to set the messages. It needs to be done from there because the message will come from different places (for reword it comes through the git command, but for normal commits it comes from context).
Ideally I would to simply set whatever message and description comes through the args. However, From what I've seen, when a commit fails, the commit message context is cleared at some point, is that correct? Since that's the case, we need to fallback to render whatever is in the view, because that's not cleared. It would be much simpler if the context wasn't cleared when there is an error though 🤔
There was a problem hiding this comment.
I still prefer to the clear the context whenever we need to close is given that depending on what's in the view always ends up causing issues down the line.
If the commit fails, I would not expect the message to go away. Is that currently happening?
|
@jesseduffield I've made some additional changes/fixes and run all the tests locally. I've rebased and run the unit and new integration tests are all passing, but there are a couple of old tests that fail but they seem unrelated, it could be a local configuration thing. Can we run the pipeline again? Feel free to have a look now. I left a couple of comments in the PR, would be good to get your point of view on those topics to see if there's a simpler solution: |
pkg/config/user_config.go
Outdated
| ConfirmAlt2 string `yaml:"confirm-alt2"` | ||
| ConfirmAlt1 string `yaml:"confirm-alt1"` |
There was a problem hiding this comment.
| ConfirmAlt2 string `yaml:"confirm-alt2"` | |
| ConfirmAlt1 string `yaml:"confirm-alt1"` | |
| ConfirmAlt1 string `yaml:"confirm-alt1"` | |
| ConfirmAlt2 string `yaml:"confirm-alt2"` |
please update Config.md.
| func (self *CommitMessageController) setCommitMessageAtIndex(index int) error { | ||
| msg, err := self.git.Commit.GetCommitMessageFromHistory(index) | ||
| if err != nil { | ||
| if err.Error() == "invalid commit index" { |
There was a problem hiding this comment.
diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go
index e7ef056c..3758dbb7 100644
--- a/pkg/commands/git_commands/commit.go
+++ b/pkg/commands/git_commands/commit.go
@@ -178,11 +178,13 @@ func (self *CommitCommands) CreateFixupCommit(sha string) error {
return self.cmd.New(fmt.Sprintf("git commit --fixup=%s", sha)).Run()
}
+var ErrInvalidCommitIndex = errors.New("invalid commit index")
+
func (self *CommitCommands) GetCommitMessageFromHistory(value int) (string, error) {
hash, _ := self.cmd.New(fmt.Sprintf("git log -1 --skip=%d --pretty=%%H", value-1)).DontLog().RunWithOutput()
formattedHash := strings.TrimSpace(hash)
if len(formattedHash) == 0 {
- return "", errors.New("invalid commit index")
+ return "", ErrInvalidCommitIndex
}
return self.GetCommitMessage(formattedHash)
}| if err.Error() == "invalid commit index" { | |
| if err == git_commands.ErrInvalidCommitIndex { |
pkg/commands/git_commands/commit.go
Outdated
| } | ||
|
|
||
| func (self *CommitCommands) GetCommitMessageFromHistory(value int) (string, error) { | ||
| hash, _ := self.cmd.New(fmt.Sprintf("git log -1 --skip=%d --pretty=%%H", value-1)).DontLog().RunWithOutput() |
There was a problem hiding this comment.
git log fails when a repository is empty.
| hash, _ := self.cmd.New(fmt.Sprintf("git log -1 --skip=%d --pretty=%%H", value-1)).DontLog().RunWithOutput() | |
| hash, _, err := self.cmd.New(fmt.Sprintf("git log -1 --skip=%d --pretty=%%H", value-1)).DontLog().RunWithOutputs() | |
| if err != nil { | |
| return "", ErrInvalidCommitIndex | |
| } |
| self.context().SetIsAtFirstCommit(true) | ||
| return nil | ||
| } | ||
| return self.c.ErrorMsg(self.c.Tr.CommitWithoutMessageErr) |
There was a problem hiding this comment.
Is this error message appropriate?
|
|
||
| func (self *CommitsHelper) UpdateCommitPanelView(message string, description string) { | ||
| // first try the passed in message, if not fallback to context -> view in that order | ||
| if message != "" { |
|
@seand52 I've spent some time with your PR as a way to better understand/review it and I'd like to push some commits. Is that alright with you? |
Sure, feel free to push changes! The latest changes are all pushed 👍 |
|
Sweet, pushed :) Let me know if you have any questions about those changes. My main hangup now is around the context stuff and how we're pushing both contexts at once. I wanna spend a bit more time thinking if there's a better way to go about that. |
2efc39b to
0a4f529
Compare
3d6d781 to
16bb777
Compare
|
I'm pushing some small improvements. Haven't decided whether this should go in before the big refactor PR or if the refactor PR should go in first and I should rebase this on top of that. I'll probably do the latter (don't worry about handling that rebasey stuff yourself @seand52 , I won't inflict that upon you!) |
db2ba37 to
e3ccd0d
Compare
… panel When we use the one panel for the entire commit message, its tricky to have a keybinding both for adding a newline and submitting. By having two panels: one for the summary line and one for the description, we allow for 'enter' to submit the message when done from the summary panel, and 'enter' to add a newline when done from the description panel. Alt-enter, for those who can use that key combo, also works for submitting the message from the description panel. For those who can't use that key combo, and don't want to remap the keybinding, they can hit tab to go back to the summary panel and then 'enter' to submit the message. We have some awkwardness in that both contexts (i.e. panels) need to appear and disappear in tandem and we don't have a great way of handling that concept, so we just push both contexts one after the other, and likewise remove both contexts when we escape.
When cycling history, we want to make it so that upon returning to the original prompt, you get your text back. Importantly, we don't want to use the existing preservedMessage field for that because that's only for preserving a NEW commit message, and we don't want the history stuff of the commit reword flow to overwrite that.
We now refresh the staging panel when doing an unscoped refresh, so that if we commit from the staging panel we escape back to the files panel if need be. But that causes flickering when doing an unscoped refresh from other contexts, because the refreshStagingPanel function assumes that the staging panel has focus. So we're adding a guard at the top of that function to early exit if we don't have focus.
e3ccd0d to
9adbef4
Compare
|
Merged! Thanks again @seand52 for making this |
PR Description
Fixes Revamping the commit message window #2324
Press up/down arrows to cycle through previous commits
Instead of hitting alt + enter, press tab to toggle a new panel where you can add a commit description
Please check if the PR fulfills these requirements
go run scripts/cheatsheet/main.go generate)docs/Config.md) have been updated if necessary