summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-17 19:31:26 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-30 18:35:23 +1000
commitb5ff55e538dded74e163a90bdf9793939eb733b7 (patch)
treeb3c475d6a08684cca8a71e0ad372be216558ed9f /pkg/gui
parent81a91332613e9aff0e4dbae419f9127e5debeec6 (diff)
Show loader when switching worktrees
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/controllers/helpers/repos_helper.go55
1 files changed, 29 insertions, 26 deletions
diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go
index 95bd7e94a..5ea42222d 100644
--- a/pkg/gui/controllers/helpers/repos_helper.go
+++ b/pkg/gui/controllers/helpers/repos_helper.go
@@ -8,6 +8,7 @@ import (
"sync"
"github.com/jesseduffield/generics/slices"
+ "github.com/jesseduffield/gocui"
appTypes "github.com/jesseduffield/lazygit/pkg/app/types"
"github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
@@ -143,40 +144,42 @@ func (self *ReposHelper) DispatchSwitchToRepo(path string, reuse bool, contextKe
}
func (self *ReposHelper) DispatchSwitchTo(path string, reuse bool, errMsg string, contextKey types.ContextKey) error {
- env.UnsetGitDirEnvs()
- originalPath, err := os.Getwd()
- if err != nil {
- return nil
- }
+ return self.c.WithWaitingStatus(self.c.Tr.Switching, func(gocui.Task) error {
+ env.UnsetGitDirEnvs()
+ originalPath, err := os.Getwd()
+ if err != nil {
+ return nil
+ }
- self.c.LogCommand(fmt.Sprintf("Changing directory to %s", path), false)
+ self.c.LogCommand(fmt.Sprintf("Changing directory to %s", path), false)
- if err := os.Chdir(path); err != nil {
- if os.IsNotExist(err) {
- return self.c.ErrorMsg(errMsg)
+ if err := os.Chdir(path); err != nil {
+ if os.IsNotExist(err) {
+ return self.c.ErrorMsg(errMsg)
+ }
+ return err
}
- return err
- }
- if err := commands.VerifyInGitRepo(self.c.OS()); err != nil {
- if err := os.Chdir(originalPath); err != nil {
+ if err := commands.VerifyInGitRepo(self.c.OS()); err != nil {
+ if err := os.Chdir(originalPath); err != nil {
+ return err
+ }
+
return err
}
- return err
- }
-
- if err := self.recordDirectoryHelper.RecordCurrentDirectory(); err != nil {
- return err
- }
+ if err := self.recordDirectoryHelper.RecordCurrentDirectory(); err != nil {
+ return err
+ }
- // these two mutexes are used by our background goroutines (triggered via `self.goEvery`. We don't want to
- // switch to a repo while one of these goroutines is in the process of updating something
- self.c.Mutexes().SyncMutex.Lock()
- defer self.c.Mutexes().SyncMutex.Unlock()
+ // these two mutexes are used by our background goroutines (triggered via `self.goEvery`. We don't want to
+ // switch to a repo while one of these goroutines is in the process of updating something
+ self.c.Mutexes().SyncMutex.Lock()
+ defer self.c.Mutexes().SyncMutex.Unlock()
- self.c.Mutexes().RefreshingFilesMutex.Lock()
- defer self.c.Mutexes().RefreshingFilesMutex.Unlock()
+ self.c.Mutexes().RefreshingFilesMutex.Lock()
+ defer self.c.Mutexes().RefreshingFilesMutex.Unlock()
- return self.onNewRepo(appTypes.StartArgs{}, reuse, contextKey)
+ return self.onNewRepo(appTypes.StartArgs{}, reuse, contextKey)
+ })
}