diff options
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | argv.go | 1 | ||||
| -rw-r--r-- | doPull.go | 136 | ||||
| -rw-r--r-- | forgeDir.go | 2 | ||||
| -rw-r--r-- | main.go | 48 |
5 files changed, 147 insertions, 44 deletions
@@ -4,7 +4,9 @@ VERSION = $(shell git describe --tags) BUILDTIME = $(shell date +%Y.%m.%d_%H%M) all: build - ./forged pull + # ./forged pull + FORGE_GOSRC=/home/forge ./forged list + # ./forged list build: goimports GO111MODULE=off go build \ @@ -13,6 +13,7 @@ var argv args type args struct { Pull *EmptyCmd `arg:"subcommand:pull" help:"list the repos"` + List *EmptyCmd `arg:"subcommand:list" help:"list the repos"` Port int `arg:"--port" default:"2520" help:"port to run on"` Hostname string `arg:"--hostname" default:"forge.wit.com" help:"hostname to use"` } 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("") +} diff --git a/forgeDir.go b/forgeDir.go index c11554b..7d5a2a5 100644 --- a/forgeDir.go +++ b/forgeDir.go @@ -65,7 +65,7 @@ func scanForgedDir(srcDir string) ([]string, error) { // todo: check if dir is empty here and delete dir? return nil }) - // + // probably always leave this here forever // this check, along with CheckDirty() makes sure you can safely delete ~/go/src or the go.work directory // because everything is either checked in or deleted. An important thing to know! @@ -4,11 +4,8 @@ import ( "embed" "fmt" "net/http" - "os" - "path/filepath" "time" - "go.wit.com/lib/protobuf/forgepb" "go.wit.com/log" ) @@ -29,47 +26,14 @@ func main() { if argv.Hostname != "" { HOSTNAME = argv.Hostname } + + if argv.List != nil { + doList() + okExit("") + } // forge = forgepb.Init() if argv.Pull != nil { - 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 i, 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 - } - log.Info("repo:", repo.Namespace, repo.URL) - - // 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", dir) - if err := forgepb.RunGitClone("git.clone", dir, "https://"+repo.Namespace); err != nil { - log.Info("git clone failed", err) - if giturl, err := forgepb.FindGoImport("https://" + repo.Namespace); 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) - } - } - - } - } else { - log.Info("repo is already cloned", dir) - } - break - } + doPull() okExit("") } |
