diff --git a/doStrict.go b/doStrict.go index 9d233b9..59439d7 100644 --- a/doStrict.go +++ b/doStrict.go @@ -8,6 +8,8 @@ import ( ) func doStrict(repo *gitpb.Repo) error { + var err error + if !repo.IsValidDir() { log.Info(repo.GetGoPath(), "is invalid. fix your repos.pb file with 'forge' first") log.Info("") @@ -35,7 +37,7 @@ func doStrict(repo *gitpb.Repo) error { return errors.New(repo.GetGoPath() + " not in the git master branch") } - err := repo.RepoIgnoresGoMod() + err = repo.RepoIgnoresGoMod() if err != nil { log.Info(repo.GetGoPath(), "some wierd git error happened. investigate.", err) return err @@ -57,11 +59,22 @@ func doStrict(repo *gitpb.Repo) error { log.Info(repo.GetGoPath(), "GOING TO MAKE NEW go.* FILES") // actually will re-create go.sum and go.mod now - if err := redoGoMod(repo); err != nil { - log.Info(repo.GetGoPath(), "redoGoMod() failed", err) + if _, err = repo.RunQuiet([]string{"go", "mod", "init", repo.GetGoPath()}); err != nil { + log.Warn("go mod init failed", err) return err } + if repo.Exists("go.mod") { + // well, if go mod init fails, then we will just error since 'go mod init' almost never fails + return err + } + + if _, err := repo.RunQuiet([]string{"go", "mod", "tidy", "-go=" + golangVersion}); err == nil { + // I guess the thing to do, if go mod tidy fails, is to just leave the repo alone + // it's either primitive or could be a go support project but not in go + return nil + } + // the first time, it'll attempt to fix some stuff cleanGoDepsCheckOk(repo) // try to trim junk