more go.* handling. this is getting annoying. I don't like go.work files
This commit is contained in:
parent
8a8f287a81
commit
34b8325a06
44
redoGoMod.go
44
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 {
|
||||
|
|
Loading…
Reference in New Issue