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/git_commands/worktree.go | |
parent | 1ce9a87544c87629567812fbb72d4f4a4f37bdf9 (diff) |
Address PR comments
Diffstat (limited to 'pkg/commands/git_commands/worktree.go')
-rw-r--r-- | pkg/commands/git_commands/worktree.go | 29 |
1 files changed, 29 insertions, 0 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 +} |