mirror of
https://github.com/grdl/git-get.git
synced 2026-02-10 03:49:25 +00:00
Check if repos root exists and is not empty before opening repos
This commit is contained in:
11
pkg/list.go
11
pkg/list.go
@@ -3,6 +3,7 @@ package pkg
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -21,8 +22,14 @@ var skipNode = errors.New(".git directory found, skipping this node")
|
|||||||
var repos []string
|
var repos []string
|
||||||
|
|
||||||
func FindRepos() ([]string, error) {
|
func FindRepos() ([]string, error) {
|
||||||
|
repos = []string{}
|
||||||
|
|
||||||
root := Cfg.ReposRoot()
|
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{
|
walkOpts := &godirwalk.Options{
|
||||||
ErrorCallback: ErrorCb,
|
ErrorCallback: ErrorCb,
|
||||||
Callback: WalkCb,
|
Callback: WalkCb,
|
||||||
@@ -35,6 +42,10 @@ func FindRepos() ([]string, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(repos) == 0 {
|
||||||
|
return nil, fmt.Errorf("No git repos found in repos root %s", root)
|
||||||
|
}
|
||||||
|
|
||||||
return repos, nil
|
return repos, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user