diff options
| author | Jeff Carr <[email protected]> | 2025-01-29 20:42:49 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-01-29 20:42:49 -0600 |
| commit | a7e37626c0be69c312a001418725c382de9393ae (patch) | |
| tree | f4930f81bbcf4e08f210aa07aa14aa9ec7335d9b | |
| parent | 088496e2fb0638747a38fd4bf3fd860fa2ae77f0 (diff) | |
maybe, finally, release logic works
| -rw-r--r-- | argv.go | 1 | ||||
| -rw-r--r-- | doSmart.go | 37 | ||||
| -rw-r--r-- | main.go | 30 |
3 files changed, 35 insertions, 33 deletions
@@ -13,6 +13,7 @@ type args struct { Force bool `arg:"--force" help:"remove things and redo them no matter what"` Strict bool `arg:"--strict" help:"never make go.* files unless everything is perfect"` Purge bool `arg:"--purge" help:"purge all the git notes. this might be bad for you."` + Smart bool `arg:"--smart" help:"whatever seems best at the time. never os.Exit(-1)"` } func (args) Version() string { @@ -8,45 +8,62 @@ import ( // 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 { + // erase the go.mod and go.sum files + eraseGoMod(repo) + // if the repo has go.mod in the repo... if err := repo.RepoIgnoresGoMod(); err != nil { + if repo.ParseGoSum() { + return nil + } 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") - repo.ParseGoSum() + // return nil + } + if repo.Exists("go.mod") { return nil } - // 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 { log.Info(repo.GetGoPath(), "files were restored ok from git metadata (notes)") - configSave = true + } + if repo.Exists("go.mod") { return nil } // attempt to restore from ~/go/pkg/mod/ if err := restoreFromGoPkg(repo); err == nil { - configSave = true + log.Info(repo.GetGoPath(), "files were restored ok ~/go/mod/") + } + if repo.Exists("go.mod") { return nil } // actually will re-create go.sum and go.mod now if err := redoGoMod(repo); err != nil { - return err + log.Info(repo.GetGoPath(), "the files were restored with redoGoMod()") + } + if repo.Exists("go.mod") { + return nil } // the first time, it'll attempt to fix some stuff cleanGoDepsCheckOk(repo) // try to trim junk if err := trimGoSum(repo); err != nil { - return err + } + if repo.Exists("go.mod") { + return nil } repo.ParseGoSum() - // everything worked more or less - configSave = true + if repo.Exists("go.mod") { + return nil + } + // last chance. just run go mod init + repo.RunVerbose([]string{"go", "mod", "init"}) + return nil } @@ -58,25 +58,20 @@ func main() { } okExit(check, "go.mod seems clean") } - - if err := doMain(check); err != nil { - badExit(check, err) + if argv.Smart { + // best effort + if err := doSmart(check); err != nil { + // badExit(check, err) + } + okExit(check, "maybe it's ok") } + if argv.Force { if err := doForce(check); err != nil { badExit(check, err) } - } else { - if err := doSmart(check); err != nil { - badExit(check, err) - } } - if configSave { - forge.ConfigSave() - } - - log.Info("forge.FinalGoDepsCheck() worked :", check.GetGoPath()) okExit(check, "go.sum seems clean") } @@ -111,14 +106,3 @@ func saveAsMetadata(repo *gitpb.Repo) error { } return nil } - -func doMain(repo *gitpb.Repo) error { - if argv.Force { - err := doForce(repo) - return err - } - - // if --force or --strict is not set, fall back to a "smart" guess - // at what the user probably would want - return doSmart(repo) -} |
