From e6be71a33caf7dba9d4060231bd34586aeb41fe2 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 9 Mar 2024 09:23:04 -0600 Subject: [PATCH] git clone deps --- main.go | 36 ++++++++++++++++++++++++++++-------- readWorkFile.go | 6 ++++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index a37f07f..fb1f6b6 100644 --- a/main.go +++ b/main.go @@ -4,10 +4,12 @@ import ( "fmt" "os" "path/filepath" + "strings" "go.wit.com/dev/alexflint/arg" "go.wit.com/gui" "go.wit.com/lib/gui/repolist" + "go.wit.com/lib/gui/repostatus" "go.wit.com/lib/gui/shell" "go.wit.com/log" ) @@ -51,10 +53,23 @@ func main() { newr.Status.MakeRedomod() // rv.NewRepo("go.wit.com/apps/helloworld") + for _, path := range repostatus.ScanGitDirectories(wdir) { + gopath := strings.TrimPrefix(path, wdir) + gopath = strings.Trim(gopath, "/") + // log.Info("Also should add:", gopath) + rv.NewRepo(gopath) + } + + godep := newr.Status.GetGoDeps() + for gopath, version := range godep { + log.Info("git clone =", gopath, version) + rv.NewRepo(gopath) + } for _, repo := range rv.AllRepos() { log.Info("found repo", repo.GoPath(), repo.Status.Path()) } + rv.MakeGoWork() // rv.Watchdog(func() { // log.Info("watchdog") @@ -76,26 +91,31 @@ func findWorkFile() (string, error) { pwd, err := os.Getwd() if err == nil { // Check for go.work in the current directory and then move up until root - pwd, err = digup(pwd) - if err == nil { + if pwd, err := digup(pwd); err == nil { + // found an existing go.work file os.Chdir(pwd) return pwd, nil } + // if the user added '--work' on the cmdline, make a work directory and init the go.work file if myargs.Work { - pwd := filepath.Join(pwd, "work") - shell.Mkdir(pwd) - os.Chdir(pwd) + pwd, err = os.Getwd() + newpwd := filepath.Join(pwd, "work") + shell.Mkdir(newpwd) + os.Chdir(newpwd) if _, err := os.Stat("go.work"); err == nil { - return pwd, nil + return newpwd, nil } - shell.RunPath(pwd, []string{"go", "work", "init"}) + shell.RunPath(newpwd, []string{"go", "work", "init"}) if shell.Exists("go.work") { - return pwd, nil + return newpwd, nil } } } + // there are no go.work files, resume the ~/go/src behavior from prior to golang 1.22 + // this is the 'old way" and works fine for me. I use it because I like the ~/go/src directory + // because I know exactly what is in it: GO stuff & nothing else homeDir, err := os.UserHomeDir() if err != nil { return "", err diff --git a/readWorkFile.go b/readWorkFile.go index e11ad90..3383a82 100644 --- a/readWorkFile.go +++ b/readWorkFile.go @@ -3,6 +3,7 @@ package main import ( "bufio" "os" + "path/filepath" "strings" "go.wit.com/lib/gui/shell" @@ -15,8 +16,9 @@ func addDir(d string) { } } -func readControlFile() error { - file, err := os.Open("go.work") +func readControlFile(path string) error { + fullname := filepath.Join(path, "go.work") + file, err := os.Open(fullname) if err != nil { return err }