From e3608b784e5e89e7501fb310d3b4e13ac6ef41ae Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 15 Dec 2024 12:14:36 -0600 Subject: [PATCH] trying to fix clone --- build.go | 1 + clone.go | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/build.go b/build.go index c630803..2457177 100644 --- a/build.go +++ b/build.go @@ -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 } } diff --git a/clone.go b/clone.go index 514624f..3d308a7 100644 --- a/clone.go +++ b/clone.go @@ -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