From 1ee5ff6bf07dfb089d62cb43c6b5cd3a388f5a64 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Wed, 1 Feb 2023 10:58:31 -0800 Subject: [PATCH] fix an error where the wait group never completes on uninitialized repo --- cmd/mgfetch/mgfetch.go | 7 ++++++- commits/chancommits.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/mgfetch/mgfetch.go b/cmd/mgfetch/mgfetch.go index 0837b1d..1e6afd6 100644 --- a/cmd/mgfetch/mgfetch.go +++ b/cmd/mgfetch/mgfetch.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "time" git "github.com/go-git/go-git/v5" @@ -12,12 +13,16 @@ import ( type Repo git.Repository func main() { - year := time.Now().Year() - 1 + year := time.Now().Year() authors := []string{"Groot"} mr, err := commits.GetMRRepos() if err != nil { panic(err) } + if len(mr) == 0 { + fmt.Println("found no repos!") + os.Exit(1) + } gfreq, err := mr.FrequencyChan(year, authors) if err != nil { panic(err) diff --git a/commits/chancommits.go b/commits/chancommits.go index e829d59..51b1aeb 100644 --- a/commits/chancommits.go +++ b/commits/chancommits.go @@ -24,6 +24,7 @@ func (paths RepoSet) FrequencyChan(year int, authors []string) (types.Freq, erro for _, p := range paths { wg.Add(1) go func(path string) { + defer wg.Done() repo, err := OpenRepo(path) if err != nil { return @@ -40,7 +41,6 @@ func (paths RepoSet) FrequencyChan(year int, authors []string) (types.Freq, erro for c := range cc { outChan <- c } - wg.Done() }(p) } go func() {