summaryrefslogtreecommitdiff
path: root/redoGoMod.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-18 20:08:28 -0600
committerJeff Carr <[email protected]>2024-12-18 20:08:28 -0600
commit34b8325a063fe13c26ee278cb24da6299608aada (patch)
treebbf8bca66a3bd4050af8dc59dfc91844cae0fa33 /redoGoMod.go
parent8a8f287a81b827bdfb33b1e7be2fdcacc86af1f9 (diff)
more go.* handling. this is getting annoying. I don't like go.work files
Diffstat (limited to 'redoGoMod.go')
-rw-r--r--redoGoMod.go44
1 files changed, 12 insertions, 32 deletions
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 {