diff options
Diffstat (limited to 'doPull.go')
| -rw-r--r-- | doPull.go | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/doPull.go b/doPull.go new file mode 100644 index 0000000..0558b8f --- /dev/null +++ b/doPull.go @@ -0,0 +1,136 @@ +package main + +import ( + "os" + "path/filepath" + + "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func doPull() { + log.Info("do pull here") + dirs, err := scanForgedDir(FORGEDIR) + if err != nil { + badExit(err) + } + os.Chdir(FORGEDIR) + forge := forgepb.InitPB() + log.Info("forge len", forge.Repos.Len()) + forge.PrintHumanTable(forge.Repos) + + for _, dir := range dirs { + // log.Info("found repo", i, dir) + // repo, err := forge.AddNamespaceDir(ns string, fullpath string) + repo, err := readGitPB(dir) + if err != nil { + log.Info(dir, err) + continue + } + + // check to see if 'git clone' has already been run + _, err = os.Stat(filepath.Join(dir, "git.clone")) + if os.IsNotExist(err) { + log.Info("repo needs cloning:", repo.Namespace, repo.URL, dir) + if err := tryGitClone(repo, dir); err == nil { + continue + } + + // check for GO lang specific 'git clone' redirects + if pkgurl, err := forgepb.RunGoList(repo.Namespace); err == nil { + log.Info("NEED TO TRY", pkgurl) + // if repo, err := f.urlClone(gopath, pkgurl); repo != nil { + // return repo, err + // } + if err := forgepb.RunGitClone("git.clone", dir, pkgurl); err == nil { + } else { + badExit(err) + } + } else { + badExit(err) + } + } else { + // log.Info("repo is already cloned", dir, repo.Namespace) + } + } + okExit("") +} + +func tryGitClone(repo *gitpb.Repo, dir string) error { + if err := forgepb.RunGitClone("git.clone", dir, "https://"+repo.Namespace); err == nil { + return nil + } + giturl, err := forgepb.FindGoImport("https://" + repo.Namespace) + if err == nil { + log.Info("TRY THIS INSTEAD!!!!", giturl) + if err := forgepb.RunGitClone("git.clone", dir, giturl); err != nil { + log.Info("git clone still failed", giturl, err) + return err + } + return nil + } + log.Info("git clone failed", err) + return err +} + +func doList() { + log.Info("do pull here") + dirs, err := scanForgedDir(FORGEDIR) + if err != nil { + badExit(err) + } + os.Chdir(FORGEDIR) + forge := forgepb.InitPB() + log.Info("forge len", forge.Repos.Len()) + forge.PrintHumanTable(forge.Repos) + + count := 0 + for _, dir := range dirs { + // log.Info("found repo", i, dir) + // repo, err := forge.AddNamespaceDir(ns string, fullpath string) + oldr, err := readGitPB(dir) + if err != nil { + log.Info(dir, err) + continue + } + + fullpath := filepath.Join(dir, "git.clone") + + if check := 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, repo.URL, dir) + } else { + log.Info("repo is already cloned", dir, oldr.Namespace) + newr, err := forge.Repos.NewGoRepo(fullpath, oldr.Namespace) + if err != nil { + log.Info("repo add failed", err) + } + log.Info("REPO namespace:", newr.Namespace) + log.Info("REPO fullpath:", newr.FullPath) + log.Info("REPO URL:", newr.URL) + os.Chdir(newr.FullPath) + newr.Reload() + log.Info("NEWR namespace:", newr.Namespace) + log.Info("NEWR fullpath:", newr.FullPath) + log.Info("NEWR Master Branch:", newr.GetMasterBranchName()) + log.Info("NEWR URL:", newr.URL) + log.Info("repo scan worked", newr.Namespace, newr.GetMasterBranchName(), newr.URL) + // forge.Repos.Append(newr) + // break + if count > 50 { + // break + } + count += 1 + } + } + forge.PrintHumanTable(forge.Repos) + forge.Repos.ConfigSave() + okExit("") +} |
