diff options
author | Joel Baranick <joel.baranick@ensighten.com> | 2022-09-10 22:36:47 -0700 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-30 18:35:21 +1000 |
commit | db02c13bf65a251cab3a92409024b05813cd1ec6 (patch) | |
tree | ae6e3eea2e29d62d23d9c94e18ba030ed6610deb /pkg/commands | |
parent | 1ce9a87544c87629567812fbb72d4f4a4f37bdf9 (diff) |
Address PR comments
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git_commands/worktree.go | 29 | ||||
-rw-r--r-- | pkg/commands/models/worktree.go | 24 |
2 files changed, 29 insertions, 24 deletions
diff --git a/pkg/commands/git_commands/worktree.go b/pkg/commands/git_commands/worktree.go index 71ffb7aa3..78157ddf2 100644 --- a/pkg/commands/git_commands/worktree.go +++ b/pkg/commands/git_commands/worktree.go @@ -1,5 +1,15 @@ package git_commands +import ( + "errors" + "fmt" + "io/fs" + "log" + "os" + + "github.com/jesseduffield/lazygit/pkg/commands/models" +) + type WorktreeCommands struct { *GitCommon } @@ -21,3 +31,22 @@ func (self *WorktreeCommands) Delete(worktreePath string, force bool) error { return self.cmd.New(cmdArgs).Run() } + +func (self *WorktreeCommands) IsCurrentWorktree(w *models.Worktree) bool { + pwd, err := os.Getwd() + if err != nil { + log.Fatalln(err.Error()) + } + + return pwd == w.Path +} + +func (self *WorktreeCommands) IsWorktreePathMissing(w *models.Worktree) 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 +} diff --git a/pkg/commands/models/worktree.go b/pkg/commands/models/worktree.go index f02dc184c..3b9cf64b3 100644 --- a/pkg/commands/models/worktree.go +++ b/pkg/commands/models/worktree.go @@ -1,11 +1,6 @@ package models import ( - "fmt" - "github.com/go-errors/errors" - "io/fs" - "log" - "os" "path/filepath" ) @@ -35,22 +30,3 @@ func (w *Worktree) Name() string { 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 -} |