realtime git clone. go.work paths work again

This commit is contained in:
Jeff Carr 2024-11-15 09:11:11 -06:00
parent dcf9f72264
commit bef6d6c911
2 changed files with 29 additions and 31 deletions

View File

@ -32,7 +32,8 @@ build-go-1.21:
@# GO111MODULE=off go build -v -ldflags "-X main.GUIVERSION=${VERSION}" @# GO111MODULE=off go build -v -ldflags "-X main.GUIVERSION=${VERSION}"
install: install:
GO111MODULE="off" go install -v GO111MODULE=off go install -v \
-ldflags "-X main.VERSION=${VERSION} -X gui.GUIVERSION=${VERSION}"
goimports: goimports:
goimports -w *.go goimports -w *.go

57
main.go
View File

@ -34,23 +34,33 @@ func main() {
log.Info(err) log.Info(err)
os.Exit(-1) os.Exit(-1)
} }
log.Info("scanning directory:", wdir) if wdir != "" {
os.Setenv("REPO_WORK_PATH", wdir) os.Setenv("REPO_WORK_PATH", wdir)
}
fullgitdir := filepath.Join(wdir, argv.Repo, ".git")
if shell.IsDir(fullgitdir) {
if ! argv.Recursive {
log.Info("repo already cloned", filepath.Join(wdir, argv.Repo))
os.Exit(0)
}
}
// readControlFile() // readControlFile()
b := gui.RawBox() b := gui.RawBox()
rv = repolist.AutotypistView(b) rv = repolist.AutotypistView(b)
log.Info("got here")
if argv.Pull { if argv.Pull {
count := scanForRepos(wdir) count := scanForRepos(wdir)
log.Info("Total repositories:", count) log.Info("Total repositories:", count)
log.Info("Going to run git pull in each one") log.Info("Going to run git pull in each one")
log.Sleep(1) log.Sleep(1)
pull := []string{"git", "pull"} pull := []string{"git", "pull"}
loop := rv.ReposSortByName()
var trycount, errcount int var trycount, errcount int
loop := rv.ReposSortByName()
for loop.Scan() { for loop.Scan() {
repo := loop.Repo() repo := loop.Repo()
if argv.DryRun { if argv.DryRun {
@ -82,10 +92,12 @@ func main() {
} }
newr.Status.MakeRedomod() newr.Status.MakeRedomod()
fullgitdir := filepath.Join(wdir, argv.Repo, ".git") fullgitdir = filepath.Join(wdir, argv.Repo, ".git")
if shell.IsDir(fullgitdir) { if shell.IsDir(fullgitdir) {
log.Info("repo already cloned", filepath.Join(wdir, argv.Repo)) if ! argv.Recursive {
os.Exit(0) log.Info("repo already cloned", filepath.Join(wdir, argv.Repo))
os.Exit(0)
}
} }
log.Info("scanning for repo in:", filepath.Join(wdir, argv.Repo)) log.Info("scanning for repo in:", filepath.Join(wdir, argv.Repo))
@ -111,7 +123,9 @@ func main() {
} }
var count int var count int
for _, repo := range rv.AllRepos() { loop := rv.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
count += 1 count += 1
if !repo.Status.Exists("go.mod") { if !repo.Status.Exists("go.mod") {
repo.Status.MakeRedomod() repo.Status.MakeRedomod()
@ -127,41 +141,24 @@ func main() {
} }
} }
// look for or make a go.work file // look for a go.work file
// otherwise use ~/go/src // otherwise use ~/go/src
func findWorkFile() (string, error) { func findWorkFile() (string, error) {
if argv.GoSrc {
// user put --go-src on the command line so use ~/go/src
return useGoSrc()
}
pwd, err := os.Getwd() pwd, err := os.Getwd()
if err == nil { if err == nil {
// Check for go.work in the current directory and then move up until root // Check for go.work in the current directory and then move up until root
if pwd, err := digup(pwd); err == nil { if pwd, err := digup(pwd); err == nil {
log.Info("using go.work file in directory", pwd)
// found an existing go.work file // found an existing go.work file
os.Chdir(pwd) os.Chdir(pwd)
return pwd, nil return pwd, nil
} }
// if the user added '--work' on the cmdline, make a work directory and init the go.work file
if !argv.NoWork {
pwd, err = os.Getwd()
newpwd := filepath.Join(pwd, "work")
shell.Mkdir(newpwd)
os.Chdir(newpwd)
if _, err := os.Stat("go.work"); err == nil {
return newpwd, nil
}
shell.PathRun(newpwd, []string{"go", "work", "init"})
if shell.Exists("go.work") {
return newpwd, nil
}
}
} }
// there are no go.work files, resume the ~/go/src behavior from prior to golang 1.22 // there are no go.work files, resume the ~/go/src behavior from prior to golang 1.22
return useGoSrc() pwd, err = useGoSrc()
log.Info("using ~/go/src directory", pwd)
return pwd, err
} }
// this is the 'old way" and works fine for me. I use it because I like the ~/go/src directory // this is the 'old way" and works fine for me. I use it because I like the ~/go/src directory