6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-05 06:13:48 +00:00

Fix issues found by err113 linter

This commit is contained in:
Grzegorz Dlugoszewski
2025-08-24 16:53:48 +02:00
parent 1e1584ba33
commit f20ab7dea2
4 changed files with 18 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
package git
import (
"errors"
"fmt"
"io/fs"
"os"
@@ -12,8 +13,11 @@ import (
// Max number of concurrently running status loading workers.
const maxWorkers = 100
var errDirNoAccess = fmt.Errorf("directory can't be accessed")
var errDirNotExist = fmt.Errorf("directory doesn't exist")
var (
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.
func Exists(path string) (bool, error) {
@@ -23,11 +27,11 @@ func Exists(path string) (bool, error) {
}
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
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.
@@ -91,7 +95,7 @@ func (f *RepoFinder) Find() error {
}
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

View File

@@ -16,10 +16,6 @@ func TestFinder(t *testing.T) {
want int
}{
{
name: "no repos",
reposMaker: makeNoRepos,
want: 0,
}, {
name: "single repos",
reposMaker: makeSingleRepo,
want: 1,
@@ -59,7 +55,7 @@ func TestExists(t *testing.T) {
{
name: "dir does not exist",
path: "/this/directory/does/not/exist",
want: errDirNotExist,
want: ErrDirNotExist,
}, {
name: "dir exists",
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 {
root := test.TempDir(t, "")