give up and make 3 different versions
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
6392687a63
commit
3b714282df
2
argv.go
2
argv.go
|
@ -13,7 +13,7 @@ type args struct {
|
||||||
Verbose bool `arg:"--verbose" help:"show more"`
|
Verbose bool `arg:"--verbose" help:"show more"`
|
||||||
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 things and redo them no matter what"`
|
||||||
Strict bool `arg:"--strict" default:"false" help:"never make go.* files unless everything is perfect"`
|
Strict bool `arg:"--strict" default:"false" help:"never make go.* files unless everything is perfect"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// this will make go.mod and go.sum files no matter what
|
||||||
|
// thsi will clean out everything and start over
|
||||||
|
func doForce(repo *gitpb.Repo) error {
|
||||||
|
// var perfect bool = true
|
||||||
|
if !repo.IsValid() {
|
||||||
|
log.Info(repo.GoPath, "is invalid. fix your repos.pb file with 'forge' first")
|
||||||
|
log.Info("")
|
||||||
|
log.Info("go install go.wit.com/apps/forge@latest")
|
||||||
|
log.Info("")
|
||||||
|
return errors.New(repo.GoPath + " is invalid. fix your repository list with 'forge' first")
|
||||||
|
}
|
||||||
|
log.Info(repo.GoPath, "is valid according to forge")
|
||||||
|
|
||||||
|
// purge the git meta-data if --force
|
||||||
|
repo.Run([]string{"git", "notes", "remove"})
|
||||||
|
|
||||||
|
// erase the go.mod and go.sum files
|
||||||
|
eraseGoMod(repo)
|
||||||
|
|
||||||
|
// actually will re-create go.sum and go.mod now
|
||||||
|
if err := redoGoMod(repo); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// the first time, it'll attempt to fix some stuff
|
||||||
|
cleanGoDepsCheckOk(repo)
|
||||||
|
|
||||||
|
// try to trim junk
|
||||||
|
if err := trimGoSum(repo); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
repo.ParseGoSum()
|
||||||
|
|
||||||
|
configSave = true
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"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 !repo.IsValid() {
|
||||||
|
log.Info(repo.GoPath, "is invalid. fix your repos.pb file with 'forge' first")
|
||||||
|
log.Info("")
|
||||||
|
log.Info("go install go.wit.com/apps/forge@latest")
|
||||||
|
log.Info("")
|
||||||
|
return errors.New(repo.GoPath + " is invalid. fix your repository list with 'forge' first")
|
||||||
|
}
|
||||||
|
log.Info(repo.GoPath, "is valid according to forge")
|
||||||
|
|
||||||
|
// if the repo has go.mod in the repo...
|
||||||
|
if err := repo.RepoIgnoresGoMod(); err != nil {
|
||||||
|
log.Info("never modify go.mod or go.sum for this repo", repo.GoPath)
|
||||||
|
log.Info("We recommend you add 'go.*' to your .gitignore file and store those files as git tag metadata")
|
||||||
|
repo.ParseGoSum()
|
||||||
|
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.GoPath, "files were restored ok from git metadata (notes)")
|
||||||
|
configSave = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// attempt to restore from ~/go/pkg/mod/
|
||||||
|
if err := restoreFromGoPkg(repo); err == nil {
|
||||||
|
configSave = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// actually will re-create go.sum and go.mod now
|
||||||
|
if err := redoGoMod(repo); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// the first time, it'll attempt to fix some stuff
|
||||||
|
cleanGoDepsCheckOk(repo)
|
||||||
|
// try to trim junk
|
||||||
|
if err := trimGoSum(repo); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
repo.ParseGoSum()
|
||||||
|
|
||||||
|
// everything worked more or less
|
||||||
|
configSave = true
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func doStrict(repo *gitpb.Repo) error {
|
||||||
|
if !repo.IsValid() {
|
||||||
|
log.Info(repo.GoPath, "is invalid. fix your repos.pb file with 'forge' first")
|
||||||
|
log.Info("")
|
||||||
|
log.Info("go install go.wit.com/apps/forge@latest")
|
||||||
|
log.Info("")
|
||||||
|
return errors.New(repo.GoPath + " is invalid. fix your repository list with 'forge' first")
|
||||||
|
}
|
||||||
|
log.Info(repo.GoPath, "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("")
|
||||||
|
return errors.New(repo.GoPath + " not in the git master branch")
|
||||||
|
}
|
||||||
|
|
||||||
|
err := repo.RepoIgnoresGoMod()
|
||||||
|
if err != nil {
|
||||||
|
log.Info(repo.GoPath, "some wierd git error happened. investigate.", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if forge.Config.IsReadOnly(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
|
||||||
|
}
|
||||||
|
|
||||||
|
if repo.CheckDirty() {
|
||||||
|
log.Info("")
|
||||||
|
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")
|
||||||
|
|
||||||
|
// actually will re-create go.sum and go.mod now
|
||||||
|
if err := redoGoMod(repo); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// the first time, it'll attempt to fix some stuff
|
||||||
|
cleanGoDepsCheckOk(repo)
|
||||||
|
// try to trim junk
|
||||||
|
if err := trimGoSum(repo); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
repo.ParseGoSum()
|
||||||
|
|
||||||
|
// check go.sum file
|
||||||
|
if err := cleanGoDepsCheckOk(repo); err != nil {
|
||||||
|
log.Info("forge.FinalGoDepsCheck() failed. boo. :", repo.GoPath)
|
||||||
|
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 {
|
||||||
|
log.Info("save go.mod as git metadata failed", repo.GoPath, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// everything worked!
|
||||||
|
configSave = true
|
||||||
|
return nil
|
||||||
|
}
|
140
main.go
140
main.go
|
@ -37,8 +37,14 @@ func main() {
|
||||||
all := forge.Repos.SortByGoPath()
|
all := forge.Repos.SortByGoPath()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
check = all.Next()
|
check = all.Next()
|
||||||
if err := doMain(check); err != nil {
|
if argv.Force {
|
||||||
badExit(check, err)
|
if err := doForce(check); err != nil {
|
||||||
|
// badExit(check, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := doSmart(check); err != nil {
|
||||||
|
// badExit(check, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -49,13 +55,19 @@ func main() {
|
||||||
badExit(nil, nil)
|
badExit(nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := doMain(check); err != nil {
|
if argv.Force {
|
||||||
badExit(check, err)
|
if err := doForce(check); err != nil {
|
||||||
|
badExit(check, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := doSmart(check); err != nil {
|
||||||
|
badExit(check, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if configSave {
|
if configSave {
|
||||||
// forge.ConfigSave()
|
forge.ConfigSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("forge.FinalGoDepsCheck() worked :", check.GoPath)
|
log.Info("forge.FinalGoDepsCheck() worked :", check.GoPath)
|
||||||
|
@ -128,121 +140,3 @@ func restoreFromGoPkg(repo *gitpb.Repo) error {
|
||||||
// try go.sum, but no error checking since it might not be there
|
// try go.sum, but no error checking since it might not be there
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func doMain(repo *gitpb.Repo) error {
|
|
||||||
var perfect bool = true
|
|
||||||
if !repo.IsValid() {
|
|
||||||
log.Info(repo.GoPath, "is invalid. fix your repos.pb file with 'forge' first")
|
|
||||||
log.Info("")
|
|
||||||
log.Info("go install go.wit.com/apps/forge@latest")
|
|
||||||
log.Info("")
|
|
||||||
return errors.New(repo.GoPath + " is invalid. fix your repository list with 'forge' first")
|
|
||||||
}
|
|
||||||
log.Info(repo.GoPath, "is valid according to forge")
|
|
||||||
|
|
||||||
// purge the git meta-data if --force
|
|
||||||
if argv.Force {
|
|
||||||
repo.Run([]string{"git", "notes", "remove"})
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := repo.RepoIgnoresGoMod(); err != nil {
|
|
||||||
log.Info("never modify go.mod or go.sum for this repo", repo.GoPath)
|
|
||||||
log.Info("We recommend you add 'go.*' to your .gitignore file and store those files as git tag metadata")
|
|
||||||
repo.ParseGoSum()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// erase the go.mod and go.sum files
|
|
||||||
eraseGoMod(repo)
|
|
||||||
|
|
||||||
if !argv.Strict {
|
|
||||||
if err := restoreFromGoPkg(repo); err == nil {
|
|
||||||
configSave = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to restore from the git metadata
|
|
||||||
cname := repo.GetCurrentBranchName()
|
|
||||||
if err := repo.AutogenRestore(cname); err == nil {
|
|
||||||
log.Info(repo.GoPath, "go.mod and go.sum were restored ok")
|
|
||||||
if !argv.Strict {
|
|
||||||
configSave = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if they were auto restored, one should exit here
|
|
||||||
if err := repo.ValidGoSum(); err == nil {
|
|
||||||
if !argv.Strict {
|
|
||||||
log.Info(repo.GoPath, "go.mod and go.sum were restored ok")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if repo.GetMasterBranchName() != repo.GetCurrentBranchName() {
|
|
||||||
perfect = false
|
|
||||||
if argv.Strict {
|
|
||||||
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("")
|
|
||||||
return errors.New(repo.GoPath + " not in the git master branch")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if repo.CheckDirty() {
|
|
||||||
perfect = false
|
|
||||||
if argv.Strict {
|
|
||||||
log.Info("")
|
|
||||||
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")
|
|
||||||
|
|
||||||
// actually will re-create go.sum and go.mod now
|
|
||||||
if err := redoGoMod(repo); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if argv.Trim {
|
|
||||||
// the first time, it'll attempt to fix some stuff
|
|
||||||
cleanGoDepsCheckOk(repo)
|
|
||||||
// try to trim junk
|
|
||||||
if err := trimGoSum(repo); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
repo.ParseGoSum()
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
data, _ := repo.ReadFile("go.mod")
|
|
||||||
log.Info(string(data))
|
|
||||||
data, _ = repo.ReadFile("go.sum")
|
|
||||||
log.Info(string(data))
|
|
||||||
*/
|
|
||||||
|
|
||||||
// check go.sum file
|
|
||||||
if err := cleanGoDepsCheckOk(repo); err != nil {
|
|
||||||
log.Info("forge.FinalGoDepsCheck() failed. boo. :", repo.GoPath)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// if everything is perfect, save them as git metadata
|
|
||||||
if perfect {
|
|
||||||
// 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 {
|
|
||||||
log.Info("save go.mod as git metadata failed", repo.GoPath, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// everything worked!
|
|
||||||
configSave = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue