diff options
author | David Roman <d@vidroman.dev> | 2022-03-15 14:12:26 +0100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-17 19:01:28 +1100 |
commit | b8fc829f860a1d6157ebe49f63e1b16db19c950c (patch) | |
tree | b2248bc581aabe4bb026b44a9027b8e13a676ddb /pkg | |
parent | 950bb5090dfa8e553b6a066b02547fce427c1acd (diff) |
Record current directory on switch
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/app/app.go | 7 | ||||
-rw-r--r-- | pkg/gui/dummies.go | 2 | ||||
-rw-r--r-- | pkg/gui/gui.go | 11 | ||||
-rw-r--r-- | pkg/gui/quitting.go | 10 | ||||
-rw-r--r-- | pkg/gui/recent_repos_panel.go | 4 |
5 files changed, 27 insertions, 7 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go index cb9aaafea..f38dcb75e 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -128,6 +128,11 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) { return app, err } + dirName, err := os.Getwd() + if err != nil { + return app, err + } + showRecentRepos, err := app.setupRepo() if err != nil { return app, err @@ -135,7 +140,7 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) { gitConfig := git_config.NewStdCachedGitConfig(app.Log) - app.Gui, err = gui.NewGui(app.Common, config, gitConfig, app.Updater, filterPath, showRecentRepos) + app.Gui, err = gui.NewGui(app.Common, config, gitConfig, app.Updater, filterPath, showRecentRepos, dirName) if err != nil { return app, err } diff --git a/pkg/gui/dummies.go b/pkg/gui/dummies.go index 587460ccd..f740b4881 100644 --- a/pkg/gui/dummies.go +++ b/pkg/gui/dummies.go @@ -17,6 +17,6 @@ func NewDummyUpdater() *updates.Updater { func NewDummyGui() *Gui { newAppConfig := config.NewDummyAppConfig() - dummyGui, _ := NewGui(utils.NewDummyCommon(), newAppConfig, git_config.NewFakeGitConfig(nil), NewDummyUpdater(), "", false) + dummyGui, _ := NewGui(utils.NewDummyCommon(), newAppConfig, git_config.NewFakeGitConfig(nil), NewDummyUpdater(), "", false, "") return dummyGui } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index c6dbf1f65..416a2faf7 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -124,6 +124,8 @@ type Gui struct { PopupHandler PopupHandler IsNewRepo bool + + InitialRepoDir string } type listPanelState struct { @@ -447,6 +449,7 @@ func NewGui( updater *updates.Updater, filterPath string, showRecentRepos bool, + initialRepoDir string, ) (*Gui, error) { gui := &Gui{ Common: cmn, @@ -464,6 +467,8 @@ func NewGui( // but now we do it via state. So we need to still support the config for the // sake of backwards compatibility. We're making use of short circuiting here ShowExtrasWindow: cmn.UserConfig.Gui.ShowCommandLog && !config.GetAppState().HideCommandLog, + + InitialRepoDir: initialRepoDir, } guiIO := oscommands.NewGuiIO( @@ -590,7 +595,11 @@ func (gui *Gui) RunAndHandleError() error { switch err { case gocui.ErrQuit: - if !gui.State.RetainOriginalDir { + if gui.State.RetainOriginalDir { + if err := gui.recordDirectory(gui.InitialRepoDir); err != nil { + return err + } + } else { if err := gui.recordCurrentDirectory(); err != nil { return err } diff --git a/pkg/gui/quitting.go b/pkg/gui/quitting.go index c3fd2ce2f..eae68ea5f 100644 --- a/pkg/gui/quitting.go +++ b/pkg/gui/quitting.go @@ -11,16 +11,18 @@ import ( // shell can then change to that directory. That means you don't get kicked // back to the directory that you started with. func (gui *Gui) recordCurrentDirectory() error { - if os.Getenv("LAZYGIT_NEW_DIR_FILE") == "" { - return nil - } - // determine current directory, set it in LAZYGIT_NEW_DIR_FILE dirName, err := os.Getwd() if err != nil { return err } + return gui.recordDirectory(dirName) +} +func (gui *Gui) recordDirectory(dirName string) error { + if os.Getenv("LAZYGIT_NEW_DIR_FILE") == "" { + return nil + } return gui.OSCommand.CreateFileWithContent(os.Getenv("LAZYGIT_NEW_DIR_FILE"), dirName) } diff --git a/pkg/gui/recent_repos_panel.go b/pkg/gui/recent_repos_panel.go index 7bf6b068c..01b9a00d3 100644 --- a/pkg/gui/recent_repos_panel.go +++ b/pkg/gui/recent_repos_panel.go @@ -84,6 +84,10 @@ func (gui *Gui) dispatchSwitchToRepo(path string, reuse bool) error { gui.Mutexes.RefreshingFilesMutex.Lock() defer gui.Mutexes.RefreshingFilesMutex.Unlock() + if err := gui.recordCurrentDirectory(); err != nil { + return err + } + gui.resetState("", reuse) return nil |