diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 89 |
1 files changed, 27 insertions, 62 deletions
@@ -1,9 +1,7 @@ package main import ( - "errors" "os" - "path/filepath" "strings" "go.wit.com/dev/alexflint/arg" @@ -33,35 +31,37 @@ func main() { // this lets you configure repos you have read/write access too forge = forgepb.Init() - if argv.All { - // run this on every single repo - // do this before publishing new golang versions - all := forge.Repos.SortByFullPath() - for all.Scan() { - check = all.Next() - if err := doMain(check); err != nil { - badExit(check, err) - } - } - } else { - // figure out what directory we are running in - check = findPwdRepo() - if check == nil { - log.Info("this directory isn't in a golang project (not in ~/go/src nor a go.work file)") - badExit(nil, nil) + // figure out what directory we are running in + check = findPwdRepo() + if check == nil { + log.Info("this directory isn't in a golang project (not in ~/go/src nor a go.work file)") + badExit(nil, nil) + } + + // deletes all the git notes + if argv.Purge { + purgeNotes(check) + okExit(check, "notes gone") + } + + if argv.Restore { + // attempt to restore from ~/go/pkg/mod/ + if err := restoreFromGoPkg(check); err != nil { + badExit(check, err) } + okExit(check, "go.mod and go.sum restored from ~/go/pkg/mod/") + } - if err := doMain(check); err != nil { + if err := doMain(check); err != nil { + badExit(check, err) + } + if argv.Force { + if err := doForce(check); err != nil { badExit(check, err) } - if argv.Force { - if err := doForce(check); err != nil { - badExit(check, err) - } - } else { - if err := doSmart(check); err != nil { - badExit(check, err) - } + } else { + if err := doSmart(check); err != nil { + badExit(check, err) } } @@ -105,41 +105,6 @@ func saveAsMetadata(repo *gitpb.Repo) error { return nil } -func restoreFromGoPkg(repo *gitpb.Repo) error { - homedir, err := os.UserHomeDir() - if err != nil { - badExit(nil, err) - } - rver := repo.GetMasterVersion() - if rver == "" { - return errors.New("could not get master version") - } - modfile := filepath.Join(homedir, "go/pkg/mod", repo.GetGoPath()+"@"+rver, "go.mod") - log.Info("mod path should be", modfile) - data, err := os.ReadFile(modfile) - if err != nil { - return err - } - modf, err := os.OpenFile("go.mod", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) - if err != nil { - return err - } - defer modf.Close() - modf.Write(data) - - modfile = filepath.Join(homedir, "go/pkg/mod", repo.GetGoPath()+"@"+rver, "go.sum") - log.Info("mod path should be", modfile) - data, err = os.ReadFile(modfile) - if err == nil { - sumf, _ := os.OpenFile("go.sum", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) - defer sumf.Close() - sumf.Write(data) - } - - // try go.sum, but no error checking since it might not be there - return nil -} - func doMain(repo *gitpb.Repo) error { if argv.Strict { return doStrict(repo) |
