mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
Update worktree model
This commit is contained in:
@ -144,14 +144,7 @@ func (self *BranchLoader) obtainBranches() []*models.Branch {
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
branchDir := split[6]
|
return obtainBranch(split, currentDir), true
|
||||||
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
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,13 +176,15 @@ var branchFields = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtain branch information from parsed line output of getRawBranches()
|
// 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]
|
headMarker := split[0]
|
||||||
fullName := split[1]
|
fullName := split[1]
|
||||||
upstreamName := split[2]
|
upstreamName := split[2]
|
||||||
track := split[3]
|
track := split[3]
|
||||||
subject := split[4]
|
subject := split[4]
|
||||||
commitHash := split[5]
|
commitHash := split[5]
|
||||||
|
branchDir := split[6]
|
||||||
|
checkedOutByOtherWorktree := len(branchDir) > 0 && branchDir != currentDir
|
||||||
|
|
||||||
name := strings.TrimPrefix(fullName, "heads/")
|
name := strings.TrimPrefix(fullName, "heads/")
|
||||||
pushables, pullables, gone := parseUpstreamInfo(upstreamName, track)
|
pushables, pullables, gone := parseUpstreamInfo(upstreamName, track)
|
||||||
@ -202,6 +197,7 @@ func obtainBranch(split []string) *models.Branch {
|
|||||||
Head: headMarker == "*",
|
Head: headMarker == "*",
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
CommitHash: commitHash,
|
CommitHash: commitHash,
|
||||||
|
CheckedOutByOtherWorktree: checkedOutByOtherWorktree,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ func (self *WorktreeLoader) GetWorktrees() ([]*models.Worktree, error) {
|
|||||||
if strings.HasPrefix(splitLine, "worktree ") {
|
if strings.HasPrefix(splitLine, "worktree ") {
|
||||||
path := strings.SplitN(splitLine, " ", 2)[1]
|
path := strings.SplitN(splitLine, " ", 2)[1]
|
||||||
currentWorktree = &models.Worktree{
|
currentWorktree = &models.Worktree{
|
||||||
Id: len(worktrees),
|
IsMain: len(worktrees) == 0,
|
||||||
Path: path,
|
Path: path,
|
||||||
}
|
}
|
||||||
} else if strings.HasPrefix(splitLine, "branch ") {
|
} else if strings.HasPrefix(splitLine, "branch ") {
|
||||||
|
@ -26,6 +26,8 @@ type Branch struct {
|
|||||||
Subject string
|
Subject string
|
||||||
// commit hash
|
// commit hash
|
||||||
CommitHash string
|
CommitHash string
|
||||||
|
|
||||||
|
CheckedOutByOtherWorktree bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Branch) FullRefName() string {
|
func (b *Branch) FullRefName() string {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
// Worktree : A git worktree
|
// Worktree : A git worktree
|
||||||
type Worktree struct {
|
type Worktree struct {
|
||||||
Id int
|
IsMain bool
|
||||||
Path string
|
Path string
|
||||||
Branch string
|
Branch string
|
||||||
}
|
}
|
||||||
@ -28,5 +28,5 @@ func (w *Worktree) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Worktree) Main() bool {
|
func (w *Worktree) Main() bool {
|
||||||
return w.Id == 0
|
return w.IsMain
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user