diff --git a/pkg/commands/git_commands/branch_loader.go b/pkg/commands/git_commands/branch_loader.go index 4b88611eb..ab14d65d1 100644 --- a/pkg/commands/git_commands/branch_loader.go +++ b/pkg/commands/git_commands/branch_loader.go @@ -144,14 +144,7 @@ func (self *BranchLoader) obtainBranches() []*models.Branch { return nil, false } - branchDir := split[6] - if len(branchDir) > 0 && branchDir != currentDir { - // Ignore line because it is a branch checked out in a different worktree - // Branches which are not checked out will not have a path, so we should not ignore them. - return nil, false - } - - return obtainBranch(split), true + return obtainBranch(split, currentDir), true }) } @@ -183,25 +176,28 @@ var branchFields = []string{ } // Obtain branch information from parsed line output of getRawBranches() -func obtainBranch(split []string) *models.Branch { +func obtainBranch(split []string, currentDir string) *models.Branch { headMarker := split[0] fullName := split[1] upstreamName := split[2] track := split[3] subject := split[4] commitHash := split[5] + branchDir := split[6] + checkedOutByOtherWorktree := len(branchDir) > 0 && branchDir != currentDir name := strings.TrimPrefix(fullName, "heads/") pushables, pullables, gone := parseUpstreamInfo(upstreamName, track) return &models.Branch{ - Name: name, - Pushables: pushables, - Pullables: pullables, - UpstreamGone: gone, - Head: headMarker == "*", - Subject: subject, - CommitHash: commitHash, + Name: name, + Pushables: pushables, + Pullables: pullables, + UpstreamGone: gone, + Head: headMarker == "*", + Subject: subject, + CommitHash: commitHash, + CheckedOutByOtherWorktree: checkedOutByOtherWorktree, } } diff --git a/pkg/commands/git_commands/worktree_loader.go b/pkg/commands/git_commands/worktree_loader.go index 4b65caee1..3633d31e3 100644 --- a/pkg/commands/git_commands/worktree_loader.go +++ b/pkg/commands/git_commands/worktree_loader.go @@ -44,8 +44,8 @@ func (self *WorktreeLoader) GetWorktrees() ([]*models.Worktree, error) { if strings.HasPrefix(splitLine, "worktree ") { path := strings.SplitN(splitLine, " ", 2)[1] currentWorktree = &models.Worktree{ - Id: len(worktrees), - Path: path, + IsMain: len(worktrees) == 0, + Path: path, } } else if strings.HasPrefix(splitLine, "branch ") { branch := strings.SplitN(splitLine, " ", 2)[1] diff --git a/pkg/commands/models/branch.go b/pkg/commands/models/branch.go index b4dcc0a79..d3c9eb6dc 100644 --- a/pkg/commands/models/branch.go +++ b/pkg/commands/models/branch.go @@ -26,6 +26,8 @@ type Branch struct { Subject string // commit hash CommitHash string + + CheckedOutByOtherWorktree bool } func (b *Branch) FullRefName() string { diff --git a/pkg/commands/models/worktree.go b/pkg/commands/models/worktree.go index 3b9cf64b3..726b59899 100644 --- a/pkg/commands/models/worktree.go +++ b/pkg/commands/models/worktree.go @@ -6,7 +6,7 @@ import ( // Worktree : A git worktree type Worktree struct { - Id int + IsMain bool Path string Branch string } @@ -28,5 +28,5 @@ func (w *Worktree) Name() string { } func (w *Worktree) Main() bool { - return w.Id == 0 + return w.IsMain }