Skip to content

Commit

Permalink
Safer fetching of linked worktree paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Jul 30, 2023
1 parent 0604e43 commit eeec373
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/commands/git_commands/worktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit eeec373

Please sign in to comment.