go-mod-clean/doSmart.go

58 lines
1.4 KiB
Go
Raw Permalink Normal View History

package main
import (
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
// this will make go.mod and go.sum files, but you have to
// have the files in .gitignore for now
func doSmart(repo *gitpb.Repo) error {
// if the repo has go.mod in the repo...
if err := repo.RepoIgnoresGoMod(); err != nil {
2025-01-29 20:42:49 -06:00
if repo.ParseGoSum() {
return nil
}
2025-01-07 17:16:38 -06:00
log.Info("go-mod-clean can not run on this repo", repo.GetGoPath())
log.Info("go.mod and go.sum must be git metadata to continue")
2025-01-29 20:42:49 -06:00
// return nil
if repo.Exists("go.sum") {
return nil
}
2025-01-29 20:42:49 -06:00
}
// erase the go.mod and go.sum files
eraseGoMod(repo)
// try to restore from the git metadata
cname := repo.GetCurrentBranchName()
if err := repo.AutogenRestore(cname); err == nil {
2024-12-17 07:03:07 -06:00
log.Info(repo.GetGoPath(), "files were restored ok from git metadata (notes)")
if repo.Exists("go.mod") {
return nil
}
// autogen restore didn't find go.mod
}
// actually will re-create go.sum and go.mod now
if err := redoGoMod(repo); err != nil {
return err
2025-01-29 20:42:49 -06:00
}
log.Info(repo.GetGoPath(), "the files were restored with redoGoMod()")
2025-02-07 11:21:36 -06:00
/*
if repo.Exists("go.mod") {
return nil
}
*/
// the first time, it'll attempt to fix some stuff
if err := cleanGoDepsCheckOk(repo); err != nil {
return err
2025-01-29 20:42:49 -06:00
}
// trim junk that might have been added by cleanGoDepsCheckOk()
if err := trimGoSum(repo); err != nil {
return err
2025-01-29 20:42:49 -06:00
}
return nil
}