diff options
| author | Jeff Carr <[email protected]> | 2025-09-27 01:38:45 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-27 02:15:00 -0500 |
| commit | 8ba75466b1eb5ece93f50312eb811ecdcb8e9586 (patch) | |
| tree | 44c99c716a0d3f04b4797e81f68e7c60e5f559eb | |
| parent | 4285d240e406e1dc9a44c98a0b165a8c6f229ffd (diff) | |
does a repo scan
| -rw-r--r-- | doRepos.go | 93 | ||||
| -rw-r--r-- | forgeDir.go | 34 |
2 files changed, 89 insertions, 38 deletions
@@ -3,6 +3,7 @@ package main import ( "os" "path/filepath" + "strings" "time" "go.wit.com/lib/gui/shell" @@ -20,19 +21,30 @@ func doRepos() error { } if argv.Repos.Scan != nil { - return initForged() - // verifyForged() - // return nil + log.Infof("start repos scan repos.Len()=%d %s\n", me.forge.Repos.Len(), me.forge.Config.ReposDir) + _, err := scanForgedDir(me.forge.Config.ReposDir) + me.forge.SaveRepos() + return err } if argv.Repos.Reload != nil { - count := me.forge.RillReload() - if count != 0 { - me.forge.SaveRepos() - log.Infof("%d repos changed\n", count) - return nil + for repo := range me.forge.Repos.IterAll() { + if repo.GetMasterBranchName() == "" { + me.forge.VerifyBranchNames(repo) + log.Info("ABNORMAL: master branch name was blank in", repo.GetFullPath()) + } + } - log.Infof("no repos changed\n") + me.forge.SaveRepos() + /* + 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 } @@ -75,6 +87,7 @@ func doRepos() error { return nil } +/* func doReposInit() { log.Info("do pull here") dirs, err := scanForgedDir(me.forge.Config.ReposDir) @@ -119,6 +132,7 @@ func doReposInit() { } okExit("") } +*/ func tryGitClone(repo *gitpb.Repo, dir string) error { if err := forgepb.RunGitClone("git.clone", dir, "https://"+repo.Namespace); err == nil { @@ -137,6 +151,40 @@ func tryGitClone(repo *gitpb.Repo, dir string) error { return err } +// must be "/foo/bar/" + "git.clone/" and then have a .git/ dir +func addGitRepoDir(dir string) (bool, error) { + fullpath := filepath.Join(dir, "git.clone") + if check := me.forge.Repos.FindByFullPath(fullpath); check != nil { + // log.Info(oldr.Namespace, fullpath, "already added") + return false, nil + } + + var namespace string + if oldr, err := readGitPB(dir); err == nil { + namespace = oldr.Namespace + } else { + log.Info("readGitPB() failed", dir, err) + namespace = strings.TrimPrefix(dir, "/home/repos") + } + namespace = strings.Trim(namespace, "/") + + // check to see if 'git clone' has already been run + _, err := os.Stat(fullpath) + if os.IsNotExist(err) { + log.Info("repo needs cloning:", namespace, dir) + return false, err + } + if repo, err := me.forge.AddNamespaceDir(namespace, fullpath); err == nil { + log.Info("repo added", repo.FullPath) + return true, nil + } else { + log.Info("repo add failed", repo.FullPath, err) + return false, err + } + return false, err +} + +/* func initForged() error { var changed bool log.Info("do pull here") @@ -149,28 +197,12 @@ func initForged() error { 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 + ok, err := addGitRepoDir(fullpath); + if ok { + changed = true } - - oldr, err := readGitPB(dir) if err != nil { - log.Info("readGitPB() failed", dir, err) - 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 add failed", repo.FullPath, err) + log.Info("repo add problem", fullpath, err) } } if changed { @@ -178,6 +210,7 @@ func initForged() error { } return nil } +*/ func verifyForged() { var changed bool = false @@ -201,6 +234,7 @@ func verifyForged() { } } +/* func doReposList() error { log.Info("do pull here") dirs, err := scanForgedDir(me.forge.Config.ReposDir) @@ -242,3 +276,4 @@ func doReposList() error { } return nil } +*/ diff --git a/forgeDir.go b/forgeDir.go index 7d5a2a5..43a3c1a 100644 --- a/forgeDir.go +++ b/forgeDir.go @@ -11,15 +11,16 @@ import ( func readGitPB(fullpath string) (*gitpb.Repo, error) { // fmt.Fprintln(w, "repo:", repo.FullPath, repo.Namespace) - bytes, err := os.ReadFile(filepath.Join(fullpath, "git.pb")) + gitfile := filepath.Join(fullpath, "git.pb") + bytes, err := os.ReadFile(gitfile) if err != nil { - log.Info("todo: git.pb non-existant:", fullpath) + log.Info("todo: git.pb non-existant:", gitfile) return nil, err } newr := new(gitpb.Repo) if err := newr.Unmarshal(bytes); err != nil { - log.Info("todo: unmarshal failed for git.pb:", fullpath) - return nil, fmt.Errorf("todo: generate git.pb for " + fullpath) + log.Info("unmarshal failed: NEED TO DELETE:", gitfile) + return nil, fmt.Errorf("todo: re-generate git.pb for " + fullpath) } return newr, nil } @@ -32,12 +33,12 @@ func scanForgedDir(srcDir string) ([]string, error) { err := filepath.WalkDir(srcDir, func(path string, d os.DirEntry, err error) error { if err != nil { // Handle possible errors, like permission issues - fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err) + log.Infof("error accessing path %q: %v\n", path, err) return err } if d.IsDir() { - // log.Info("path is dir", path) + // log.Info("WHAT IS THIS?", path) } else { _, fname := filepath.Split(path) switch fname { @@ -56,12 +57,27 @@ func scanForgedDir(srcDir string) ([]string, error) { return nil } - gitdir := filepath.Join(path, "git.pb") - _, err2 := os.Stat(gitdir) + gitfile := filepath.Join(path, "git.pb") + _, err2 := os.Stat(gitfile) if !os.IsNotExist(err2) { - all = append(all, path) + log.Info("IS THIS THE ONE?", path) + if ok, err := addGitRepoDir(path); ok { + log.Info("added", path) + } else { + log.Info("err", path, err) + } return filepath.SkipDir } + // log.Info("BAD ?", path) + // all = append(all, path) + + /* + if ok, err := addGitRepoDir(path); ok { + log.Info("added", path) + } else { + log.Info("err", path, err) + } + */ // todo: check if dir is empty here and delete dir? return nil }) |
