fixing Init()
This commit is contained in:
parent
189d305fee
commit
cbdcfa0589
|
@ -0,0 +1,92 @@
|
||||||
|
package forgepb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"go.wit.com/lib/gui/repostatus"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (f *Forge) GitPull() bool {
|
||||||
|
var localonly int
|
||||||
|
var badmap int
|
||||||
|
|
||||||
|
log.Log(FORGEPBWARN, "running git pull everywhere")
|
||||||
|
var failed int = 0
|
||||||
|
loop := f.Repos.SortByGoPath()
|
||||||
|
for loop.Scan() {
|
||||||
|
repo := loop.Next()
|
||||||
|
if out, err := repo.GitPull(); err == nil {
|
||||||
|
log.Log(FORGEPBWARN, "Ran git pull ok", repo.GetGoPath(), out)
|
||||||
|
} else {
|
||||||
|
failed += 1
|
||||||
|
// repo.DumpTags()
|
||||||
|
if errors.Is(repostatus.ErrorGitPullOnLocal, err) {
|
||||||
|
localonly += 1
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
badmap += 1
|
||||||
|
log.Log(FORGEPBWARN, "bad unknown git error", repo.GetGoPath(), out, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Log(FORGEPBWARN, "Ran git pull in all repos. failure count =", failed)
|
||||||
|
log.Log(FORGEPBWARN, "Ran git pull in all repos. bad errors =", badmap)
|
||||||
|
if localonly != 0 {
|
||||||
|
log.Log(FORGEPBWARN, "Ran git pull in all repos. ignored local only branches =", localonly)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Forge) CheckoutDevel() bool {
|
||||||
|
log.Log(FORGEPBWARN, "running git checkout devel everwhere")
|
||||||
|
var failed int = 0
|
||||||
|
var count int = 0
|
||||||
|
loop := f.Repos.SortByGoPath()
|
||||||
|
for loop.Scan() {
|
||||||
|
repo := loop.Next()
|
||||||
|
count += 1
|
||||||
|
if repo.CheckoutDevel() {
|
||||||
|
// checkout ok
|
||||||
|
} else {
|
||||||
|
failed += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Log(FORGEPBWARN, "Ran git checkout in", count, "repos. failure count =", failed)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Forge) CheckoutMaster() bool {
|
||||||
|
log.Log(FORGEPBWARN, "running git checkout master everwhere")
|
||||||
|
var failed int = 0
|
||||||
|
var count int = 0
|
||||||
|
loop := f.Repos.SortByGoPath()
|
||||||
|
for loop.Scan() {
|
||||||
|
repo := loop.Next()
|
||||||
|
count += 1
|
||||||
|
if repo.CheckoutMaster() {
|
||||||
|
// checkout ok
|
||||||
|
} else {
|
||||||
|
failed += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Log(FORGEPBWARN, "Ran git checkout in", count, "repos. failure count =", failed)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Forge) CheckoutUser() bool {
|
||||||
|
log.Log(FORGEPBWARN, "running git checkout master everwhere")
|
||||||
|
var failed int = 0
|
||||||
|
var count int = 0
|
||||||
|
loop := f.Repos.SortByGoPath()
|
||||||
|
for loop.Scan() {
|
||||||
|
repo := loop.Next()
|
||||||
|
count += 1
|
||||||
|
if repo.CheckoutUser() {
|
||||||
|
// checkout ok
|
||||||
|
} else {
|
||||||
|
failed += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Log(FORGEPBWARN, "Ran git checkout in", count, "repos. failure count =", failed)
|
||||||
|
return true
|
||||||
|
}
|
36
goSrcScan.go
36
goSrcScan.go
|
@ -13,26 +13,36 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *Forge) ScanGoSrc() (bool, error) {
|
func (f *Forge) ScanGoSrc() (bool, error) {
|
||||||
log.Info("pre dir walk")
|
|
||||||
dirs, err := gitDirectoriesNew(f.goSrc)
|
dirs, err := gitDirectoriesNew(f.goSrc)
|
||||||
log.Info("post dir walk", len(dirs))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var gopaths []string
|
var gopaths []string
|
||||||
for _, dir := range dirs {
|
for _, dir := range dirs {
|
||||||
|
// log.Info("forge.ScanGoSrc()", dir)
|
||||||
if strings.HasPrefix(dir, f.goSrc) {
|
if strings.HasPrefix(dir, f.goSrc) {
|
||||||
gopath := strings.TrimPrefix(dir, f.goSrc)
|
gopath := strings.TrimPrefix(dir, f.goSrc)
|
||||||
gopath = strings.Trim(gopath, "/")
|
gopath = strings.Trim(gopath, "/")
|
||||||
|
if r := f.Repos.FindByGoPath(gopath); r != nil {
|
||||||
|
// log.Info("already have", gopath)
|
||||||
|
continue
|
||||||
|
}
|
||||||
gopaths = append(gopaths, gopath)
|
gopaths = append(gopaths, gopath)
|
||||||
} else {
|
} else {
|
||||||
log.Log(FORGEPBWARN, "ScanGoSrc() bad:", dir)
|
log.Log(FORGEPBWARN, "ScanGoSrc() bad:", dir)
|
||||||
return false, errors.New("forgepb.ScanGoSrc() bad dir: " + dir)
|
return false, errors.New("forgepb.ScanGoSrc() bad dir: " + dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Info("pre rill")
|
newcount, err := f.rillScanDirs(gopaths)
|
||||||
f.rillScanDirs(gopaths)
|
if err != nil {
|
||||||
|
log.Info("go src dir problem. exit for now?", err)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
if newcount != 0 {
|
||||||
|
log.Info("forge go src scan found", newcount, "repos")
|
||||||
|
f.Repos.ConfigSave()
|
||||||
|
}
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +57,13 @@ func gitDirectoriesNew(srcDir string) ([]string, error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.IsDir() {
|
||||||
|
// log.Info("path is dir", path)
|
||||||
|
} else {
|
||||||
|
log.Info("warning: you have an untracked file:", path)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
gitdir := filepath.Join(path, ".git")
|
gitdir := filepath.Join(path, ".git")
|
||||||
_, err2 := os.Stat(gitdir)
|
_, err2 := os.Stat(gitdir)
|
||||||
if !os.IsNotExist(err2) {
|
if !os.IsNotExist(err2) {
|
||||||
|
@ -118,24 +135,23 @@ func rillAddDirs(gopaths []string) {
|
||||||
|
|
||||||
// rill is awesome. long live rill
|
// rill is awesome. long live rill
|
||||||
// attempt scan with rill
|
// attempt scan with rill
|
||||||
func (f *Forge) rillScanDirs(gopaths []string) error {
|
func (f *Forge) rillScanDirs(gopaths []string) (int, error) {
|
||||||
// Convert a slice of user IDs into a channel
|
// Convert a slice of user IDs into a channel
|
||||||
ids := rill.FromSlice(gopaths, nil)
|
ids := rill.FromSlice(gopaths, nil)
|
||||||
|
|
||||||
// Read users from the API.
|
// Read users from the API.
|
||||||
// Concurrency = 20
|
// Concurrency = 20
|
||||||
dirs := rill.Map(ids, 20, func(id string) (*gitpb.Repo, error) {
|
dirs := rill.Map(ids, 20, func(id string) (*gitpb.Repo, error) {
|
||||||
return f.Repos.NewGoPath(f.goSrc, id)
|
return f.NewGoPathRepo(id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var counter int
|
||||||
// Activate users.
|
// Activate users.
|
||||||
// Concurrency = 10
|
// Concurrency = 10
|
||||||
err := rill.ForEach(dirs, 10, func(repo *gitpb.Repo) error {
|
err := rill.ForEach(dirs, 10, func(repo *gitpb.Repo) error {
|
||||||
// could do something here
|
counter += 1
|
||||||
// fmt.Printf("Repo found : %s\n", repo.GoPath)
|
|
||||||
// repo.Run([]string{"git", "pull"})
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return err
|
return counter, err
|
||||||
}
|
}
|
||||||
|
|
34
repoClone.go
34
repoClone.go
|
@ -80,7 +80,7 @@ func (f *Forge) guessPaths(path string) (string, string, string, bool, error) {
|
||||||
|
|
||||||
// TODO: make some config file for things like this
|
// TODO: make some config file for things like this
|
||||||
// can be used to work around temporary problems
|
// can be used to work around temporary problems
|
||||||
func clonePathHack(dirname string, basedir string, gopath string) error {
|
func clonePathHack(dirname string, basedir string, gopath string) (string, error) {
|
||||||
// newdir = helloworld
|
// newdir = helloworld
|
||||||
// basedir = /home/jcarr/go/src/go.wit.com/apps
|
// basedir = /home/jcarr/go/src/go.wit.com/apps
|
||||||
// giturl = https://gitea.wit.com/gui/helloworld
|
// giturl = https://gitea.wit.com/gui/helloworld
|
||||||
|
@ -117,7 +117,7 @@ func clonePathHack(dirname string, basedir string, gopath string) error {
|
||||||
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/appengine")
|
return cloneActual(dirname, basedir, "https://"+"go.googlesource.com/appengine")
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.New("no gopath override here")
|
return "", errors.New("no gopath override here")
|
||||||
}
|
}
|
||||||
|
|
||||||
// attempt to git clone if the go path doesn't exist
|
// attempt to git clone if the go path doesn't exist
|
||||||
|
@ -126,7 +126,7 @@ func clonePathHack(dirname string, basedir string, gopath string) error {
|
||||||
// gopath = go.wit.com/apps/helloworld
|
// gopath = go.wit.com/apps/helloworld
|
||||||
func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
|
func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
|
||||||
var err error
|
var err error
|
||||||
pb, err := f.Repos.NewGoPath(f.goSrc, gopath)
|
pb, err := f.Repos.NewGoPath(f.goSrc, gopath, "")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return pb, err
|
return pb, err
|
||||||
}
|
}
|
||||||
|
@ -142,9 +142,9 @@ func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
|
||||||
|
|
||||||
// try a direct git clone against the gopath
|
// try a direct git clone against the gopath
|
||||||
// cloneActual("helloworld", "/home/jcarr/go/src/go.wit.com/apps", "https://go.wit.com/apps/helloworld")
|
// cloneActual("helloworld", "/home/jcarr/go/src/go.wit.com/apps", "https://go.wit.com/apps/helloworld")
|
||||||
if err = cloneActual(dirname, basedir, url); err == nil {
|
if finalurl, err := cloneActual(dirname, basedir, url); err == nil {
|
||||||
// git clone worked!
|
// git clone worked!
|
||||||
return f.Repos.NewGoPath(f.goSrc, gopath)
|
return f.Repos.NewGoPath(f.goSrc, gopath, finalurl)
|
||||||
}
|
}
|
||||||
log.Info("direct attempt at git clone failed", url)
|
log.Info("direct attempt at git clone failed", url)
|
||||||
|
|
||||||
|
@ -155,9 +155,9 @@ func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
|
||||||
log.Info("findGoImport() DID NOT WORK", url)
|
log.Info("findGoImport() DID NOT WORK", url)
|
||||||
log.Info("findGoImport() DID NOT WORK", err)
|
log.Info("findGoImport() DID NOT WORK", err)
|
||||||
} else {
|
} else {
|
||||||
if err := cloneActual(dirname, basedir, url); err == nil {
|
if finalurl, err := cloneActual(dirname, basedir, url); err == nil {
|
||||||
// git clone worked!
|
// git clone worked!
|
||||||
return f.Repos.NewGoPath(f.goSrc, gopath)
|
return f.Repos.NewGoPath(f.goSrc, gopath, finalurl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Info("git clone from 'go-import' info failed", url)
|
log.Info("git clone from 'go-import' info failed", url)
|
||||||
|
@ -167,18 +167,18 @@ func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
|
||||||
if url, err = runGoList(gopath); err != nil {
|
if url, err = runGoList(gopath); err != nil {
|
||||||
log.Info("go list failed", err)
|
log.Info("go list failed", err)
|
||||||
} else {
|
} else {
|
||||||
if err := cloneActual(dirname, basedir, url); err == nil {
|
if finalurl, err := cloneActual(dirname, basedir, url); err == nil {
|
||||||
// git clone worked!
|
// git clone worked!
|
||||||
return f.Repos.NewGoPath(f.goSrc, gopath)
|
return f.Repos.NewGoPath(f.goSrc, gopath, finalurl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Info("git clone from 'git list' info failed", url)
|
log.Info("git clone from 'git list' info failed", url)
|
||||||
|
|
||||||
// try to parse a redirect
|
// try to parse a redirect
|
||||||
|
|
||||||
if err = clonePathHack(dirname, basedir, gopath); err == nil {
|
if finalurl, err := clonePathHack(dirname, basedir, gopath); err == nil {
|
||||||
// WTF didn't go-import or go list work?
|
// WTF didn't go-import or go list work?
|
||||||
return f.Repos.NewGoPath(f.goSrc, gopath)
|
return f.Repos.NewGoPath(f.goSrc, gopath, finalurl)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("can not find git sources for gopath " + gopath)
|
return nil, errors.New("can not find git sources for gopath " + gopath)
|
||||||
|
@ -187,7 +187,7 @@ func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
|
||||||
// newdir = helloworld
|
// newdir = helloworld
|
||||||
// basedir = /home/jcarr/go/src/go.wit.com/apps
|
// basedir = /home/jcarr/go/src/go.wit.com/apps
|
||||||
// giturl = https://gitea.wit.com/gui/helloworld
|
// giturl = https://gitea.wit.com/gui/helloworld
|
||||||
func cloneActual(newdir, basedir, giturl string) error {
|
func cloneActual(newdir, basedir, giturl string) (string, error) {
|
||||||
log.Info("cloneActual() newdir =", newdir)
|
log.Info("cloneActual() newdir =", newdir)
|
||||||
log.Info("cloneActual() basedir =", basedir)
|
log.Info("cloneActual() basedir =", basedir)
|
||||||
log.Info("cloneActual() giturl =", giturl)
|
log.Info("cloneActual() giturl =", giturl)
|
||||||
|
@ -197,7 +197,7 @@ func cloneActual(newdir, basedir, giturl string) error {
|
||||||
err := os.Chdir(basedir)
|
err := os.Chdir(basedir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("chdir failed", basedir, err)
|
log.Warn("chdir failed", basedir, err)
|
||||||
return err
|
return giturl, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := []string{"git", "clone", "--verbose", "--progress", giturl, newdir}
|
cmd := []string{"git", "clone", "--verbose", "--progress", giturl, newdir}
|
||||||
|
@ -205,22 +205,22 @@ func cloneActual(newdir, basedir, giturl string) error {
|
||||||
r := shell.PathRunRealtime(basedir, cmd)
|
r := shell.PathRunRealtime(basedir, cmd)
|
||||||
if r.Error != nil {
|
if r.Error != nil {
|
||||||
log.Warn("git clone error", r.Error)
|
log.Warn("git clone error", r.Error)
|
||||||
return r.Error
|
return giturl, r.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
fullpath := filepath.Join(basedir, newdir)
|
fullpath := filepath.Join(basedir, newdir)
|
||||||
if !IsDirectory(fullpath) {
|
if !IsDirectory(fullpath) {
|
||||||
log.Info("git clone failed", giturl)
|
log.Info("git clone failed", giturl)
|
||||||
return errors.New("git clone failed " + giturl)
|
return giturl, errors.New("git clone failed " + giturl)
|
||||||
}
|
}
|
||||||
gitdir := filepath.Join(fullpath, ".git")
|
gitdir := filepath.Join(fullpath, ".git")
|
||||||
if IsDirectory(gitdir) {
|
if IsDirectory(gitdir) {
|
||||||
log.Info("git cloned worked to", fullpath)
|
log.Info("git cloned worked to", fullpath)
|
||||||
return nil
|
return giturl, nil
|
||||||
}
|
}
|
||||||
// git clone didn't really work but did make a directory
|
// git clone didn't really work but did make a directory
|
||||||
log.Info("fullpath is probably empty", fullpath)
|
log.Info("fullpath is probably empty", fullpath)
|
||||||
return errors.New("crapnuts. rmdir fullpath here? " + fullpath)
|
return giturl, errors.New("crapnuts. rmdir fullpath here? " + fullpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the server for the current go path to git url mapping
|
// check the server for the current go path to git url mapping
|
||||||
|
|
39
repoNew.go
39
repoNew.go
|
@ -6,44 +6,15 @@ import (
|
||||||
"go.wit.com/lib/protobuf/gitpb"
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
func (f *Forge) NewGoPathRepo(gopath string) (*gitpb.Repo, error) {
|
||||||
func (f *Forge) NewGoPath(gopath string) (*gitpb.Repo, error) {
|
repo, err := f.Repos.NewGoPath(f.GetGoSrc(), gopath, "")
|
||||||
newr, err := f.Repos.NewGoPath(f.goSrc, gopath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log(FORGEPBWARN, "init failed", err)
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Info("init worked for", newr.GoPath)
|
f.VerifyBranchNames(repo)
|
||||||
// try to guess what the 'master' branch is
|
repo.ParseGoSum()
|
||||||
if newr.IsBranch("guimaster") {
|
return repo, nil
|
||||||
newr.SetMasterBranchName("guimaster")
|
|
||||||
} else if newr.IsBranch("master") {
|
|
||||||
newr.SetMasterBranchName("master")
|
|
||||||
} else if newr.IsBranch("main") {
|
|
||||||
newr.SetMasterBranchName("main")
|
|
||||||
} else {
|
|
||||||
newr.SetMasterBranchName("masterFIXME")
|
|
||||||
}
|
|
||||||
|
|
||||||
if newr.IsBranch("guidevel") {
|
|
||||||
newr.SetDevelBranchName("guidevel")
|
|
||||||
} else if newr.IsBranch("devel") {
|
|
||||||
newr.SetDevelBranchName("devel")
|
|
||||||
} else {
|
|
||||||
newr.SetDevelBranchName("develFIXME")
|
|
||||||
}
|
|
||||||
|
|
||||||
usr, _ := user.Current()
|
|
||||||
uname := usr.Username
|
|
||||||
if newr.IsBranch(uname) {
|
|
||||||
newr.SetUserBranchName(uname)
|
|
||||||
} else {
|
|
||||||
newr.SetUserBranchName(uname + "FIXME")
|
|
||||||
}
|
|
||||||
f.Repos.ConfigSave()
|
|
||||||
return newr, err
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
func (f *Forge) VerifyBranchNames(newr *gitpb.Repo) {
|
func (f *Forge) VerifyBranchNames(newr *gitpb.Repo) {
|
||||||
// log.Info("init worked for", newr.GoPath)
|
// log.Info("init worked for", newr.GoPath)
|
||||||
|
|
Loading…
Reference in New Issue