diff options
Diffstat (limited to 'pkg/gui/controllers/helpers/worktree_helper.go')
-rw-r--r-- | pkg/gui/controllers/helpers/worktree_helper.go | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/pkg/gui/controllers/helpers/worktree_helper.go b/pkg/gui/controllers/helpers/worktree_helper.go index a05d469ce..888838370 100644 --- a/pkg/gui/controllers/helpers/worktree_helper.go +++ b/pkg/gui/controllers/helpers/worktree_helper.go @@ -18,12 +18,14 @@ type IWorktreeHelper interface { } type WorktreeHelper struct { - c *HelperCommon + c *HelperCommon + reposHelper *ReposHelper } -func NewWorktreeHelper(c *HelperCommon) *WorktreeHelper { +func NewWorktreeHelper(c *HelperCommon, reposHelper *ReposHelper) *WorktreeHelper { return &WorktreeHelper{ - c: c, + c: c, + reposHelper: reposHelper, } } @@ -75,3 +77,17 @@ func (self *WorktreeHelper) NewWorktree() error { }, }) } + +func (self *WorktreeHelper) Switch(worktree *models.Worktree) error { + if self.c.Git().Worktree.IsCurrentWorktree(worktree) { + return self.c.ErrorMsg(self.c.Tr.AlreadyInWorktree) + } + + self.c.LogAction(self.c.Tr.SwitchToWorktree) + + // if we were in a submodule, we want to forget about that stack of repos + // so that hitting escape in the new repo does nothing + self.c.State().GetRepoPathStack().Clear() + + return self.reposHelper.DispatchSwitchTo(worktree.Path, true, self.c.Tr.ErrWorktreeMovedOrDeleted) +} |