summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-15 09:11:11 -0600
committerJeff Carr <[email protected]>2024-11-15 09:11:11 -0600
commitbef6d6c911acacceeef8390c8e8d9d91584f7a61 (patch)
tree68788a646f150aacf4c6861e05c31e111c712c70 /main.go
parentdcf9f72264f99babcddd8f2ece3ce88b11966032 (diff)
realtime git clone. go.work paths work again
Diffstat (limited to 'main.go')
-rw-r--r--main.go57
1 files changed, 27 insertions, 30 deletions
diff --git a/main.go b/main.go
index 8c29b2d..26cff91 100644
--- a/main.go
+++ b/main.go
@@ -34,23 +34,33 @@ func main() {
log.Info(err)
os.Exit(-1)
}
- log.Info("scanning directory:", wdir)
- os.Setenv("REPO_WORK_PATH", wdir)
+ if 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()
b := gui.RawBox()
rv = repolist.AutotypistView(b)
- log.Info("got here")
if argv.Pull {
count := scanForRepos(wdir)
log.Info("Total repositories:", count)
log.Info("Going to run git pull in each one")
log.Sleep(1)
pull := []string{"git", "pull"}
- loop := rv.ReposSortByName()
+
var trycount, errcount int
+ loop := rv.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
if argv.DryRun {
@@ -82,10 +92,12 @@ func main() {
}
newr.Status.MakeRedomod()
- fullgitdir := filepath.Join(wdir, argv.Repo, ".git")
+ fullgitdir = filepath.Join(wdir, argv.Repo, ".git")
if shell.IsDir(fullgitdir) {
- log.Info("repo already cloned", filepath.Join(wdir, argv.Repo))
- os.Exit(0)
+ if ! argv.Recursive {
+ log.Info("repo already cloned", filepath.Join(wdir, argv.Repo))
+ os.Exit(0)
+ }
}
log.Info("scanning for repo in:", filepath.Join(wdir, argv.Repo))
@@ -111,7 +123,9 @@ func main() {
}
var count int
- for _, repo := range rv.AllRepos() {
+ loop := rv.ReposSortByName()
+ for loop.Scan() {
+ repo := loop.Repo()
count += 1
if !repo.Status.Exists("go.mod") {
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
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()
if err == nil {
// Check for go.work in the current directory and then move up until root
if pwd, err := digup(pwd); err == nil {
+ log.Info("using go.work file in directory", pwd)
// 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 !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
- 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