summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-17 14:10:07 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-30 18:35:22 +1000
commita06a5cadee1763d3360af698e7c2e1bbe915b3e0 (patch)
tree937913a0814e21c7688e808d62c5cc2983f791e3 /pkg/gui
parent3cd2d6fa5ce0a6e81e887d7f24988e76b2c987ba (diff)
Only show worktree in status panel if not the main worktree and worktrees are supported
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/controllers/helpers/refresh_helper.go8
-rw-r--r--pkg/gui/controllers/helpers/worktree_helper.go16
-rw-r--r--pkg/gui/presentation/status.go7
3 files changed, 26 insertions, 5 deletions
diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go
index 3edd801f9..f1e24eecc 100644
--- a/pkg/gui/controllers/helpers/refresh_helper.go
+++ b/pkg/gui/controllers/helpers/refresh_helper.go
@@ -632,8 +632,12 @@ func (self *RefreshHelper) refreshStatus() {
}
workingTreeState := self.c.Git().Status.WorkingTreeState()
- mainWorktreeName := self.worktreeHelper.GetMainWorktreeName()
- status := presentation.FormatStatus(currentBranch, mainWorktreeName, workingTreeState, self.c.Tr)
+ var linkedWorktreeName string
+ if self.c.Git().Version.SupportsWorktrees() {
+ linkedWorktreeName = self.worktreeHelper.GetLinkedWorktreeName()
+ }
+
+ status := presentation.FormatStatus(currentBranch, linkedWorktreeName, workingTreeState, self.c.Tr)
self.c.SetViewContent(self.c.Views().Status, status)
}
diff --git a/pkg/gui/controllers/helpers/worktree_helper.go b/pkg/gui/controllers/helpers/worktree_helper.go
index 642378ace..db59b1afe 100644
--- a/pkg/gui/controllers/helpers/worktree_helper.go
+++ b/pkg/gui/controllers/helpers/worktree_helper.go
@@ -45,6 +45,22 @@ func (self *WorktreeHelper) GetMainWorktreeName() string {
return ""
}
+// If we're on the main worktree, we return an empty string
+func (self *WorktreeHelper) GetLinkedWorktreeName() string {
+ worktrees := self.c.Model().Worktrees
+ if len(worktrees) == 0 {
+ return ""
+ }
+
+ // worktrees always have the current worktree on top
+ currentWorktree := worktrees[0]
+ if currentWorktree.Main() {
+ return ""
+ }
+
+ return currentWorktree.Name()
+}
+
func (self *WorktreeHelper) IsCurrentWorktree(w *models.Worktree) bool {
pwd, err := os.Getwd()
if err != nil {
diff --git a/pkg/gui/presentation/status.go b/pkg/gui/presentation/status.go
index e0288406f..650303d44 100644
--- a/pkg/gui/presentation/status.go
+++ b/pkg/gui/presentation/status.go
@@ -10,7 +10,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils"
)
-func FormatStatus(currentBranch *models.Branch, mainWorktreeName string, workingTreeState enums.RebaseMode, tr *i18n.TranslationSet) string {
+func FormatStatus(currentBranch *models.Branch, linkedWorktreeName string, workingTreeState enums.RebaseMode, tr *i18n.TranslationSet) string {
status := ""
if currentBranch.IsRealBranch() {
@@ -23,8 +23,9 @@ func FormatStatus(currentBranch *models.Branch, mainWorktreeName string, working
name := GetBranchTextStyle(currentBranch.Name).Sprint(currentBranch.Name)
repoName := utils.GetCurrentRepoName()
- if repoName != mainWorktreeName {
- repoName = fmt.Sprintf("%s(%s)", mainWorktreeName, style.FgCyan.Sprint(repoName))
+ // If the user is in a linked worktree (i.e. not the main worktree) we'll display that
+ if linkedWorktreeName != "" {
+ repoName = fmt.Sprintf("%s(%s)", repoName, style.FgCyan.Sprint(linkedWorktreeName))
}
status += fmt.Sprintf("%s → %s ", repoName, name)