trying to fix clone

This commit is contained in:
Jeff Carr 2024-12-15 12:14:36 -06:00
parent 340872788e
commit e3608b784e
2 changed files with 24 additions and 13 deletions

View File

@ -47,6 +47,7 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err
if f.IsGoWork() {
// there must be a valid go.mod file if compiling with go.work
if err := repo.ValidGoSum(); err != nil {
log.Warn("forge.doBuild() failed. run go-mod-clean here?")
return err
}
}

View File

@ -66,7 +66,7 @@ func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
var err error
pb, err := f.Repos.NewGoPath(f.goSrc, gopath, "")
if err == nil {
return pb, err
return f.finishClone(gopath, pb.URL)
}
workdir := f.goSrc
fullpath := filepath.Join(workdir, gopath)
@ -81,9 +81,7 @@ func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
// try a direct git clone against the gopath
// cloneActual("helloworld", "/home/jcarr/go/src/go.wit.com/apps", "https://go.wit.com/apps/helloworld")
if finalurl, err := cloneActual(dirname, basedir, url); err == nil {
f.Repos.DeleteByGoPath(gopath)
// git clone worked!
return f.Repos.NewGoPath(f.goSrc, gopath, finalurl)
return f.finishClone(gopath, finalurl)
}
log.Info("direct attempt at git clone failed", url)
@ -95,9 +93,7 @@ func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
log.Info("findGoImport() DID NOT WORK", err)
} else {
if finalurl, err := cloneActual(dirname, basedir, url); err == nil {
f.Repos.DeleteByGoPath(gopath)
// git clone worked!
return f.Repos.NewGoPath(f.goSrc, gopath, finalurl)
return f.finishClone(gopath, finalurl)
}
}
log.Info("git clone from 'go-import' info failed", url)
@ -108,9 +104,7 @@ func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
log.Info("go list failed", err)
} else {
if finalurl, err := cloneActual(dirname, basedir, url); err == nil {
f.Repos.DeleteByGoPath(gopath)
// git clone worked!
return f.Repos.NewGoPath(f.goSrc, gopath, finalurl)
return f.finishClone(gopath, finalurl)
}
}
log.Info("git clone from 'git list' info failed", url)
@ -118,14 +112,30 @@ func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
// try to parse a redirect
if finalurl, err := clonePathHack(dirname, basedir, gopath); err == nil {
f.Repos.DeleteByGoPath(gopath)
// WTF didn't go-import or go list work?
return f.Repos.NewGoPath(f.goSrc, gopath, finalurl)
return f.finishClone(gopath, finalurl)
}
return nil, errors.New("can not find git sources for gopath " + gopath)
}
// actually does something smart
func (f *Forge) finishClone(gopath string, giturl string) (*gitpb.Repo, error) {
var err error
newr := f.Repos.FindByGoPath(gopath)
if newr == nil {
newr, err = f.Repos.NewGoPath(f.goSrc, gopath, giturl)
}
if newr == nil {
log.Warn("forge.Clone() new repo can not be found or created for gopath", gopath)
return nil, err
}
if newr.URL != giturl {
log.Warn("forge.Clone() url changed", newr.URL, "to", giturl)
newr.URL = giturl
}
return newr, nil
}
// newdir = helloworld
// basedir = /home/jcarr/go/src/go.wit.com/apps
// giturl = https://gitea.wit.com/gui/helloworld