diff --git a/pkg/gui/controllers/worktrees_controller.go b/pkg/gui/controllers/worktrees_controller.go index 042d96898..0c515b564 100644 --- a/pkg/gui/controllers/worktrees_controller.go +++ b/pkg/gui/controllers/worktrees_controller.go @@ -140,6 +140,10 @@ func (self *WorktreesController) GetOnClick() func() error { } func (self *WorktreesController) enter(worktree *models.Worktree) error { + if self.c.Git().Worktree.IsCurrentWorktree(worktree) { + return self.c.ErrorMsg(self.c.Tr.AlreadyInWorktree) + } + // 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() diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 17ccacab1..cff0e367b 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -550,6 +550,7 @@ type TranslationSet struct { DeleteWorktreePrompt string ForceDeleteWorktreePrompt string CantDeleteCurrentWorktree string + AlreadyInWorktree string CantDeleteMainWorktree string NoWorktreesThisRepo string MissingWorktree string @@ -1268,6 +1269,7 @@ func EnglishTranslationSet() TranslationSet { DeleteWorktreePrompt: "Are you sure you want to delete worktree '{{.worktreeName}}'?", ForceDeleteWorktreePrompt: "'{{.worktreeName}}' is not fully merged. Are you sure you want to delete it?", CantDeleteCurrentWorktree: "You cannot delete the current worktree!", + AlreadyInWorktree: "You are already in the selected worktree", CantDeleteMainWorktree: "You cannot delete the main worktree!", NoWorktreesThisRepo: "No worktrees", MissingWorktree: "(missing)",