summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-06-03 19:55:17 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-03 12:54:14 +1000
commitcd989d8ebeb923af74e8074cee09863b50862410 (patch)
treeb0a46e56462fbdee6e7e9cc4b3ac65595a810c0e
parent261f30f49c552e3abe3bb7378208b0b355595c86 (diff)
Fix escape logic for remote branches
The remote branches controller was using its own escape method meaning it didn't go through the flow of cancelling an active filter. It's now using the same approach as the sub-commits and commit-files contexts: defining a parent context to return to upon hittin escape.
-rw-r--r--pkg/gui/controllers/remote_branches_controller.go9
-rw-r--r--pkg/gui/controllers/remotes_controller.go10
-rw-r--r--pkg/integration/tests/filter_and_search/filter_remote_branches.go59
-rw-r--r--pkg/integration/tests/test_list.go1
4 files changed, 66 insertions, 13 deletions
diff --git a/pkg/gui/controllers/remote_branches_controller.go b/pkg/gui/controllers/remote_branches_controller.go
index c1cc9d46b..b26230d90 100644
--- a/pkg/gui/controllers/remote_branches_controller.go
+++ b/pkg/gui/controllers/remote_branches_controller.go
@@ -60,11 +60,6 @@ func (self *RemoteBranchesController) GetKeybindings(opts types.KeybindingsOpts)
Description: self.c.Tr.SetAsUpstream,
},
{
- Key: opts.GetKey(opts.Config.Universal.Return),
- Handler: self.escape,
- Description: self.c.Tr.ReturnToRemotesList,
- },
- {
Key: opts.GetKey(opts.Config.Commits.ViewResetOptions),
Handler: self.checkSelected(self.createResetMenu),
Description: self.c.Tr.ViewResetOptions,
@@ -115,10 +110,6 @@ func (self *RemoteBranchesController) checkSelected(callback func(*models.Remote
}
}
-func (self *RemoteBranchesController) escape() error {
- return self.c.PushContext(self.c.Contexts().Remotes)
-}
-
func (self *RemoteBranchesController) delete(selectedBranch *models.RemoteBranch) error {
message := fmt.Sprintf("%s '%s'?", self.c.Tr.DeleteRemoteBranchMessage, selectedBranch.FullName())
diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go
index 283119886..b6d9a963b 100644
--- a/pkg/gui/controllers/remotes_controller.go
+++ b/pkg/gui/controllers/remotes_controller.go
@@ -104,14 +104,16 @@ func (self *RemotesController) enter(remote *models.Remote) error {
if len(remote.Branches) == 0 {
newSelectedLine = -1
}
- self.c.Contexts().RemoteBranches.SetSelectedLineIdx(newSelectedLine)
- self.c.Contexts().RemoteBranches.SetTitleRef(remote.Name)
+ remoteBranchesContext := self.c.Contexts().RemoteBranches
+ remoteBranchesContext.SetSelectedLineIdx(newSelectedLine)
+ remoteBranchesContext.SetTitleRef(remote.Name)
+ remoteBranchesContext.SetParentContext(self.Context())
- if err := self.c.PostRefreshUpdate(self.c.Contexts().RemoteBranches); err != nil {
+ if err := self.c.PostRefreshUpdate(remoteBranchesContext); err != nil {
return err
}
- return self.c.PushContext(self.c.Contexts().RemoteBranches)
+ return self.c.PushContext(remoteBranchesContext)
}
func (self *RemotesController) add() error {
diff --git a/pkg/integration/tests/filter_and_search/filter_remote_branches.go b/pkg/integration/tests/filter_and_search/filter_remote_branches.go
new file mode 100644
index 000000000..11cfea30b
--- /dev/null
+++ b/pkg/integration/tests/filter_and_search/filter_remote_branches.go
@@ -0,0 +1,59 @@
+package filter_and_search
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var FilterRemoteBranches = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Filtering remote branches",
+ ExtraCmdArgs: []string{},
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.NewBranch("branch-apple")
+ shell.EmptyCommit("commit-one")
+ shell.NewBranch("branch-grape")
+ shell.NewBranch("branch-orange")
+
+ shell.CloneIntoRemote("origin")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Remotes().
+ Focus().
+ Lines(
+ Contains(`origin`).IsSelected(),
+ ).
+ PressEnter()
+
+ t.Views().RemoteBranches().
+ IsFocused().
+ Lines(
+ Contains(`branch-apple`).IsSelected(),
+ Contains(`branch-grape`),
+ Contains(`branch-orange`),
+ ).
+ FilterOrSearch("grape").
+ Lines(
+ Contains(`branch-grape`).IsSelected(),
+ ).
+ // cancel the filter
+ PressEscape().
+ Tap(func() {
+ t.Views().Search().IsInvisible()
+ }).
+ Lines(
+ Contains(`branch-apple`),
+ Contains(`branch-grape`).IsSelected(),
+ Contains(`branch-orange`),
+ ).
+ // return to remotes view
+ PressEscape()
+
+ t.Views().Remotes().
+ IsFocused().
+ Lines(
+ Contains(`origin`).IsSelected(),
+ )
+ },
+})
diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go
index e3a6e51dd..9aab7ea43 100644
--- a/pkg/integration/tests/test_list.go
+++ b/pkg/integration/tests/test_list.go
@@ -98,6 +98,7 @@ var tests = []*components.IntegrationTest{
filter_and_search.FilterCommitFiles,
filter_and_search.FilterFiles,
filter_and_search.FilterMenu,
+ filter_and_search.FilterRemoteBranches,
filter_and_search.NestedFilter,
filter_and_search.NestedFilterTransient,
filter_by_path.CliArg,