diff options
author | Sean <seand52@gmail.com> | 2023-01-21 11:38:14 +0000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-04-30 12:17:34 +1000 |
commit | 49da7b482d4f3012814e4100a556ecfad3f0742d (patch) | |
tree | 4d403b4301e0918c57ba292b11d6ce9256e8843a /pkg/integration | |
parent | 826128a8e03fb50f7287029ebac93c85712faecb (diff) |
Split commit message panel into commit summary and commit description 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.
Diffstat (limited to 'pkg/integration')
-rw-r--r-- | pkg/integration/components/commit_description_panel_driver.go | 25 | ||||
-rw-r--r-- | pkg/integration/components/commit_message_panel_driver.go | 33 | ||||
-rw-r--r-- | pkg/integration/components/popup.go | 13 | ||||
-rw-r--r-- | pkg/integration/components/view_driver.go | 5 | ||||
-rw-r--r-- | pkg/integration/components/views.go | 4 | ||||
-rw-r--r-- | pkg/integration/tests/commit/commit_multiline.go | 12 | ||||
-rw-r--r-- | pkg/integration/tests/commit/reword.go | 66 | ||||
-rw-r--r-- | pkg/integration/tests/interactive_rebase/reword_first_commit.go | 4 | ||||
-rw-r--r-- | pkg/integration/tests/interactive_rebase/reword_last_commit.go | 4 | ||||
-rw-r--r-- | pkg/integration/tests/interactive_rebase/reword_you_are_here_commit.go | 4 | ||||
-rw-r--r-- | pkg/integration/tests/test_list.go | 1 |
11 files changed, 161 insertions, 10 deletions
diff --git a/pkg/integration/components/commit_description_panel_driver.go b/pkg/integration/components/commit_description_panel_driver.go new file mode 100644 index 000000000..46d36652d --- /dev/null +++ b/pkg/integration/components/commit_description_panel_driver.go @@ -0,0 +1,25 @@ +package components + +type CommitDescriptionPanelDriver struct { + t *TestDriver +} + +func (self *CommitDescriptionPanelDriver) getViewDriver() *ViewDriver { + return self.t.Views().CommitDescription() +} + +func (self *CommitDescriptionPanelDriver) Type(value string) *CommitDescriptionPanelDriver { + self.t.typeContent(value) + + return self +} + +func (self *CommitDescriptionPanelDriver) SwitchToSummary() *CommitMessagePanelDriver { + self.getViewDriver().PressTab() + return &CommitMessagePanelDriver{t: self.t} +} + +func (self *CommitDescriptionPanelDriver) AddNewline() *CommitDescriptionPanelDriver { + self.t.press(self.t.keys.Universal.Confirm) + return self +} diff --git a/pkg/integration/components/commit_message_panel_driver.go b/pkg/integration/components/commit_message_panel_driver.go index e420334bf..d077761fc 100644 --- a/pkg/integration/components/commit_message_panel_driver.go +++ b/pkg/integration/components/commit_message_panel_driver.go @@ -10,19 +10,36 @@ func (self *CommitMessagePanelDriver) getViewDriver() *ViewDriver { // asserts on the text initially present in the prompt func (self *CommitMessagePanelDriver) InitialText(expected *Matcher) *CommitMessagePanelDriver { + return self.Content(expected) +} + +// asserts on the current context in the prompt +func (self *CommitMessagePanelDriver) Content(expected *Matcher) *CommitMessagePanelDriver { self.getViewDriver().Content(expected) return self } +// asserts that the confirmation view has the expected title +func (self *CommitMessagePanelDriver) Title(expected *Matcher) *CommitMessagePanelDriver { + self.getViewDriver().Title(expected) + + return self +} + func (self *CommitMessagePanelDriver) Type(value string) *CommitMessagePanelDriver { self.t.typeContent(value) return self } +func (self *CommitMessagePanelDriver) SwitchToDescription() *CommitDescriptionPanelDriver { + self.getViewDriver().PressTab() + return &CommitDescriptionPanelDriver{t: self.t} +} + func (self *CommitMessagePanelDriver) AddNewline() *CommitMessagePanelDriver { - self.t.press(self.t.keys.Universal.AppendNewline) + self.t.press(self.t.keys.Universal.Confirm) return self } @@ -49,6 +66,20 @@ func (self *CommitMessagePanelDriver) Confirm() { self.getViewDriver().PressEnter() } +func (self *CommitMessagePanelDriver) Close() { + self.getViewDriver().PressEscape() +} + func (self *CommitMessagePanelDriver) Cancel() { self.getViewDriver().PressEscape() } + +func (self *CommitMessagePanelDriver) SelectPreviousMessage() *CommitMessagePanelDriver { + self.getViewDriver().SelectPreviousItem() + return self +} + +func (self *CommitMessagePanelDriver) SelectNextMessage() *CommitMessagePanelDriver { + self.getViewDriver().SelectNextItem() + return self +} diff --git a/pkg/integration/components/popup.go b/pkg/integration/components/popup.go index b342fa03c..46df83e23 100644 --- a/pkg/integration/components/popup.go +++ b/pkg/integration/components/popup.go @@ -62,9 +62,22 @@ func (self *Popup) CommitMessagePanel() *CommitMessagePanelDriver { return &CommitMessagePanelDriver{t: self.t} } +func (self *Popup) CommitDescriptionPanel() *CommitMessagePanelDriver { + self.inCommitDescriptionPanel() + + return &CommitMessagePanelDriver{t: self.t} +} + func (self *Popup) inCommitMessagePanel() { self.t.assertWithRetries(func() (bool, string) { currentView := self.t.gui.CurrentContext().GetView() return currentView.Name() == "commitMessage", "Expected commit message panel to be focused" }) } + +func (self *Popup) inCommitDescriptionPanel() { + self.t.assertWithRetries(func() (bool, string) { + currentView := self.t.gui.CurrentContext().GetView() + return currentView.Name() == "commitDescription", "Expected commit description panel to be focused" + }) +} diff --git a/pkg/integration/components/view_driver.go b/pkg/integration/components/view_driver.go index 280843cf3..eb9c0d7f7 100644 --- a/pkg/integration/components/view_driver.go +++ b/pkg/integration/components/view_driver.go @@ -361,6 +361,11 @@ func (self *ViewDriver) PressEnter() *ViewDriver { return self.Press(self.t.keys.Universal.Confirm) } +// i.e. pressing tab +func (self *ViewDriver) PressTab() *ViewDriver { + return self.Press(self.t.keys.Universal.TogglePanel) +} + // i.e. pressing escape func (self *ViewDriver) PressEscape() *ViewDriver { return self.Press(self.t.keys.Universal.Return) diff --git a/pkg/integration/components/views.go b/pkg/integration/components/views.go index 667fe9471..1a6e54b7e 100644 --- a/pkg/integration/components/views.go +++ b/pkg/integration/components/views.go @@ -207,6 +207,10 @@ func (self *Views) CommitMessage() *ViewDriver { return self.regularView("commitMessage") } +func (self *Views) CommitDescription() *ViewDriver { + return self.regularView("commitDescription") +} + func (self *Views) Suggestions() *ViewDriver { return self.regularView("suggestions") } diff --git a/pkg/integration/tests/commit/commit_multiline.go b/pkg/integration/tests/commit/commit_multiline.go index 4967ffb77..d36a5fdb4 100644 --- a/pkg/integration/tests/commit/commit_multiline.go +++ b/pkg/integration/tests/commit/commit_multiline.go @@ -22,14 +22,20 @@ var CommitMultiline = NewIntegrationTest(NewIntegrationTestArgs{ PressPrimaryAction(). Press(keys.Files.CommitChanges) - t.ExpectPopup().CommitMessagePanel().Type("first line").AddNewline().AddNewline().Type("third line").Confirm() - + t.ExpectPopup().CommitMessagePanel(). + Type("first line"). + SwitchToDescription(). + AddNewline(). + AddNewline(). + Type("fourth line"). + SwitchToSummary(). + Confirm() t.Views().Commits(). Lines( Contains("first line"), ) t.Views().Commits().Focus() - t.Views().Main().Content(MatchesRegexp("first line\n\\s*\n\\s*third line")) + t.Views().Main().Content(MatchesRegexp("first line\n\\s*\n\\s*fourth line")) }, }) diff --git a/pkg/integration/tests/commit/reword.go b/pkg/integration/tests/commit/reword.go new file mode 100644 index 000000000..f488977ed --- /dev/null +++ b/pkg/integration/tests/commit/reword.go @@ -0,0 +1,66 @@ +package commit + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var Reword = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Staging a couple files and committing", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFile("myfile", "myfile content") + shell.CreateFile("myfile2", "myfile2 content") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + IsEmpty() + + t.Views().Files(). + IsFocused(). + PressPrimaryAction(). + Press(keys.Files.CommitChanges) + + commitMessage := "my commit message" + + t.ExpectPopup().CommitMessagePanel().Type(commitMessage).Confirm() + t.Views().Commits(). + Lines( + Contains(commitMessage), + ) + + t.Views().Files(). + IsFocused(). + PressPrimaryAction(). + Press(keys.Files.CommitChanges) + + wipCommitMessage := "my commit message wip" + + t.ExpectPopup().CommitMessagePanel().Type(wipCommitMessage).Close() + + t.Views().Commits().Focus(). + Lines( + Contains(commitMessage), + ).Press(keys.Commits.RenameCommit) + + t.ExpectPopup().CommitMessagePanel(). + SwitchToDescription(). + Type("some description"). + SwitchToSummary(). + Confirm() + + t.Views().Main().Content(MatchesRegexp("my commit message\n\\s*some description")) + + t.Views().Files(). + Focus(). + Press(keys.Files.CommitChanges) + + t.ExpectPopup().CommitMessagePanel().Confirm() + t.Views().Commits(). + Lines( + Contains(wipCommitMessage), + ) + }, +}) diff --git a/pkg/integration/tests/interactive_rebase/reword_first_commit.go b/pkg/integration/tests/interactive_rebase/reword_first_commit.go index c85293cec..50ca2fb0e 100644 --- a/pkg/integration/tests/interactive_rebase/reword_first_commit.go +++ b/pkg/integration/tests/interactive_rebase/reword_first_commit.go @@ -27,8 +27,8 @@ var RewordFirstCommit = NewIntegrationTest(NewIntegrationTestArgs{ NavigateToLine(Contains("commit 01")). Press(keys.Commits.RenameCommit). Tap(func() { - t.ExpectPopup().Prompt(). - Title(Equals("reword commit")). + t.ExpectPopup().CommitMessagePanel(). + Title(Equals("Reword commit")). InitialText(Equals("commit 01")). Clear(). Type("renamed 01"). diff --git a/pkg/integration/tests/interactive_rebase/reword_last_commit.go b/pkg/integration/tests/interactive_rebase/reword_last_commit.go index 9a4329219..742b250d4 100644 --- a/pkg/integration/tests/interactive_rebase/reword_last_commit.go +++ b/pkg/integration/tests/interactive_rebase/reword_last_commit.go @@ -23,8 +23,8 @@ var RewordLastCommit = NewIntegrationTest(NewIntegrationTestArgs{ ). Press(keys.Commits.RenameCommit). Tap(func() { - t.ExpectPopup().Prompt(). - Title(Equals("reword commit")). + t.ExpectPopup().CommitMessagePanel(). + Title(Equals("Reword commit")). InitialText(Equals("commit 02")). Clear(). Type("renamed 02"). diff --git a/pkg/integration/tests/interactive_rebase/reword_you_are_here_commit.go b/pkg/integration/tests/interactive_rebase/reword_you_are_here_commit.go index 921e1a016..c7431d059 100644 --- a/pkg/integration/tests/interactive_rebase/reword_you_are_here_commit.go +++ b/pkg/integration/tests/interactive_rebase/reword_you_are_here_commit.go @@ -31,8 +31,8 @@ var RewordYouAreHereCommit = NewIntegrationTest(NewIntegrationTestArgs{ ). Press(keys.Commits.RenameCommit). Tap(func() { - t.ExpectPopup().Prompt(). - Title(Equals("reword commit")). + t.ExpectPopup().CommitMessagePanel(). + Title(Equals("Reword commit")). InitialText(Equals("commit 02")). Clear(). Type("renamed 02"). diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index d4da79732..10838c008 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -53,6 +53,7 @@ var tests = []*components.IntegrationTest{ commit.ResetAuthor, commit.Revert, commit.RevertMerge, + commit.Reword, commit.Search, commit.SetAuthor, commit.StageRangeOfLines, |