diff --git a/redoGoMod.go b/redoGoMod.go index 4593b2f..ca9b536 100644 --- a/redoGoMod.go +++ b/redoGoMod.go @@ -3,7 +3,7 @@ package main // recreates the go.mod and go.sum files import ( - "errors" + "fmt" "os" "strings" @@ -50,6 +50,13 @@ func redoGoMod(repo *gitpb.Repo) error { log.Warn("go mod init failed", err) return err } + + // check to see if this is primitive + repo.ParseGoSum() + if repo.GetGoPrimitive() { + return nil + } + if result, err := goTidy(repo.FullPath); err != nil { if tinyFixer(result) { if _, err := goTidy(repo.FullPath); err != nil { @@ -64,40 +71,13 @@ func redoGoMod(repo *gitpb.Repo) error { return err } - repo.GoDeps = nil - repo.SetGoPrimitive(false) - - // if there is not a go.sum file, it better be a primitive golang project - if !repo.Exists("go.sum") { - // todo. fix this logic - err := repo.SetPrimitive() - if err != nil { - // this means this repo does not depend on any other package - log.Info("PRIMATIVE repo error:", repo.GetGoPath(), "err =", err) - return err - } - } - - // now check if GoPrimitive is true - if repo.GetGoPrimitive() { - // perfect! + // parse the go.mod and go.sum files + if repo.ParseGoSum() { + // this is primitive return nil } - // well, it's not a primitive and we are still missing the go.sum file - if !repo.Exists("go.sum") { - // this means something else went wrong! - // display the go.mod file and try to figure out what happened - // maybe the format of go.mod changed in some future version of golang - data, _ := repo.ReadFile("go.mod") - log.Info(string(data)) - return errors.New("missing go.sum file on non-primitive go.mod") - } - - repo.GoDeps = new(gitpb.GoDeps) - // return the attempt to parse go.sum - _, err := repo.ParseGoSum() - return err + return fmt.Errorf("check.ParseGoSum() failed") } func tinyFixer(result cmd.Status) bool {