diff --git a/pkg/git/finder.go b/pkg/git/finder.go index 8926649..87d4251 100644 --- a/pkg/git/finder.go +++ b/pkg/git/finder.go @@ -105,13 +105,13 @@ func (f *RepoFinder) Find() error { // If fetch equals true, it first fetches from the remote repo before loading the status. // Each repo is loaded concurrently by a separate worker, with max 100 workers being active at the same time. func (f *RepoFinder) LoadAll(fetch bool) []*Status { - var statuses []*Status + statuses := []*Status{} reposChan := make(chan *Repo, f.maxWorkers) statusChan := make(chan *Status, f.maxWorkers) // Fire up workers. They listen on reposChan, load status and send the result to statusChan. - for i := 0; i < f.maxWorkers; i++ { + for range f.maxWorkers { go statusWorker(fetch, reposChan, statusChan) } diff --git a/pkg/git/repo.go b/pkg/git/repo.go index ac599d2..a4dee0a 100644 --- a/pkg/git/repo.go +++ b/pkg/git/repo.go @@ -156,6 +156,7 @@ func (r *Repo) Upstream(branch string) (string, error) { out, err := run.Git("rev-parse", "--abbrev-ref", "--symbolic-full-name", fmt.Sprintf("%s@{upstream}", branch)).OnRepo(r.path).AndCaptureLine() if err != nil { // TODO: no upstream will also throw an error. + // lint:ignore nilerr fix when working on TODO return "", nil } diff --git a/pkg/print/print.go b/pkg/print/print.go index 1a4d470..58fac04 100644 --- a/pkg/print/print.go +++ b/pkg/print/print.go @@ -15,7 +15,7 @@ type Printable interface { Path() string Current() string Branches() []string - BranchStatus(string) string + BranchStatus(branch string) string WorkTreeStatus() string Remote() string Errors() []string diff --git a/pkg/run/run.go b/pkg/run/run.go index 20e8148..390c4e6 100644 --- a/pkg/run/run.go +++ b/pkg/run/run.go @@ -3,6 +3,7 @@ package run import ( "bytes" + "context" "fmt" "os" "os/exec" @@ -32,8 +33,9 @@ type Cmd struct { // Git creates a git command with given arguments. func Git(args ...string) *Cmd { + ctx := context.Background() return &Cmd{ - cmd: exec.Command("git", args...), + cmd: exec.CommandContext(ctx, "git", args...), args: strings.Join(args, " "), } } diff --git a/pkg/url.go b/pkg/url.go index 92ef232..fe0c39b 100644 --- a/pkg/url.go +++ b/pkg/url.go @@ -19,8 +19,8 @@ var scpSyntax = regexp.MustCompile(`^([a-zA-Z0-9_]+)@([a-zA-Z0-9._-]+):(.*)$`) // ParseURL parses given rawURL string into a URL. // When the parsed URL has an empty host, use the defaultHost. // When the parsed URL has an empty scheme, use the defaultScheme. -func ParseURL(rawURL string, defaultHost string, defaultScheme string) (url *urlpkg.URL, err error) { - url, err = parseRawURL(rawURL) +func ParseURL(rawURL string, defaultHost string, defaultScheme string) (*urlpkg.URL, error) { + url, err := parseRawURL(rawURL) if err != nil { return nil, err }