go-mod-clean/doStrict.go

91 lines
2.5 KiB
Go
Raw Permalink Normal View History

package main
import (
"errors"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
func doStrict(repo *gitpb.Repo) error {
2024-12-17 01:55:37 -06:00
if !repo.IsValidDir() {
2024-12-17 07:03:07 -06:00
log.Info(repo.GetGoPath(), "is invalid. fix your repos.pb file with 'forge' first")
log.Info("")
log.Info("go install go.wit.com/apps/forge@latest")
log.Info("")
2024-12-17 07:03:07 -06:00
return errors.New(repo.GetGoPath() + " is invalid. fix your repository list with 'forge' first")
}
2024-12-17 07:03:07 -06:00
log.Info(repo.GetGoPath(), "is valid according to forge")
repo.Run([]string{"git", "notes", "remove"})
// erase the go.mod and go.sum files
eraseGoMod(repo)
if repo.GetMasterBranchName() != repo.GetCurrentBranchName() {
log.Info("")
log.Info("You are not operating on your git master branch.")
log.Info("Publishing go.mod & go.sum files must come from from git version tag on the master branch")
log.Info("")
2024-12-17 07:03:07 -06:00
return errors.New(repo.GetGoPath() + " not in the git master branch")
}
err := repo.RepoIgnoresGoMod()
if err != nil {
2024-12-17 07:03:07 -06:00
log.Info(repo.GetGoPath(), "some wierd git error happened. investigate.", err)
return err
}
2024-12-17 07:03:07 -06:00
if forge.Config.IsReadOnly(repo.GetGoPath()) {
log.Info("you can not push to read only repositories.", repo.GetGoPath())
log.Info("change your .config/forge/ to indicate you own this repository")
return nil
}
if repo.CheckDirty() {
log.Info("")
log.Info("You can not continue on a dirty git repo.")
log.Info("")
2024-12-17 07:03:07 -06:00
return errors.New(repo.GetGoPath() + " git repo is dirty")
}
2024-12-17 07:03:07 -06:00
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)
return err
}
// the first time, it'll attempt to fix some stuff
cleanGoDepsCheckOk(repo)
// try to trim junk
if err := trimGoSum(repo); err != nil {
log.Info(repo.GetGoPath(), "trimGoSum() failed", err)
return err
}
if repo.ParseGoSum() {
log.Info(repo.GetGoPath(), "ParseGoSum() ok")
} else {
log.Info(repo.GetGoPath(), "ParseGoSum() failed")
}
// check go.sum file
if err := cleanGoDepsCheckOk(repo); err != nil {
2024-12-17 07:03:07 -06:00
log.Info("forge.FinalGoDepsCheck() failed. boo. :", repo.GetGoPath())
return err
}
// put the files in the notes section in git
// this way, git commits are not messed up
// with this autogenerated code
if err := saveAsMetadata(repo); err != nil {
2024-12-17 07:03:07 -06:00
log.Info("save go.mod as git metadata failed", repo.GetGoPath(), err)
return err
}
// everything worked!
configSave = true
return nil
}