diff options
| author | Jeff Carr <[email protected]> | 2024-12-03 00:35:50 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-12-03 00:35:50 -0600 |
| commit | 1d1d8e7eea642cd3fc546101b4899ec1db81e3b7 (patch) | |
| tree | 0a313aa1a49b1aeaacfc3df802171193ed76a324 /repo.new.go | |
| parent | 7a90613c91fa5c06b6fbe5a7a6e48fbba722877d (diff) | |
lots of code hopefully better than before
Diffstat (limited to 'repo.new.go')
| -rw-r--r-- | repo.new.go | 60 |
1 files changed, 16 insertions, 44 deletions
diff --git a/repo.new.go b/repo.new.go index dc7f17e..9404d7b 100644 --- a/repo.new.go +++ b/repo.new.go @@ -1,11 +1,9 @@ package gitpb import ( - "bufio" "errors" "os" "path/filepath" - "strings" "go.wit.com/log" ) @@ -15,16 +13,21 @@ import ( // 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) (*Repo, error) { +func (all *Repos) NewGoPath(basepath string, gopath string, url string) (*Repo, error) { + if gopath == "" { + return nil, errors.New("blank gopath") + } if r := all.FindByGoPath(gopath); r != nil { // already had this gopath - return r, nil + return nil, errors.New("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 } @@ -32,6 +35,7 @@ func (all *Repos) NewGoPath(basepath string, gopath string) (*Repo, error) { newr := Repo{ FullPath: filepath.Join(basepath, gopath), GoPath: gopath, + URL: url, } newr.Tags = new(GitTags) // newr.UpdateGit() @@ -40,53 +44,21 @@ func (all *Repos) NewGoPath(basepath string, gopath string) (*Repo, error) { // newr.RedoGoMod() switch newr.goListRepoType() { + case "plugin": + newr.GoPlugin = true + case "protobuf": + newr.GoProtobuf = true case "library": newr.GoLibrary = true case "binary": newr.GoBinary = true } - all.AppendUniqueGoPath(&newr) - return &newr, nil -} - -// Detect a 'Primative' package. Sets the isPrimative flag -// will return true if the repo is truly not dependent on _anything_ else -// like spew or lib/widget -// it assumes go mod ran init and tidy ran without error -func (repo *Repo) isPrimativeGoMod() (bool, error) { - // go mod init & go mod tidy ran without errors - log.Log(GITPB, "isPrimativeGoMod()", repo.FullPath) - tmp := filepath.Join(repo.FullPath, "go.mod") - gomod, err := os.Open(tmp) - if err != nil { - log.Log(GITPB, "missing go.mod", repo.FullPath) - repo.GoDeps = nil - return false, err - } - defer gomod.Close() - - scanner := bufio.NewScanner(gomod) - for scanner.Scan() { - line := strings.TrimSpace(scanner.Text()) - - parts := strings.Split(line, " ") - log.Log(GITPB, " gomod:", parts) - if len(parts) >= 1 { - log.Log(GITPB, " gomod: part[0] =", parts[0]) - if parts[0] == "require" { - log.Log(GITPB, " should return false here") - return false, errors.New("go.mod file is not primative") - } - - } + if all.AppendUniqueGoPath(&newr) { + // worked + return &newr, nil } - repo.GoPrimitive = true - return true, nil -} - -func (repo *Repo) SetMasterBranchName(bname string) { - repo.MasterBranchName = bname + return nil, errors.New("repo already exists: " + gopath) } func (repo *Repo) SetDevelBranchName(bname string) { |
