mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Style missing worktree as red and display better error when trying to switch to them
Use a broken link icon for missing worktrees
This commit is contained in:
committed by
Jesse Duffield
parent
9a79154d05
commit
c679fd1924
@ -1,15 +1,22 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/go-errors/errors"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Worktree : A git worktree
|
||||
type Worktree struct {
|
||||
Name string
|
||||
Main bool
|
||||
Current bool
|
||||
Path string
|
||||
Id int
|
||||
Path string
|
||||
}
|
||||
|
||||
func (w *Worktree) RefName() string {
|
||||
return w.Name
|
||||
return w.Name()
|
||||
}
|
||||
|
||||
func (w *Worktree) ID() string {
|
||||
@ -19,3 +26,30 @@ func (w *Worktree) ID() string {
|
||||
func (w *Worktree) Description() string {
|
||||
return w.RefName()
|
||||
}
|
||||
|
||||
func (w *Worktree) Name() string {
|
||||
return filepath.Base(w.Path)
|
||||
}
|
||||
|
||||
func (w *Worktree) Main() bool {
|
||||
return w.Id == 0
|
||||
}
|
||||
|
||||
func (w *Worktree) Current() bool {
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
|
||||
return pwd == w.Path
|
||||
}
|
||||
|
||||
func (w *Worktree) Missing() bool {
|
||||
if _, err := os.Stat(w.Path); err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return true
|
||||
}
|
||||
log.Fatalln(fmt.Errorf("failed to check if worktree path `%s` exists\n%w", w.Path, err).Error())
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user