diff --git a/pkg/commands/git_commands/worktree_loader.go b/pkg/commands/git_commands/worktree_loader.go index 06a22d2b5..d81b23f4b 100644 --- a/pkg/commands/git_commands/worktree_loader.go +++ b/pkg/commands/git_commands/worktree_loader.go @@ -87,7 +87,7 @@ func (self *WorktreeLoader) GetWorktrees() ([]*models.Worktree, error) { })) for index, worktree := range worktrees { - worktree.NameField = names[index] + worktree.Name = names[index] } // move current worktree to the top diff --git a/pkg/commands/models/worktree.go b/pkg/commands/models/worktree.go index 662d137dc..58d4bf790 100644 --- a/pkg/commands/models/worktree.go +++ b/pkg/commands/models/worktree.go @@ -21,11 +21,11 @@ type Worktree struct { Branch string // based on the path, but uniquified. Not the same name that git uses in the worktrees/ folder (no good reason for this, // I just prefer my naming convention better) - NameField string + Name string } func (w *Worktree) RefName() string { - return w.Name() + return w.Name } func (w *Worktree) ID() string { @@ -35,19 +35,3 @@ func (w *Worktree) ID() string { func (w *Worktree) Description() string { return w.RefName() } - -func (w *Worktree) Name() string { - return w.NameField -} - -func (w *Worktree) Main() bool { - return w.IsMain -} - -func (w *Worktree) Current() bool { - return w.IsCurrent -} - -func (w *Worktree) PathMissing() bool { - return w.IsPathMissing -} diff --git a/pkg/gui/context/worktrees_context.go b/pkg/gui/context/worktrees_context.go index 224a233e1..055467b74 100644 --- a/pkg/gui/context/worktrees_context.go +++ b/pkg/gui/context/worktrees_context.go @@ -17,7 +17,7 @@ func NewWorktreesContext(c *ContextCommon) *WorktreesContext { viewModel := NewFilteredListViewModel( func() []*models.Worktree { return c.Model().Worktrees }, func(Worktree *models.Worktree) []string { - return []string{Worktree.Name()} + return []string{Worktree.Name} }, ) diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index b3c3fdcdc..f85bd49fa 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -203,7 +203,7 @@ func (self *BranchesController) press(selectedBranch *models.Branch) error { } worktreeForRef, ok := self.worktreeForBranch(selectedBranch) - if ok && !worktreeForRef.Current() { + if ok && !worktreeForRef.IsCurrent { return self.promptToCheckoutWorktree(worktreeForRef) } @@ -218,7 +218,7 @@ func (self *BranchesController) worktreeForBranch(branch *models.Branch) (*model func (self *BranchesController) promptToCheckoutWorktree(worktree *models.Worktree) error { return self.c.Confirm(types.ConfirmOpts{ Title: "Switch to worktree", - Prompt: fmt.Sprintf("This branch is checked out by worktree %s. Do you want to switch to that worktree?", worktree.Name()), + Prompt: fmt.Sprintf("This branch is checked out by worktree %s. Do you want to switch to that worktree?", worktree.Name), HandleConfirm: func() error { return self.c.Helpers().Worktree.Switch(worktree, context.LOCAL_BRANCHES_CONTEXT_KEY) }, @@ -337,7 +337,7 @@ func (self *BranchesController) promptWorktreeBranchDelete(selectedBranch *model } return self.c.Menu(types.CreateMenuOptions{ - Title: fmt.Sprintf("Branch %s is checked out by worktree %s", selectedBranch.Name, worktree.Name()), + Title: fmt.Sprintf("Branch %s is checked out by worktree %s", selectedBranch.Name, worktree.Name), Items: []*types.MenuItem{ { Label: "Switch to worktree", @@ -432,7 +432,7 @@ func (self *BranchesController) fastForward(branch *models.Branch) error { worktreeGitDir := "" // if it is the current worktree path, no need to specify the path - if !worktree.Current() { + if !worktree.IsCurrent { worktreeGitDir = worktree.GitDir } diff --git a/pkg/gui/controllers/helpers/worktree_helper.go b/pkg/gui/controllers/helpers/worktree_helper.go index 0a0a505ac..8126f3d8e 100644 --- a/pkg/gui/controllers/helpers/worktree_helper.go +++ b/pkg/gui/controllers/helpers/worktree_helper.go @@ -34,8 +34,8 @@ func NewWorktreeHelper(c *HelperCommon, reposHelper *ReposHelper, refsHelper *Re func (self *WorktreeHelper) GetMainWorktreeName() string { for _, worktree := range self.c.Model().Worktrees { - if worktree.Main() { - return worktree.Name() + if worktree.IsMain { + return worktree.Name } } @@ -51,11 +51,11 @@ func (self *WorktreeHelper) GetLinkedWorktreeName() string { // worktrees always have the current worktree on top currentWorktree := worktrees[0] - if currentWorktree.Main() { + if currentWorktree.IsMain { return "" } - return currentWorktree.Name() + return currentWorktree.Name } func (self *WorktreeHelper) NewWorktree() error { @@ -153,7 +153,7 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo } func (self *WorktreeHelper) Switch(worktree *models.Worktree, contextKey types.ContextKey) error { - if worktree.Current() { + if worktree.IsCurrent { return self.c.ErrorMsg(self.c.Tr.AlreadyInWorktree) } @@ -173,7 +173,7 @@ func (self *WorktreeHelper) Remove(worktree *models.Worktree, force bool) error message := utils.ResolvePlaceholderString( templateStr, map[string]string{ - "worktreeName": worktree.Name(), + "worktreeName": worktree.Name, }, ) diff --git a/pkg/gui/controllers/worktrees_controller.go b/pkg/gui/controllers/worktrees_controller.go index 78d53914d..c76c3b1de 100644 --- a/pkg/gui/controllers/worktrees_controller.go +++ b/pkg/gui/controllers/worktrees_controller.go @@ -67,18 +67,18 @@ func (self *WorktreesController) GetOnRenderToMain() func() error { task = types.NewRenderStringTask(self.c.Tr.NoWorktreesThisRepo) } else { main := "" - if worktree.Main() { + if worktree.IsMain { main = style.FgDefault.Sprintf(" %s", self.c.Tr.MainWorktree) } missing := "" - if worktree.PathMissing() { + if worktree.IsPathMissing { missing = style.FgRed.Sprintf(" %s", self.c.Tr.MissingWorktree) } var builder strings.Builder w := tabwriter.NewWriter(&builder, 0, 0, 2, ' ', 0) - _, _ = fmt.Fprintf(w, "%s:\t%s%s\n", self.c.Tr.Name, style.FgGreen.Sprint(worktree.Name()), main) + _, _ = fmt.Fprintf(w, "%s:\t%s%s\n", self.c.Tr.Name, style.FgGreen.Sprint(worktree.Name), main) _, _ = fmt.Fprintf(w, "%s:\t%s\n", self.c.Tr.Branch, style.FgYellow.Sprint(worktree.Branch)) _, _ = fmt.Fprintf(w, "%s:\t%s%s\n", self.c.Tr.Path, style.FgCyan.Sprint(worktree.Path), missing) _ = w.Flush() @@ -101,11 +101,11 @@ func (self *WorktreesController) add() error { } func (self *WorktreesController) remove(worktree *models.Worktree) error { - if worktree.Main() { + if worktree.IsMain { return self.c.ErrorMsg(self.c.Tr.CantDeleteMainWorktree) } - if worktree.Current() { + if worktree.IsCurrent { return self.c.ErrorMsg(self.c.Tr.CantDeleteCurrentWorktree) } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 42a29d500..8db98238c 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -374,7 +374,7 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context { SearchState: types.NewSearchState(), } - gui.RepoStateMap[Repo(currentDir)] = gui.State + gui.RepoStateMap[Repo(worktreePath)] = gui.State return initialContext(contextTree, startArgs) } diff --git a/pkg/gui/presentation/worktrees.go b/pkg/gui/presentation/worktrees.go index c16871c69..d2796af83 100644 --- a/pkg/gui/presentation/worktrees.go +++ b/pkg/gui/presentation/worktrees.go @@ -22,13 +22,13 @@ func GetWorktreeDisplayString(tr *i18n.TranslationSet, worktree *models.Worktree current := "" currentColor := style.FgCyan - if worktree.Current() { + if worktree.IsCurrent { current = " *" currentColor = style.FgGreen } icon := icons.IconForWorktree(false) - if worktree.PathMissing() { + if worktree.IsPathMissing { textStyle = style.FgRed icon = icons.IconForWorktree(true) } @@ -39,11 +39,11 @@ func GetWorktreeDisplayString(tr *i18n.TranslationSet, worktree *models.Worktree res = append(res, textStyle.Sprint(icon)) } - name := worktree.Name() - if worktree.Main() { + name := worktree.Name + if worktree.IsMain { name += " " + tr.MainWorktree } - if worktree.PathMissing() && !icons.IsIconEnabled() { + if worktree.IsPathMissing && !icons.IsIconEnabled() { name += " " + tr.MissingWorktree } res = append(res, textStyle.Sprint(name)) diff --git a/pkg/integration/tests/ui/switch_tab_from_menu.go b/pkg/integration/tests/ui/switch_tab_from_menu.go index e74d76017..61bd991ab 100644 --- a/pkg/integration/tests/ui/switch_tab_from_menu.go +++ b/pkg/integration/tests/ui/switch_tab_from_menu.go @@ -17,11 +17,9 @@ var SwitchTabFromMenu = NewIntegrationTest(NewIntegrationTestArgs{ Press(keys.Universal.OptionMenuAlt1) t.ExpectPopup().Menu().Title(Equals("Keybindings")). - // Looping back around to the end to side-step the worktrees view which is - // only present on recent git versions - Select(Contains("Previous tab")). + Select(Contains("Next tab")). Confirm() - t.Views().Submodules().IsFocused() + t.Views().Worktrees().IsFocused() }, })