mirror of
https://github.com/grdl/git-get.git
synced 2026-02-05 23:27:56 +00:00
Fix issues found by wsl linter
This commit is contained in:
@@ -18,7 +18,6 @@ var errDirNotExist = fmt.Errorf("directory doesn't exist")
|
||||
// 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) {
|
||||
_, err := os.Stat(path)
|
||||
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
@@ -61,6 +60,7 @@ func (f *RepoFinder) Find() error {
|
||||
if os.IsPermission(err) {
|
||||
return nil // Skip this path but continue
|
||||
}
|
||||
|
||||
return fmt.Errorf("failed to walk %s: %w", path, err)
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ func (f *RepoFinder) Find() error {
|
||||
if d.Name() == dotgit {
|
||||
parentPath := filepath.Dir(path)
|
||||
f.addIfOk(parentPath)
|
||||
|
||||
return fs.SkipDir // Skip the .git directory contents
|
||||
}
|
||||
|
||||
@@ -85,7 +86,6 @@ func (f *RepoFinder) Find() error {
|
||||
|
||||
return nil // Continue walking
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to walk directory tree: %w", err)
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ func Clone(opts *CloneOpts) (*Repo, error) {
|
||||
}
|
||||
|
||||
Repo, err := Open(opts.Path)
|
||||
|
||||
return Repo, err
|
||||
}
|
||||
|
||||
@@ -79,6 +80,7 @@ func (r *Repo) Uncommitted() (int, error) {
|
||||
}
|
||||
|
||||
count := 0
|
||||
|
||||
for _, line := range out {
|
||||
// Don't count lines with untracked files and empty lines.
|
||||
if !strings.HasPrefix(line, untracked) && strings.TrimSpace(line) != "" {
|
||||
@@ -97,6 +99,7 @@ func (r *Repo) Untracked() (int, error) {
|
||||
}
|
||||
|
||||
count := 0
|
||||
|
||||
for _, line := range out {
|
||||
if strings.HasPrefix(line, untracked) {
|
||||
count++
|
||||
@@ -122,6 +125,7 @@ func (r *Repo) CurrentBranch() (string, error) {
|
||||
// Fall back to "main" as the modern default
|
||||
return "main", nil
|
||||
}
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -190,6 +194,7 @@ func (r *Repo) Remote() (string, error) {
|
||||
if strings.Contains(err.Error(), "No remote configured to list refs from") {
|
||||
return "", nil // Return empty string instead of error for missing remote
|
||||
}
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ func TestUncommitted(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
r, _ := Open(test.repoMaker(t).Path())
|
||||
got, err := r.Uncommitted()
|
||||
|
||||
got, err := r.Uncommitted()
|
||||
if err != nil {
|
||||
t.Errorf("got error %q", err)
|
||||
}
|
||||
@@ -95,8 +95,8 @@ func TestUntracked(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
r, _ := Open(test.repoMaker(t).Path())
|
||||
got, err := r.Uncommitted()
|
||||
|
||||
got, err := r.Uncommitted()
|
||||
if err != nil {
|
||||
t.Errorf("got error %q", err)
|
||||
}
|
||||
@@ -139,8 +139,8 @@ func TestCurrentBranch(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
r, _ := Open(test.repoMaker(t).Path())
|
||||
got, err := r.CurrentBranch()
|
||||
|
||||
got, err := r.CurrentBranch()
|
||||
if err != nil {
|
||||
t.Errorf("got error %q", err)
|
||||
}
|
||||
@@ -182,8 +182,8 @@ func TestBranches(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
r, _ := Open(test.repoMaker(t).Path())
|
||||
got, err := r.Branches()
|
||||
|
||||
got, err := r.Branches()
|
||||
if err != nil {
|
||||
t.Errorf("got error %q", err)
|
||||
}
|
||||
@@ -287,6 +287,7 @@ func TestAheadBehind(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
r, _ := Open(test.repoMaker(t).Path())
|
||||
|
||||
upstream, err := r.Upstream(test.branch)
|
||||
if err != nil {
|
||||
t.Errorf("got error %q", err)
|
||||
@@ -313,7 +314,6 @@ func TestCleanupFailedClone(t *testing.T) {
|
||||
// └── x/
|
||||
// └── y/
|
||||
// └── file.txt
|
||||
|
||||
tests := []struct {
|
||||
path string // path to cleanup
|
||||
wantGone string // this path should be deleted, if empty - nothing should be deleted
|
||||
@@ -393,6 +393,7 @@ func TestRemote(t *testing.T) {
|
||||
if test.wantErr && err == nil {
|
||||
t.Errorf("expected error but got none")
|
||||
}
|
||||
|
||||
if !test.wantErr && err != nil {
|
||||
t.Errorf("unexpected error: %q", err)
|
||||
}
|
||||
@@ -413,8 +414,8 @@ func createTestDirTree(t *testing.T) string {
|
||||
root := test.TempDir(t, "")
|
||||
err := os.MkdirAll(filepath.Join(root, "a", "b", "c"), os.ModePerm)
|
||||
err = os.MkdirAll(filepath.Join(root, "a", "x", "y"), os.ModePerm)
|
||||
_, err = os.Create(filepath.Join(root, "a", "x", "y", "file.txt"))
|
||||
|
||||
_, err = os.Create(filepath.Join(root, "a", "x", "y", "file.txt"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -32,12 +32,14 @@ func (r *Repo) LoadStatus(fetch bool) *Status {
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
status.current, err = r.CurrentBranch()
|
||||
if err != nil {
|
||||
status.errors = append(status.errors, err.Error())
|
||||
}
|
||||
|
||||
var errs []error
|
||||
|
||||
status.branches, errs = r.loadBranches()
|
||||
for _, err := range errs {
|
||||
status.errors = append(status.errors, err.Error())
|
||||
@@ -69,6 +71,7 @@ func (r *Repo) loadBranches() (map[string]string, []error) {
|
||||
for _, branch := range branches {
|
||||
status, err := r.loadBranchStatus(branch)
|
||||
statuses[branch] = status
|
||||
|
||||
if err != nil {
|
||||
errors = append(errors, err)
|
||||
}
|
||||
@@ -100,6 +103,7 @@ func (r *Repo) loadBranchStatus(branch string) (string, error) {
|
||||
if ahead != 0 {
|
||||
res = append(res, fmt.Sprintf("%d ahead", ahead))
|
||||
}
|
||||
|
||||
if behind != 0 {
|
||||
res = append(res, fmt.Sprintf("%d behind", behind))
|
||||
}
|
||||
@@ -126,6 +130,7 @@ func (r *Repo) loadWorkTree() (string, error) {
|
||||
if uncommitted != 0 {
|
||||
res = append(res, fmt.Sprintf("%d uncommitted", uncommitted))
|
||||
}
|
||||
|
||||
if untracked != 0 {
|
||||
res = append(res, fmt.Sprintf("%d untracked", untracked))
|
||||
}
|
||||
@@ -151,6 +156,7 @@ func (s *Status) Branches() []string {
|
||||
branches = append(branches, b)
|
||||
}
|
||||
}
|
||||
|
||||
return branches
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ func RepoEmptyInDir(t *testing.T, parent string) *Repo {
|
||||
}
|
||||
|
||||
r.init()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -97,6 +98,7 @@ func RepoWithBranchWithUpstream(t *testing.T) *Repo {
|
||||
|
||||
r := origin.clone()
|
||||
r.checkout("feature/branch")
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -107,6 +109,7 @@ func RepoWithBranchWithoutUpstream(t *testing.T) *Repo {
|
||||
r := origin.clone()
|
||||
r.branch("feature/branch")
|
||||
r.checkout("feature/branch")
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user