start cleaning up git interactions

This commit is contained in:
Jeff Carr 2024-12-17 00:00:27 -06:00
parent a9286af8fd
commit 075fce61e5
3 changed files with 18 additions and 13 deletions

View File

@ -60,18 +60,17 @@ func clonePathHack(dirname string, basedir string, gopath string) (string, error
// attempt to git clone if the go path doesn't exist // attempt to git clone if the go path doesn't exist
// does a git clone, if it works, returns true // does a git clone, if it works, returns true
// workdir = /home/jcarr/go/src/
// 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, "") fullpath := filepath.Join(f.goSrc, gopath)
if err == nil {
return f.finishClone(gopath, pb.URL)
}
workdir := f.goSrc
fullpath := filepath.Join(workdir, gopath)
dirname := filepath.Base(fullpath)
if pb := f.Repos.FindByFullPath(fullpath); pb != nil {
// repo already exists
return pb, nil
}
dirname := filepath.Base(fullpath)
basedir := strings.TrimSuffix(fullpath, dirname) basedir := strings.TrimSuffix(fullpath, dirname)
url := "https://" + gopath url := "https://" + gopath
@ -123,7 +122,7 @@ func (f *Forge) finishClone(gopath string, giturl string) (*gitpb.Repo, error) {
var err error var err error
newr := f.Repos.FindByGoPath(gopath) newr := f.Repos.FindByGoPath(gopath)
if newr == nil { if newr == nil {
newr, err = f.Repos.NewGoPath(f.goSrc, gopath, giturl) newr, err = f.NewGoRepo(gopath, giturl)
} }
if newr == nil { if newr == nil {
log.Warn("forge.Clone() new repo can not be found or created for gopath", gopath) log.Warn("forge.Clone() new repo can not be found or created for gopath", gopath)

View File

@ -68,6 +68,9 @@ func gitDirectoriesNew(srcDir string) ([]string, error) {
case "go.work.last": case "go.work.last":
default: default:
// todo: figure out a way to do padding for init() // todo: figure out a way to do padding for init()
if trip == false {
log.Info("WARNING:")
}
log.Info("WARNING: you have an untracked file outside of any .git repository:", path) log.Info("WARNING: you have an untracked file outside of any .git repository:", path)
trip = true trip = true
} }
@ -141,7 +144,7 @@ func (f *Forge) rillScanDirs(gopaths []string) (int, error) {
// 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.NewGoPathRepo(id) return f.NewGoRepo(id, "")
}) })
var counter int var counter int

View File

@ -3,19 +3,22 @@ package forgepb
import ( import (
"fmt" "fmt"
"os/user" "os/user"
"path/filepath"
"strings" "strings"
"go.wit.com/lib/protobuf/gitpb" "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log" "go.wit.com/log"
) )
func (f *Forge) NewGoPathRepo(gopath string) (*gitpb.Repo, error) { func (f *Forge) NewGoRepo(gopath string, url string) (*gitpb.Repo, error) {
repo, err := f.Repos.NewGoPath(f.GetGoSrc(), gopath, "") fullpath := filepath.Join(f.GetGoSrc(), gopath)
repo, err := f.Repos.NewGoRepo(fullpath, gopath)
if err != nil { if err != nil {
return nil, err return nil, err
} }
repo.URL = url
f.VerifyBranchNames(repo) f.VerifyBranchNames(repo)
repo.ParseGoSum() repo.Reload()
return repo, nil return repo, nil
} }