mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-23 22:50:41 +02:00
Hide worktrees in the worktree panel if they point at a non-existing filesystem location.
Remove unneeded check when filtering out branches from non-current worktrees from the branch panel. Add link icon for linked worktrees
This commit is contained in:
parent
60872c91e6
commit
9a79154d05
@ -144,8 +144,10 @@ func (self *BranchLoader) obtainBranches() []*models.Branch {
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(split[6]) > 0 && split[6] != currentDir {
|
branchDir := split[6]
|
||||||
|
if len(branchDir) > 0 && branchDir != currentDir {
|
||||||
// Ignore line because it is a branch checked out in a different worktree
|
// 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 nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package git_commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -43,20 +45,26 @@ func (self *WorktreeLoader) GetWorktrees() ([]*models.Worktree, error) {
|
|||||||
var currentWorktree *models.Worktree
|
var currentWorktree *models.Worktree
|
||||||
for _, splitLine := range splitLines {
|
for _, splitLine := range splitLines {
|
||||||
if len(splitLine) == 0 && currentWorktree != nil {
|
if len(splitLine) == 0 && currentWorktree != nil {
|
||||||
|
|
||||||
worktrees = append(worktrees, currentWorktree)
|
worktrees = append(worktrees, currentWorktree)
|
||||||
currentWorktree = nil
|
currentWorktree = nil
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(splitLine, "worktree ") {
|
if strings.HasPrefix(splitLine, "worktree ") {
|
||||||
|
path := strings.SplitN(splitLine, " ", 2)[1]
|
||||||
|
|
||||||
|
if _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) {
|
||||||
|
// Ignore because the worktree is points to a non-existing filesystem location
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
main := false
|
main := false
|
||||||
name := "main"
|
name := "main"
|
||||||
path := strings.SplitN(splitLine, " ", 2)[1]
|
|
||||||
if len(worktrees) == 0 {
|
if len(worktrees) == 0 {
|
||||||
main = true
|
main = true
|
||||||
} else {
|
} else {
|
||||||
name = filepath.Base(path)
|
name = filepath.Base(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentWorktree = &models.Worktree{
|
currentWorktree = &models.Worktree{
|
||||||
Name: name,
|
Name: name,
|
||||||
Path: path,
|
Path: path,
|
||||||
|
@ -14,7 +14,7 @@ var (
|
|||||||
MERGE_COMMIT_ICON = "\U000f062d" //
|
MERGE_COMMIT_ICON = "\U000f062d" //
|
||||||
DEFAULT_REMOTE_ICON = "\uf02a2" //
|
DEFAULT_REMOTE_ICON = "\uf02a2" //
|
||||||
STASH_ICON = "\uf01c" //
|
STASH_ICON = "\uf01c" //
|
||||||
WORKTREE_ICON = "\uf02b" //
|
LINKED_WORKTREE_ICON = "\uf838" //
|
||||||
)
|
)
|
||||||
|
|
||||||
var remoteIcons = map[string]string{
|
var remoteIcons = map[string]string{
|
||||||
@ -70,6 +70,9 @@ func IconForStash(stash *models.StashEntry) string {
|
|||||||
return STASH_ICON
|
return STASH_ICON
|
||||||
}
|
}
|
||||||
|
|
||||||
func IconForWorktree(tag *models.Worktree) string {
|
func IconForWorktree(worktree *models.Worktree) string {
|
||||||
return WORKTREE_ICON
|
if worktree.Main {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return LINKED_WORKTREE_ICON
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user