diff options
| author | Jeff Carr <[email protected]> | 2025-09-26 06:05:21 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-26 06:07:33 -0500 |
| commit | e41cf6f043e3475c74b3376d80d2294d9a6e72df (patch) | |
| tree | 14f9c4afda3d74e443f9dc4eab5cdd7cbc4e2426 /doRepos.go | |
| parent | 95663ece2bdfaad9edcd64045005f1cde6c15e2a (diff) | |
Diffstat (limited to 'doRepos.go')
| -rw-r--r-- | doRepos.go | 89 |
1 files changed, 78 insertions, 11 deletions
@@ -3,7 +3,9 @@ package main import ( "os" "path/filepath" + "time" + "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" @@ -13,9 +15,58 @@ func doRepos() error { if argv.Repos.List != nil { me.forge.PrintForgedTable(me.forge.Repos) // return doReposList() + return nil + } + + if argv.Repos.Scan != nil { + return initForged() + // verifyForged() + // return nil + } + + if argv.Repos.Reload != nil { + count := me.forge.RillReload() + if count != 0 { + me.forge.SaveRepos() + log.Infof("%d repos changed\n", count) + return nil + } + log.Infof("no repos changed\n") + return nil + } + + if argv.Repos.Pull != nil { + var count int + for repo := range me.forge.Repos.IterAll() { + dur := repo.GitPullAge() + if dur < time.Hour { + continue + } + count += 1 + log.Infof("%s %s git pull\n", shell.FormatDuration(dur), repo.FullPath) + if stats := repo.RunRealtimeVerbose([]string{"git", "fetch", "origin"}); stats.Error != nil { + log.Infof("%s %s failed %v\n", shell.FormatDuration(dur), repo.FullPath, stats.Error) + } + /* + if _, err := repo.GitPull(); err != nil { + log.Infof("%s %s failed %v\n", shell.FormatDuration(dur), repo.FullPath, err) + repo.RunVerbose([]string{"git", "remote", "prune", "origin"}) + } + */ + if count > 70 { + break + } + } + if count != 0 { + me.forge.SaveRepos() + } + return nil } log.Infof("Repos len=%d\n", me.forge.Repos.Len()) + if me.forge.Repos.Len() < 2 { + return nil + } found := gitpb.NewRepos() found.Append(me.forge.Repos.Repos[0]) found.Append(me.forge.Repos.Repos[1]) @@ -86,6 +137,7 @@ func tryGitClone(repo *gitpb.Repo, dir string) error { } func initForged() error { + var changed bool log.Info("do pull here") dirs, err := scanForgedDir(me.forge.Config.ReposDir) if err != nil { @@ -95,43 +147,58 @@ func initForged() error { // me.forge.PrintHumanTable(me.forge.Repos) for _, dir := range dirs { + fullpath := filepath.Join(dir, "git.clone") + if check := me.forge.Repos.FindByFullPath(fullpath); check != nil { + // log.Info(oldr.Namespace, fullpath, "already added") + continue + } + oldr, err := readGitPB(dir) if err != nil { log.Info("readGitPB() failed", dir, err) continue } - fullpath := filepath.Join(dir, "git.clone") - - if check := me.forge.Repos.FindByFullPath(fullpath); check != nil { - // log.Info(oldr.Namespace, fullpath, "already added") - continue - } // check to see if 'git clone' has already been run _, err = os.Stat(fullpath) if os.IsNotExist(err) { log.Info("repo needs cloning:", oldr.Namespace, oldr.FullPath, dir) + continue + } + if repo, err := me.forge.AddNamespaceDir(oldr.Namespace, fullpath); err == nil { + log.Info("repo added", repo.FullPath) + changed = true } else { - log.Info("repo is already cloned", dir, oldr.Namespace) + log.Info("repo add failed", repo.FullPath, err) } } + if changed { + me.forge.SaveRepos() + } return nil } -/* func verifyForged() { var changed bool = false for repo := range me.forge.Repos.IterAll() { - // do something + // check to see if 'git clone' has already been run + _, err := os.Stat(repo.FullPath) + if os.IsNotExist(err) { + log.Info("repo no longer exists", repo.FullPath, err) me.forge.Repos.Delete(repo) changed = true + continue + } + if err != nil { + log.Info("repo has some other error", repo.FullPath, err) + continue } + // repo is fine } if changed { - f.Repos.ConfigSave() + me.forge.Repos.ConfigSave(me.forge.Config.ReposPB) } } -*/ func doReposList() error { log.Info("do pull here") |
