Skip to content

Do not display recent repo list when it would be empty #4642

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/constants"
"github.com/jesseduffield/lazygit/pkg/env"
"github.com/jesseduffield/lazygit/pkg/gui"

Check failure on line 23 in pkg/app/app.go

View workflow job for this annotation

GitHub Actions / lint

could not import github.com/jesseduffield/lazygit/pkg/gui (-: # github.com/jesseduffield/lazygit/pkg/gui

Check failure on line 23 in pkg/app/app.go

View workflow job for this annotation

GitHub Actions / lint

could not import github.com/jesseduffield/lazygit/pkg/gui (-: # github.com/jesseduffield/lazygit/pkg/gui
"github.com/jesseduffield/lazygit/pkg/i18n"
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
"github.com/jesseduffield/lazygit/pkg/logs"
Expand Down Expand Up @@ -129,11 +129,9 @@
}

// used for testing purposes
if os.Getenv("SHOW_RECENT_REPOS") == "true" {
showRecentRepos = true
}
forceRecentRepos := os.Getenv("SHOW_RECENT_REPOS") == "true"

app.Gui, err = gui.NewGui(common, config, gitVersion, updater, showRecentRepos, dirName, test)
app.Gui, err = gui.NewGui(common, config, gitVersion, updater, showRecentRepos, forceRecentRepos, dirName, test)
if err != nil {
return app, err
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/gui/controllers/helpers/repos_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ func (self *ReposHelper) getCurrentBranch(path string) string {
return self.c.Tr.BranchUnknown
}

func (self *ReposHelper) CreateRecentReposMenu() error {
// we'll show an empty panel if there are no recent repos
func (self *ReposHelper) CreateRecentReposMenu(force bool) error {
recentRepoPaths := []string{}
if len(self.c.GetAppState().RecentRepos) > 0 {
// we skip the first one because we're currently in it
recentRepoPaths = self.c.GetAppState().RecentRepos[1:]
}

// we'll skip the panel if there are no recent repos, and we are not forcing this via a test
if len(recentRepoPaths) == 0 && !force {
return nil
}

currentBranches := sync.Map{}

wg := sync.WaitGroup{}
Expand Down
6 changes: 3 additions & 3 deletions pkg/gui/controllers/status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (self *StatusController) GetKeybindings(opts types.KeybindingsOpts) []*type
},
{
Key: opts.GetKey(opts.Config.Status.RecentRepos),
Handler: self.c.Helpers().Repos.CreateRecentReposMenu,
Handler: func() error { return self.c.Helpers().Repos.CreateRecentReposMenu(true) },
Description: self.c.Tr.SwitchRepo,
DisplayOnScreen: true,
},
Expand Down Expand Up @@ -114,10 +114,10 @@ func (self *StatusController) onClick(opts gocui.ViewMouseBindingOpts) error {
return self.c.Helpers().MergeAndRebase.CreateRebaseOptionsMenu()
}
if cursorInSubstring(opts.X, upstreamStatus+" "+workingTreeStatus+" ", repoName) {
return self.c.Helpers().Repos.CreateRecentReposMenu()
return self.c.Helpers().Repos.CreateRecentReposMenu(false)
}
} else if cursorInSubstring(opts.X, upstreamStatus+" ", repoName) {
return self.c.Helpers().Repos.CreateRecentReposMenu()
return self.c.Helpers().Repos.CreateRecentReposMenu(false)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/dummies.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ func NewDummyUpdater() *updates.Updater {
// NewDummyGui creates a new dummy GUI for testing
func NewDummyGui() *Gui {
newAppConfig := config.NewDummyAppConfig()
dummyGui, _ := NewGui(common.NewDummyCommon(), newAppConfig, &git_commands.GitVersion{Major: 2, Minor: 0, Patch: 0}, NewDummyUpdater(), false, "", nil)
dummyGui, _ := NewGui(common.NewDummyCommon(), newAppConfig, &git_commands.GitVersion{Major: 2, Minor: 0, Patch: 0}, NewDummyUpdater(), false, false, "", nil)
return dummyGui
}
5 changes: 5 additions & 0 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ type Gui struct {
// recent repo with the recent repos popup showing
showRecentRepos bool

// Used for testing purposes
forceRecentRepos bool

Mutexes types.Mutexes

// when you enter into a submodule we'll append the superproject's path to this array
Expand Down Expand Up @@ -661,6 +664,7 @@ func NewGui(
gitVersion *git_commands.GitVersion,
updater *updates.Updater,
showRecentRepos bool,
forceRecentRepos bool,
initialDir string,
test integrationTypes.IntegrationTest,
) (*Gui, error) {
Expand All @@ -673,6 +677,7 @@ func NewGui(
viewBufferManagerMap: map[string]*tasks.ViewBufferManager{},
viewPtmxMap: map[string]*os.File{},
showRecentRepos: showRecentRepos,
forceRecentRepos: forceRecentRepos,
RepoPathStack: &utils.StringStack{},
RepoStateMap: map[Repo]*GuiRepoState{},
GuiLog: []string{},
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (gui *Gui) onInitialViewsCreation() error {
gui.c.SaveAppStateAndLogError()

if gui.showRecentRepos {
if err := gui.helpers.Repos.CreateRecentReposMenu(); err != nil {
if err := gui.helpers.Repos.CreateRecentReposMenu(gui.forceRecentRepos); err != nil {
return err
}
gui.showRecentRepos = false
Expand Down
37 changes: 35 additions & 2 deletions pkg/integration/tests/status/click_repo_name_to_open_repos_menu.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package status

import (
"path/filepath"

"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
Expand All @@ -10,9 +12,40 @@ var ClickRepoNameToOpenReposMenu = NewIntegrationTest(NewIntegrationTestArgs{
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {},
SetupRepo: func(shell *Shell) {
// Create another repo that we can switch to
shell.CloneIntoRemote("other_repo")
shell.CreateFileAndAdd("other_repo/README.md", "# other_repo")
shell.Commit("initial commit")

// Create a third repo
shell.CloneIntoRemote("third_repo")
shell.CreateFileAndAdd("third_repo/README.md", "# third_repo")
shell.Commit("initial commit")

// Add these repos to the recent repos list
otherRepoPath, err := filepath.Abs("other_repo")
if err != nil {
panic(err)
}
thirdRepoPath, err := filepath.Abs("third_repo")
if err != nil {
panic(err)
}

// Switch to the other repo and back to add it to the recent repos list
shell.RunCommand([]string{"cd", otherRepoPath})
shell.RunCommand([]string{"cd", "-"})
shell.RunCommand([]string{"cd", thirdRepoPath})
shell.RunCommand([]string{"cd", "-"})
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Status().Click(1, 0)
t.ExpectPopup().Menu().Title(Equals("Recent repositories"))
t.ExpectPopup().Menu().Title(Equals("Recent repositories")).
Lines(
Contains("other_repo").IsSelected(),
Contains("third_repo"),
Contains("Cancel"),
)
},
})
Loading