diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-09-07 09:41:15 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2018-09-07 09:41:15 +1000 |
commit | ca715c5b23fdc20ad9b3dd983814ab9225c5fdbc (patch) | |
tree | 3a02a5f769524beb3add39e584ad0712c5acd822 | |
parent | ba7e6add8690de21239cd0f37ee52a7c50236518 (diff) |
support switching to recent repo
-rw-r--r-- | pkg/app/app.go | 4 | ||||
-rw-r--r-- | pkg/gui/gui.go | 43 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 1 |
3 files changed, 46 insertions, 2 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go index b03ec5b42..65acd2e35 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -77,11 +77,11 @@ func Setup(config config.AppConfigurer) (*App, error) { app.Tr = i18n.NewLocalizer(app.Log) - app.GitCommand, err = commands.NewGitCommand(app.Log, app.OSCommand, app.Tr) + app.Updater, err = updates.NewUpdater(app.Log, config, app.OSCommand, app.Tr) if err != nil { return app, err } - app.Updater, err = updates.NewUpdater(app.Log, config, app.OSCommand, app.Tr) + app.GitCommand, err = commands.NewGitCommand(app.Log, app.OSCommand, app.Tr) if err != nil { return app, err } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 413e48202..e986ed294 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -33,6 +33,7 @@ var OverlappingEdges = false type SentinelErrors struct { ErrSubProcess error ErrNoFiles error + ErrSwitchRepo error } // GenerateSentinelErrors makes the sentinel errors for the gui. We're defining it here @@ -49,6 +50,7 @@ func (gui *Gui) GenerateSentinelErrors() { gui.Errors = SentinelErrors{ ErrSubProcess: errors.New(gui.Tr.SLocalize("RunningSubprocess")), ErrNoFiles: errors.New(gui.Tr.SLocalize("NoChangedFiles")), + ErrSwitchRepo: errors.New("switching repo"), } } @@ -292,6 +294,10 @@ func (gui *Gui) layout(g *gocui.Gui) error { // these are only called once (it's a place to put all the things you want // to happen on startup after the screen is first rendered) gui.Updater.CheckForNewUpdate(gui.onBackgroundUpdateCheckFinish, false) + if err := gui.updateRecentRepoList(); err != nil { + return err + } + gui.handleFileSelect(g, filesView) gui.refreshFiles(g) gui.refreshBranches(g) @@ -311,6 +317,41 @@ func (gui *Gui) layout(g *gocui.Gui) error { return gui.resizeCurrentPopupPanel(g) } +func newRecentReposList(recentRepos []string, currentRepo string) []string { + newRepos := []string{currentRepo} + for _, repo := range recentRepos { + if repo != currentRepo { + newRepos = append(newRepos, repo) + } + } + return newRepos +} + +// updateRecentRepoList registers the fact that we opened lazygit in this repo, +// so that we can open the same repo via a 'recent repos' menu +func (gui *Gui) updateRecentRepoList() error { + recentRepos := gui.Config.GetAppState().RecentRepos + currentRepo, err := os.Getwd() + if err != nil { + return err + } + gui.Config.GetAppState().RecentRepos = newRecentReposList(recentRepos, currentRepo) + return gui.Config.SaveAppState() +} + +func (gui *Gui) handleSwitchRepo(g *gocui.Gui, v *gocui.View) error { + newRepo := gui.Config.GetAppState().RecentRepos[1] + if err := os.Chdir(newRepo); err != nil { + return err + } + newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr) + if err != nil { + return err + } + gui.GitCommand = newGitCommand + return gui.Errors.ErrSwitchRepo +} + func (gui *Gui) promptAnonymousReporting() error { return gui.createConfirmationPanel(gui.g, nil, gui.Tr.SLocalize("AnonymousReportingTitle"), gui.Tr.SLocalize("AnonymousReportingPrompt"), func(g *gocui.Gui, v *gocui.View) error { return gui.Config.WriteToUserConfig("reporting", "on") @@ -391,6 +432,8 @@ func (gui *Gui) RunWithSubprocesses() { if err := gui.Run(); err != nil { if err == gocui.ErrQuit { break + } else if err == gui.Errors.ErrSwitchRepo { + continue } else if err == gui.Errors.ErrSubProcess { gui.SubProcess.Stdin = os.Stdin gui.SubProcess.Stdout = os.Stdout diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 494381749..287619b8b 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -27,6 +27,7 @@ func (gui *Gui) keybindings(g *gocui.Gui) error { {ViewName: "status", Key: 'e', Modifier: gocui.ModNone, Handler: gui.handleEditConfig}, {ViewName: "status", Key: 'o', Modifier: gocui.ModNone, Handler: gui.handleOpenConfig}, {ViewName: "status", Key: 'u', Modifier: gocui.ModNone, Handler: gui.handleCheckForUpdate}, + {ViewName: "status", Key: 's', Modifier: gocui.ModNone, Handler: gui.handleSwitchRepo}, {ViewName: "files", Key: 'c', Modifier: gocui.ModNone, Handler: gui.handleCommitPress}, {ViewName: "files", Key: 'C', Modifier: gocui.ModNone, Handler: gui.handleCommitEditorPress}, {ViewName: "files", Key: gocui.KeySpace, Modifier: gocui.ModNone, Handler: gui.handleFilePress}, |