gitpb/repo.new.go

48 lines
1.4 KiB
Go
Raw Normal View History

2024-11-27 14:41:57 -06:00
package gitpb
import (
"errors"
"go.wit.com/log"
2024-11-27 14:41:57 -06:00
)
// scans in a new git repo. If it detects the repo is a golang project,
// then it parses the go.mod/go.sum files
// TODO: try adding python, rails, perl, rust, other language things?
// I probably will never have time to try that, but I'd take patches for anyone
// that might see this note and feel so inclined.
2024-12-17 00:00:49 -06:00
// todo: use Repos.Lock() ?
func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) {
if gopath == "" {
return nil, errors.New("blank gopath")
}
2024-11-27 14:55:39 -06:00
if r := all.FindByGoPath(gopath); r != nil {
log.Info("gitpb.NewGoPath() already has gopath", r.GoPath)
log.Info("gitpb.NewGoPath() already has FullPath", r.FullPath)
2024-11-27 14:41:57 -06:00
// already had this gopath
2024-12-07 16:50:26 -06:00
return r, errors.New("gitpb.NewGoPath() duplicate gopath " + gopath)
}
2024-11-27 14:41:57 -06:00
// add a new one here
newr := Repo{
2024-12-17 00:00:49 -06:00
FullPath: fullpath,
}
2024-12-17 01:15:31 -06:00
newr.Times = new(GitTimes)
2024-12-17 00:00:49 -06:00
newr.GoInfo = new(GoInfo)
newr.GoInfo.GoPath = gopath
if all.AppendUniqueGoPath(&newr) {
// worked
return &newr, nil
} else {
// this is dumb, probably never happens. todo: use Repos.Lock()
if r := all.FindByGoPath(gopath); r != nil {
// already had this gopath
return r, errors.New("gitpb.NewGoPath() AppendUnique() failed but Find() worked" + gopath)
}
}
// todo: use Repos.Lock()
2024-12-07 16:50:26 -06:00
return nil, errors.New("repo gitpb.NewGoPath() should never have gotten here " + gopath)
2024-11-29 21:51:30 -06:00
}