6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 19:44:41 +00:00

Check if repos root exists and is not empty before opening repos

This commit is contained in:
Grzegorz Dlugoszewski
2020-06-03 13:25:01 +02:00
parent 8a79dcfd9f
commit b7bd30c960

View File

@@ -3,6 +3,7 @@ package pkg
import (
"errors"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
@@ -21,8 +22,14 @@ var skipNode = errors.New(".git directory found, skipping this node")
var repos []string
func FindRepos() ([]string, error) {
repos = []string{}
root := Cfg.ReposRoot()
if _, err := os.Stat(root); err != nil {
return nil, fmt.Errorf("Repos root %s does not exist or can't be accessed", root)
}
walkOpts := &godirwalk.Options{
ErrorCallback: ErrorCb,
Callback: WalkCb,
@@ -35,6 +42,10 @@ func FindRepos() ([]string, error) {
return nil, err
}
if len(repos) == 0 {
return nil, fmt.Errorf("No git repos found in repos root %s", root)
}
return repos, nil
}