diff --git a/internal/pkg/repo/discover.go b/internal/pkg/repo/discover.go index 90f3780..4fdd61b 100644 --- a/internal/pkg/repo/discover.go +++ b/internal/pkg/repo/discover.go @@ -9,26 +9,27 @@ import ( ) func ExpandPath(path string) string { - if strings.HasPrefix(path, "~") { - home, err := os.UserHomeDir() - if err != nil { - return path - } - return home + path[1:] - } - return os.ExpandEnv(path) + if strings.HasPrefix(path, "~") { + home, err := os.UserHomeDir() + if err != nil { + return path + } + return home + path[1:] + } + return os.ExpandEnv(path) } func extraDirs() []string { - paths := viper.GetStringSlice("extraDirs") - for i, path := range paths { - paths[i] = ExpandPath(path) - } + paths := viper.GetStringSlice("extraDirs") + for i, path := range paths { + paths[i] = ExpandPath(path) + } - return paths + return paths } func GetRepoPathsChan(basedir string, includeExtras bool) <-chan string { + basedir = ExpandPath(basedir) out := make(chan string) go func() { defer close(out) @@ -66,36 +67,10 @@ func GetRepoPathsChan(basedir string, includeExtras bool) <-chan string { } func GetRepoPathsAsync(baseDir string, result *[]string) error { - if len(*result) == 0 { - *result = append(*result, extraDirs()...) + ch := GetRepoPathsChan(baseDir, true) + for p := range ch { + *result = append(*result, p) } - - entries, err := os.ReadDir(baseDir) - if err != nil { - return err - } - - subdirs := []string{} - for _, entry := range entries { - if !entry.IsDir() { - continue - } - - if entry.Name() == ".git" { - *result = append(*result, baseDir) - return nil - } - - subdirs = append(subdirs, entry.Name()) - } - - for _, subdir := range subdirs { - err := GetRepoPathsAsync(fmt.Sprintf("%s/%s", baseDir, subdir), result) - if err != nil { - return err - } - } - return nil }