gitpb/repo.new.go

78 lines
2.1 KiB
Go
Raw Normal View History

2024-11-27 14:41:57 -06:00
package gitpb
import (
"errors"
"os"
2024-11-27 14:41:57 -06:00
"path/filepath"
"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.
func (all *Repos) NewGoPath(basepath string, gopath string, url 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)
log.Info("gitpb.NewGoPath() already has URL", r.URL)
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)
}
log.Info("gitpb.NewGoPath() Attempting to add new path", basepath, gopath)
// if .git doesn't exist, error out here
gitpath := filepath.Join(basepath, gopath, ".git")
_, err := os.Stat(gitpath)
if err != nil {
log.Warn("gitpb.NewGoPath() not a git directory", gitpath)
return nil, err
2024-11-27 14:41:57 -06:00
}
2024-11-27 14:41:57 -06:00
// add a new one here
newr := Repo{
FullPath: filepath.Join(basepath, gopath),
GoPath: gopath,
URL: url,
2024-11-27 14:41:57 -06:00
}
newr.Tags = new(GitTags)
2024-11-29 15:47:23 -06:00
// newr.UpdateGit()
newr.UpdateGitTags()
newr.GoDeps = new(GoDeps)
// newr.RedoGoMod()
2024-12-01 16:04:07 -06:00
switch newr.goListRepoType() {
case "plugin":
newr.GoPlugin = true
case "protobuf":
newr.GoProtobuf = true
case "library":
newr.GoLibrary = true
case "binary":
newr.GoBinary = true
}
2024-11-27 14:41:57 -06:00
if all.AppendUniqueGoPath(&newr) {
// worked
return &newr, nil
}
2024-12-07 16:50:26 -06:00
if r := all.FindByGoPath(gopath); r != nil {
// already had this gopath
return r, errors.New("gitpb.NewGoPath() AppendUnique() failed but Find() worked" + gopath)
}
return nil, errors.New("repo gitpb.NewGoPath() should never have gotten here " + gopath)
2024-11-29 21:51:30 -06:00
}
func (repo *Repo) SetDevelBranchName(bname string) {
repo.DevelBranchName = bname
}
func (repo *Repo) SetUserBranchName(bname string) {
repo.UserBranchName = bname
}