mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 17:24:49 +00:00
Fix issues found by err113 linter
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
package pkg
|
package pkg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git-get/pkg/git"
|
"git-get/pkg/git"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrMissingRepoArg = errors.New("missing <REPO> argument or --dump flag")
|
||||||
|
|
||||||
// GetCfg provides configuration for the Get command.
|
// GetCfg provides configuration for the Get command.
|
||||||
type GetCfg struct {
|
type GetCfg struct {
|
||||||
Branch string
|
Branch string
|
||||||
@@ -20,7 +23,7 @@ type GetCfg struct {
|
|||||||
// Get executes the "git get" command.
|
// Get executes the "git get" command.
|
||||||
func Get(conf *GetCfg) error {
|
func Get(conf *GetCfg) error {
|
||||||
if conf.URL == "" && conf.Dump == "" {
|
if conf.URL == "" && conf.Dump == "" {
|
||||||
return fmt.Errorf("missing <REPO> argument or --dump flag")
|
return ErrMissingRepoArg
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.URL != "" {
|
if conf.URL != "" {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
@@ -12,8 +13,11 @@ import (
|
|||||||
// Max number of concurrently running status loading workers.
|
// Max number of concurrently running status loading workers.
|
||||||
const maxWorkers = 100
|
const maxWorkers = 100
|
||||||
|
|
||||||
var errDirNoAccess = fmt.Errorf("directory can't be accessed")
|
var (
|
||||||
var errDirNotExist = fmt.Errorf("directory doesn't exist")
|
ErrDirNoAccess = errors.New("directory can't be accessed")
|
||||||
|
ErrDirNotExist = errors.New("directory doesn't exist")
|
||||||
|
ErrNoReposFound = errors.New("no git repositories found")
|
||||||
|
)
|
||||||
|
|
||||||
// Exists returns true if a directory exists. If it doesn't or the directory can't be accessed it returns an error.
|
// Exists returns true if a directory exists. If it doesn't or the directory can't be accessed it returns an error.
|
||||||
func Exists(path string) (bool, error) {
|
func Exists(path string) (bool, error) {
|
||||||
@@ -23,11 +27,11 @@ func Exists(path string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return false, fmt.Errorf("can't access %s: %w", path, errDirNotExist)
|
return false, fmt.Errorf("can't access %s: %w", path, ErrDirNotExist)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Directory exists but can't be accessed
|
// Directory exists but can't be accessed
|
||||||
return true, fmt.Errorf("can't access %s: %w", path, errDirNoAccess)
|
return true, fmt.Errorf("can't access %s: %w", path, ErrDirNoAccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepoFinder finds git repositories inside a given path and loads their status.
|
// RepoFinder finds git repositories inside a given path and loads their status.
|
||||||
@@ -91,7 +95,7 @@ func (f *RepoFinder) Find() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(f.repos) == 0 {
|
if len(f.repos) == 0 {
|
||||||
return fmt.Errorf("no git repos found in root path %s", f.root)
|
return fmt.Errorf("%w in root path %s", ErrNoReposFound, f.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ func TestFinder(t *testing.T) {
|
|||||||
want int
|
want int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no repos",
|
|
||||||
reposMaker: makeNoRepos,
|
|
||||||
want: 0,
|
|
||||||
}, {
|
|
||||||
name: "single repos",
|
name: "single repos",
|
||||||
reposMaker: makeSingleRepo,
|
reposMaker: makeSingleRepo,
|
||||||
want: 1,
|
want: 1,
|
||||||
@@ -59,7 +55,7 @@ func TestExists(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "dir does not exist",
|
name: "dir does not exist",
|
||||||
path: "/this/directory/does/not/exist",
|
path: "/this/directory/does/not/exist",
|
||||||
want: errDirNotExist,
|
want: ErrDirNotExist,
|
||||||
}, {
|
}, {
|
||||||
name: "dir exists",
|
name: "dir exists",
|
||||||
path: os.TempDir(),
|
path: os.TempDir(),
|
||||||
@@ -76,12 +72,6 @@ func TestExists(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeNoRepos(t *testing.T) string {
|
|
||||||
root := test.TempDir(t, "")
|
|
||||||
|
|
||||||
return root
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeSingleRepo(t *testing.T) string {
|
func makeSingleRepo(t *testing.T) string {
|
||||||
root := test.TempDir(t, "")
|
root := test.TempDir(t, "")
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package pkg
|
package pkg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git-get/pkg/cfg"
|
"git-get/pkg/cfg"
|
||||||
"git-get/pkg/git"
|
"git-get/pkg/git"
|
||||||
@@ -8,6 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrInvalidOutput = errors.New("invalid output format")
|
||||||
|
|
||||||
// ListCfg provides configuration for the List command.
|
// ListCfg provides configuration for the List command.
|
||||||
type ListCfg struct {
|
type ListCfg struct {
|
||||||
Fetch bool
|
Fetch bool
|
||||||
@@ -37,7 +40,7 @@ func List(conf *ListCfg) error {
|
|||||||
case cfg.OutDump:
|
case cfg.OutDump:
|
||||||
fmt.Print(print.NewDumpPrinter().Print(printables))
|
fmt.Print(print.NewDumpPrinter().Print(printables))
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid --out flag; allowed values: [%s]", strings.Join(cfg.AllowedOut, ", "))
|
return fmt.Errorf("%w, allowed values: [%s]", ErrInvalidOutput, strings.Join(cfg.AllowedOut, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user