fixes for new gitpb

This commit is contained in:
Jeff Carr 2024-12-17 07:03:07 -06:00
parent c9f1624a72
commit 62ad7e676c
6 changed files with 37 additions and 37 deletions

View File

@ -23,7 +23,7 @@ func cleanGoDepsCheckOk(check *gitpb.Repo) error {
all := check.GoDeps.SortByGoPath() all := check.GoDeps.SortByGoPath()
for all.Scan() { for all.Scan() {
depRepo := all.Next() depRepo := all.Next()
found := forge.Repos.FindByGoPath(depRepo.GetGoPath()) found := forge.Repos.FindByFullPath(depRepo.GetGoPath())
if found == nil { if found == nil {
if forge.CheckOverride(depRepo.GetGoPath()) { if forge.CheckOverride(depRepo.GetGoPath()) {
// skip this gopath because it's probably broken forever // skip this gopath because it's probably broken forever
@ -35,13 +35,13 @@ func cleanGoDepsCheckOk(check *gitpb.Repo) error {
} }
// log.Info("found dep", depRepo.GetGoPath()) // log.Info("found dep", depRepo.GetGoPath())
if depRepo.GetVersion() != found.GetMasterVersion() { if depRepo.GetVersion() != found.GetMasterVersion() {
check := forge.Repos.FindByGoPath(depRepo.GoPath) check := forge.Repos.FindByFullPath(depRepo.GetGoPath())
var ends string var ends string
if check.CheckDirty() { if check.CheckDirty() {
ends = "(dirty) " ends = "(dirty) "
} }
if forge.Config.IsReadOnly(check.GoPath) { if forge.Config.IsReadOnly(check.GetGoPath()) {
ends += "(ignoring read-only) " ends += "(ignoring read-only) "
if argv.Verbose { if argv.Verbose {
log.Printf("%-48s ok error .%s. vs .%s. %s", depRepo.GetGoPath(), log.Printf("%-48s ok error .%s. vs .%s. %s", depRepo.GetGoPath(),
@ -143,7 +143,7 @@ func trimGoSum(check *gitpb.Repo) error {
if good[gopath] { if good[gopath] {
fmt.Fprintf(newf, "%s %s\n", gopath, stuff[gopath]) fmt.Fprintf(newf, "%s %s\n", gopath, stuff[gopath])
fmt.Fprintf(newf, "%s %s\n", gopath, modver[gopath]) fmt.Fprintf(newf, "%s %s\n", gopath, modver[gopath])
check := forge.Repos.FindByGoPath(gopath) check := forge.Repos.FindByFullPath(gopath)
if check == nil { if check == nil {
log.Info("gopath does not really exist:", gopath) log.Info("gopath does not really exist:", gopath)
} }

View File

@ -12,13 +12,13 @@ import (
func doForce(repo *gitpb.Repo) error { func doForce(repo *gitpb.Repo) error {
// var perfect bool = true // var perfect bool = true
if !repo.IsValidDir() { if !repo.IsValidDir() {
log.Info(repo.GoPath, "is invalid. fix your repos.pb file with 'forge' first") log.Info(repo.GetGoPath(), "is invalid. fix your repos.pb file with 'forge' first")
log.Info("") log.Info("")
log.Info("go install go.wit.com/apps/forge@latest") log.Info("go install go.wit.com/apps/forge@latest")
log.Info("") log.Info("")
return errors.New(repo.GoPath + " is invalid. fix your repository list with 'forge' first") return errors.New(repo.GetGoPath() + " is invalid. fix your repository list with 'forge' first")
} }
log.Info(repo.GoPath, "is valid according to forge") log.Info(repo.GetGoPath(), "is valid according to forge")
// purge the git meta-data if --force // purge the git meta-data if --force
repo.Run([]string{"git", "notes", "remove"}) repo.Run([]string{"git", "notes", "remove"})

View File

@ -11,17 +11,17 @@ import (
// have the files in .gitignore for now // have the files in .gitignore for now
func doSmart(repo *gitpb.Repo) error { func doSmart(repo *gitpb.Repo) error {
if !repo.IsValidDir() { if !repo.IsValidDir() {
log.Info(repo.GoPath, "is invalid. fix your repos.pb file with 'forge' first") log.Info(repo.GetGoPath(), "is invalid. fix your repos.pb file with 'forge' first")
log.Info("") log.Info("")
log.Info("go install go.wit.com/apps/forge@latest") log.Info("go install go.wit.com/apps/forge@latest")
log.Info("") log.Info("")
return errors.New(repo.GoPath + " is invalid. fix your repository list with 'forge' first") return errors.New(repo.GetGoPath() + " is invalid. fix your repository list with 'forge' first")
} }
log.Info(repo.GoPath, "is valid according to forge") log.Info(repo.GetGoPath(), "is valid according to forge")
// if the repo has go.mod in the repo... // if the repo has go.mod in the repo...
if err := repo.RepoIgnoresGoMod(); err != nil { if err := repo.RepoIgnoresGoMod(); err != nil {
log.Info("never modify go.mod or go.sum for this repo", repo.GoPath) log.Info("never modify go.mod or go.sum for this repo", repo.GetGoPath())
log.Info("We recommend you add 'go.*' to your .gitignore file and store those files as git tag metadata") log.Info("We recommend you add 'go.*' to your .gitignore file and store those files as git tag metadata")
repo.ParseGoSum() repo.ParseGoSum()
return nil return nil
@ -33,7 +33,7 @@ func doSmart(repo *gitpb.Repo) error {
// try to restore from the git metadata // try to restore from the git metadata
cname := repo.GetCurrentBranchName() cname := repo.GetCurrentBranchName()
if err := repo.AutogenRestore(cname); err == nil { if err := repo.AutogenRestore(cname); err == nil {
log.Info(repo.GoPath, "files were restored ok from git metadata (notes)") log.Info(repo.GetGoPath(), "files were restored ok from git metadata (notes)")
configSave = true configSave = true
return nil return nil
} }

View File

@ -9,13 +9,13 @@ import (
func doStrict(repo *gitpb.Repo) error { func doStrict(repo *gitpb.Repo) error {
if !repo.IsValidDir() { if !repo.IsValidDir() {
log.Info(repo.GoPath, "is invalid. fix your repos.pb file with 'forge' first") log.Info(repo.GetGoPath(), "is invalid. fix your repos.pb file with 'forge' first")
log.Info("") log.Info("")
log.Info("go install go.wit.com/apps/forge@latest") log.Info("go install go.wit.com/apps/forge@latest")
log.Info("") log.Info("")
return errors.New(repo.GoPath + " is invalid. fix your repository list with 'forge' first") return errors.New(repo.GetGoPath() + " is invalid. fix your repository list with 'forge' first")
} }
log.Info(repo.GoPath, "is valid according to forge") log.Info(repo.GetGoPath(), "is valid according to forge")
repo.Run([]string{"git", "notes", "remove"}) repo.Run([]string{"git", "notes", "remove"})
@ -27,17 +27,17 @@ func doStrict(repo *gitpb.Repo) error {
log.Info("You are not operating on your git master branch.") 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("Publishing go.mod & go.sum files must come from from git version tag on the master branch")
log.Info("") log.Info("")
return errors.New(repo.GoPath + " not in the git master branch") return errors.New(repo.GetGoPath() + " not in the git master branch")
} }
err := repo.RepoIgnoresGoMod() err := repo.RepoIgnoresGoMod()
if err != nil { if err != nil {
log.Info(repo.GoPath, "some wierd git error happened. investigate.", err) log.Info(repo.GetGoPath(), "some wierd git error happened. investigate.", err)
return err return err
} }
if forge.Config.IsReadOnly(repo.GoPath) { if forge.Config.IsReadOnly(repo.GetGoPath()) {
log.Info("you can not push to read only repositories.", repo.GoPath) log.Info("you can not push to read only repositories.", repo.GetGoPath())
log.Info("change your .config/forge/ to indicate you own this repository") log.Info("change your .config/forge/ to indicate you own this repository")
return nil return nil
} }
@ -46,10 +46,10 @@ func doStrict(repo *gitpb.Repo) error {
log.Info("") log.Info("")
log.Info("You can not continue on a dirty git repo.") log.Info("You can not continue on a dirty git repo.")
log.Info("") log.Info("")
return errors.New(repo.GoPath + " git repo is dirty") return errors.New(repo.GetGoPath() + " git repo is dirty")
} }
log.Info(repo.GoPath, "GOING TO MAKE NEW go.* FILES") log.Info(repo.GetGoPath(), "GOING TO MAKE NEW go.* FILES")
// actually will re-create go.sum and go.mod now // actually will re-create go.sum and go.mod now
if err := redoGoMod(repo); err != nil { if err := redoGoMod(repo); err != nil {
@ -66,7 +66,7 @@ func doStrict(repo *gitpb.Repo) error {
// check go.sum file // check go.sum file
if err := cleanGoDepsCheckOk(repo); err != nil { if err := cleanGoDepsCheckOk(repo); err != nil {
log.Info("forge.FinalGoDepsCheck() failed. boo. :", repo.GoPath) log.Info("forge.FinalGoDepsCheck() failed. boo. :", repo.GetGoPath())
return err return err
} }
@ -74,7 +74,7 @@ func doStrict(repo *gitpb.Repo) error {
// this way, git commits are not messed up // this way, git commits are not messed up
// with this autogenerated code // with this autogenerated code
if err := saveAsMetadata(repo); err != nil { if err := saveAsMetadata(repo); err != nil {
log.Info("save go.mod as git metadata failed", repo.GoPath, err) log.Info("save go.mod as git metadata failed", repo.GetGoPath(), err)
return err return err
} }

14
main.go
View File

@ -34,7 +34,7 @@ func main() {
if argv.All { if argv.All {
// run this on every single repo // run this on every single repo
// do this before publishing new golang versions // do this before publishing new golang versions
all := forge.Repos.SortByGoPath() all := forge.Repos.SortByFullPath()
for all.Scan() { for all.Scan() {
check = all.Next() check = all.Next()
if err := doMain(check); err != nil { if err := doMain(check); err != nil {
@ -67,7 +67,7 @@ func main() {
forge.ConfigSave() forge.ConfigSave()
} }
log.Info("forge.FinalGoDepsCheck() worked :", check.GoPath) log.Info("forge.FinalGoDepsCheck() worked :", check.GetGoPath())
okExit(check, "go.sum seems clean") okExit(check, "go.sum seems clean")
} }
@ -80,9 +80,9 @@ func findPwdRepo() *gitpb.Repo {
gopath := strings.TrimPrefix(pwd, forge.GetGoSrc()) gopath := strings.TrimPrefix(pwd, forge.GetGoSrc())
gopath = strings.Trim(gopath, "/") gopath = strings.Trim(gopath, "/")
log.Info("findRepo() trying gopath", gopath) log.Info("findRepo() trying gopath", gopath)
check = forge.Repos.FindByGoPath(gopath) check = forge.Repos.FindByFullPath(gopath)
if check != nil { if check != nil {
log.Info("findRepo() worked", check.GoPath) log.Info("findRepo() worked", check.GetGoPath())
return check return check
} }
} }
@ -91,7 +91,7 @@ func findPwdRepo() *gitpb.Repo {
func saveAsMetadata(repo *gitpb.Repo) error { func saveAsMetadata(repo *gitpb.Repo) error {
cname := repo.GetCurrentBranchName() cname := repo.GetCurrentBranchName()
if repo.GoPrimitive { if repo.GoInfo.GoPrimitive {
if err := repo.AutogenSave([]string{"go.mod"}, cname, true); err != nil { if err := repo.AutogenSave([]string{"go.mod"}, cname, true); err != nil {
return err return err
} }
@ -112,7 +112,7 @@ func restoreFromGoPkg(repo *gitpb.Repo) error {
if rver == "" { if rver == "" {
return errors.New("could not get master version") return errors.New("could not get master version")
} }
modfile := filepath.Join(homedir, "go/pkg/mod", repo.GoPath+"@"+rver, "go.mod") modfile := filepath.Join(homedir, "go/pkg/mod", repo.GetGoPath()+"@"+rver, "go.mod")
log.Info("mod path should be", modfile) log.Info("mod path should be", modfile)
data, err := os.ReadFile(modfile) data, err := os.ReadFile(modfile)
if err != nil { if err != nil {
@ -125,7 +125,7 @@ func restoreFromGoPkg(repo *gitpb.Repo) error {
defer modf.Close() defer modf.Close()
modf.Write(data) modf.Write(data)
modfile = filepath.Join(homedir, "go/pkg/mod", repo.GoPath+"@"+rver, "go.sum") modfile = filepath.Join(homedir, "go/pkg/mod", repo.GetGoPath()+"@"+rver, "go.sum")
log.Info("mod path should be", modfile) log.Info("mod path should be", modfile)
data, err = os.ReadFile(modfile) data, err = os.ReadFile(modfile)
if err == nil { if err == nil {

View File

@ -15,7 +15,7 @@ import (
func eraseGoMod(repo *gitpb.Repo) { func eraseGoMod(repo *gitpb.Repo) {
// unset the go development ENV var to generate release files // unset the go development ENV var to generate release files
if err := repo.StrictRun([]string{"rm", "-f", "go.mod", "go.sum"}); err != nil { if err := repo.StrictRun([]string{"rm", "-f", "go.mod", "go.sum"}); err != nil {
log.Warn(repo.GoPath, "rm go.mod go.sum failed", err) log.Warn(repo.GetGoPath(), "rm go.mod go.sum failed", err)
} }
} }
@ -23,7 +23,7 @@ func eraseGoMod(repo *gitpb.Repo) {
func setGoVersion(repo *gitpb.Repo, version string) error { func setGoVersion(repo *gitpb.Repo, version string) error {
// most things should build with golang after 1.21 // most things should build with golang after 1.21
if err := repo.StrictRun([]string{"go", "mod", "edit", "-go=" + version}); err != nil { if err := repo.StrictRun([]string{"go", "mod", "edit", "-go=" + version}); err != nil {
log.Warn(repo.GoPath, "go mod edit failed", err) log.Warn(repo.GetGoPath(), "go mod edit failed", err)
return err return err
} }
return nil return nil
@ -37,7 +37,7 @@ func redoGoMod(repo *gitpb.Repo) error {
log.Warn("rm go.mod go.sum failed", err) log.Warn("rm go.mod go.sum failed", err)
return err return err
} }
if err := repo.StrictRun([]string{"go", "mod", "init", repo.GoPath}); err != nil { if err := repo.StrictRun([]string{"go", "mod", "init", repo.GetGoPath()}); err != nil {
log.Warn("go mod init failed", err) log.Warn("go mod init failed", err)
return err return err
} }
@ -48,12 +48,12 @@ func redoGoMod(repo *gitpb.Repo) error {
// most things should build with golang after 1.21 // todo: allow this to be set somewhere // most things should build with golang after 1.21 // todo: allow this to be set somewhere
if err := setGoVersion(repo, "1.21"); err != nil { if err := setGoVersion(repo, "1.21"); err != nil {
log.Warn(repo.GoPath, "go mod edit failed", err) log.Warn(repo.GetGoPath(), "go mod edit failed", err)
return err return err
} }
repo.GoDeps = nil repo.GoDeps = nil
repo.GoPrimitive = false repo.GoInfo.GoPrimitive = false
// if there is not a go.sum file, it better be a primitive golang project // if there is not a go.sum file, it better be a primitive golang project
if !repo.Exists("go.sum") { if !repo.Exists("go.sum") {
@ -61,13 +61,13 @@ func redoGoMod(repo *gitpb.Repo) error {
ok, err := repo.IsPrimitive() ok, err := repo.IsPrimitive()
if err != nil { if err != nil {
// this means this repo does not depend on any other package // this means this repo does not depend on any other package
log.Info("PRIMATIVE repo error:", repo.GoPath, "err =", err) log.Info("PRIMATIVE repo error:", repo.GetGoPath(), "err =", err)
return err return err
} }
if ok { if ok {
// this means the repo is primitive so there is no go.sum // this means the repo is primitive so there is no go.sum
repo.GoPrimitive = true repo.GoInfo.GoPrimitive = true
repo.GoDeps = new(gitpb.GoDeps) repo.GoDeps = new(gitpb.GoDeps)
return nil return nil
} }