diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-17 17:06:39 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-30 18:35:23 +1000 |
commit | eeec37372801c3dab427de474945b8d30ad88395 (patch) | |
tree | 052ea996cc1b3c905d948388fbb9c6d50fd10c29 /pkg/commands | |
parent | 0604e43813f9befc9738572deaeaba06fcf2a2e3 (diff) |
Safer fetching of linked worktree paths
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git_commands/worktree.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/pkg/commands/git_commands/worktree.go b/pkg/commands/git_commands/worktree.go index ce2d831c1..460a8b7f9 100644 --- a/pkg/commands/git_commands/worktree.go +++ b/pkg/commands/git_commands/worktree.go @@ -155,7 +155,17 @@ func linkedWortkreePaths() []string { result := []string{} worktreePath := filepath.Join(repoPath, ".git", "worktrees") // for each directory in this path we're going to cat the `gitdir` file and append its contents to our result - err := filepath.Walk(worktreePath, func(path string, info fs.FileInfo, err error) error { + + // ensure the directory exists + _, err := os.Stat(worktreePath) + if err != nil { + if errors.Is(err, fs.ErrNotExist) { + return result + } + log.Fatalln(err.Error()) + } + + err = filepath.Walk(worktreePath, func(path string, info fs.FileInfo, err error) error { if info.IsDir() { gitDirPath := filepath.Join(path, "gitdir") gitDirBytes, err := os.ReadFile(gitDirPath) |