add --strict for release management purposes

This commit is contained in:
Jeff Carr 2024-12-14 18:45:29 -06:00
parent a8f7adee19
commit f43311c36c
3 changed files with 31 additions and 19 deletions

View File

@ -14,7 +14,7 @@ type args struct {
Notes bool `arg:"--metadata" help:"save as git metadata (notes)"` Notes bool `arg:"--metadata" help:"save as git metadata (notes)"`
Restore bool `arg:"--restore" default:"true" help:"restore from git metadata"` Restore bool `arg:"--restore" default:"true" help:"restore from git metadata"`
Force bool `arg:"--force" help:"remove the old one"` Force bool `arg:"--force" help:"remove the old one"`
Pure bool `arg:"--pure" default:"false" help:"never leave go.* files unless things are perfect"` Strict bool `arg:"--strict" default:"false" help:"never make go.* files unless everything is perfect"`
} }
func (args) Version() string { func (args) Version() string {

View File

@ -18,7 +18,8 @@ func badExit(check *gitpb.Repo, err error) {
log.DaemonMode(true) log.DaemonMode(true)
log.Info("go-mod-clean failed: ", err, forge.GetGoSrc()) log.Info("go-mod-clean failed: ", err, forge.GetGoSrc())
if check != nil { if check != nil {
if argv.Pure { if argv.Strict {
// if in strict mode, remove the go.mod and go.sum
eraseGoMod(check) eraseGoMod(check)
} }
} }

45
main.go
View File

@ -94,6 +94,7 @@ func saveAsMetadata(repo *gitpb.Repo) error {
} }
func doMain(repo *gitpb.Repo) error { func doMain(repo *gitpb.Repo) error {
var perfect bool = true
if !repo.IsValid() { if !repo.IsValid() {
log.Info(repo.GoPath, "is invalid. fix your repos.pb file with 'forge' first") log.Info(repo.GoPath, "is invalid. fix your repos.pb file with 'forge' first")
log.Info("") log.Info("")
@ -127,12 +128,14 @@ func doMain(repo *gitpb.Repo) error {
} }
if repo.GetMasterBranchName() != repo.GetCurrentBranchName() { if repo.GetMasterBranchName() != repo.GetCurrentBranchName() {
log.Info("") perfect = false
log.Info("You can only run go-mod-clean on a git master branch.") if argv.Strict {
log.Info("Publishing go.mod & go.sum files must come from from git version tag") log.Info("")
log.Info("Anything else doesn't make sense.") log.Info("You are not operating on your git master branch.")
log.Info("") log.Info("Publishing go.mod & go.sum files must come from from git version tag on the master branch")
return errors.New(repo.GoPath + " not in the git master branch") log.Info("")
return errors.New(repo.GoPath + " not in the git master branch")
}
} }
ok, err := repoIgnoresGoMod(repo) ok, err := repoIgnoresGoMod(repo)
@ -147,17 +150,22 @@ func doMain(repo *gitpb.Repo) error {
// continue and attempt to create go.mod and go.sum // continue and attempt to create go.mod and go.sum
} else { } else {
if forge.Config.IsReadOnly(repo.GoPath) { if forge.Config.IsReadOnly(repo.GoPath) {
log.Info("skipping read only", repo.GoPath) log.Info("you can not push to read only repositories.", repo.GoPath)
log.Info("change your .config/forge/ to indicate you own this repository")
return nil return nil
} }
perfect = false
// continue and attempt to create go.mod and go.sum // continue and attempt to create go.mod and go.sum
} }
if repo.CheckDirty() { if repo.CheckDirty() {
log.Info("") perfect = false
log.Info("You can not run this on dirty branches.") if argv.Strict {
log.Info("") log.Info("")
return errors.New(repo.GoPath + " git repo is dirty") log.Info("You can not continue on a dirty git repo.")
log.Info("")
return errors.New(repo.GoPath + " git repo is dirty")
}
} }
log.Info(repo.GoPath, "GOING TO MAKE NEW go.* FILES") log.Info(repo.GoPath, "GOING TO MAKE NEW go.* FILES")
@ -190,12 +198,15 @@ func doMain(repo *gitpb.Repo) error {
return err return err
} }
// put the files in the notes section in git // if everything is perfect, save them as git metadata
// this way, git commits are not messed up if perfect {
// with this autogenerated code // put the files in the notes section in git
if err := saveAsMetadata(repo); err != nil { // this way, git commits are not messed up
log.Info("save go.mod as git metadata failed", repo.GoPath, err) // with this autogenerated code
return err if err := saveAsMetadata(repo); err != nil {
log.Info("save go.mod as git metadata failed", repo.GoPath, err)
return err
}
} }
// everything worked! // everything worked!