summaryrefslogtreecommitdiff
path: root/repo.new.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-27 21:40:06 -0600
committerJeff Carr <[email protected]>2024-11-27 21:40:06 -0600
commited3eacfe75e479e8c36cf7ba82a431c567f83602 (patch)
tree450d0cc89758efd161c426868d6cbc6e4ef470d0 /repo.new.go
parent8b987962ea21a827d50e7f7430ab58b47274ad0e (diff)
first attempt that seems to kinda work on New()
Diffstat (limited to 'repo.new.go')
-rw-r--r--repo.new.go54
1 files changed, 51 insertions, 3 deletions
diff --git a/repo.new.go b/repo.new.go
index c7f000f..bab2b25 100644
--- a/repo.new.go
+++ b/repo.new.go
@@ -1,7 +1,13 @@
package gitpb
import (
+ "bufio"
+ "errors"
+ "os"
"path/filepath"
+ "strings"
+
+ "go.wit.com/log"
)
// scans in a new git repo. If it detects the repo is a golang project,
@@ -9,11 +15,19 @@ 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 {
+func (all *Repos) NewGoPath(basepath string, gopath string) (*Repo, error) {
if r := all.FindByGoPath(gopath); r != nil {
// already had this gopath
- return r
+ return r, nil
+ }
+
+ // if .git doesn't exist, error out here
+ gitpath := filepath.Join(basepath, gopath, ".git")
+ _, err := os.Stat(gitpath)
+ if err != nil {
+ return nil, err
}
+
// add a new one here
newr := Repo{
FullPath: filepath.Join(basepath, gopath),
@@ -22,5 +36,39 @@ func (all *Repos) NewGoPath(basepath string, gopath string) *Repo {
newr.UpdateGit()
all.add(&newr)
- return &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")
+ }
+
+ }
+ }
+ return true, nil
}