fix clone logic
This commit is contained in:
parent
9358005c9d
commit
94e98f2145
123
clone.go
123
clone.go
|
@ -75,82 +75,40 @@ func guessPaths(path string) (string, string, string, bool, error) {
|
||||||
return path, realpath, goSrcDir, isGoLang, nil
|
return path, realpath, goSrcDir, isGoLang, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// attempt to git clone if the go path doesn't exist
|
// TODO: make some config file for things like this
|
||||||
// wdir = /home/jcarr/go/src/
|
// can be used to work around temporary problems
|
||||||
// path = go.wit.com/apps/helloworld
|
func pathHack(gopath string) string {
|
||||||
func Clone(wdir string, path string) error {
|
switch gopath {
|
||||||
fullpath := filepath.Join(wdir, path)
|
case "golang.org/x/crypto":
|
||||||
if IsDirectory(fullpath) {
|
return "go.googlesource.com/crypto"
|
||||||
// directory already exists
|
case "golang.org/x/mod":
|
||||||
return nil
|
return "go.googlesource.com/mod"
|
||||||
}
|
case "golang.org/x/net":
|
||||||
err := os.Chdir(wdir)
|
return "go.googlesource.com/net"
|
||||||
if err != nil {
|
case "golang.org/x/sys":
|
||||||
return err
|
return "go.googlesource.com/sys"
|
||||||
|
case "golang.org/x/sync":
|
||||||
|
return "go.googlesource.com/sync"
|
||||||
|
case "golang.org/x/term":
|
||||||
|
return "go.googlesource.com/term"
|
||||||
|
case "golang.org/x/text":
|
||||||
|
return "go.googlesource.com/text"
|
||||||
|
case "golang.org/x/tools":
|
||||||
|
return "go.googlesource.com/tools"
|
||||||
|
case "golang.org/x/xerrors":
|
||||||
|
return "go.googlesource.com/xerrors"
|
||||||
}
|
}
|
||||||
|
|
||||||
fulldir := filepath.Join(wdir, filepath.Dir(path))
|
return gopath
|
||||||
/*
|
|
||||||
base := filepath.Base(path)
|
|
||||||
os.MkdirAll(fulldir, 0750)
|
|
||||||
err = os.Chdir(fulldir)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return CloneNew(fulldir, path)
|
|
||||||
|
|
||||||
/*
|
|
||||||
// TODO: this should go in a config file if needed
|
|
||||||
// todo: move this to a resources/ text file in go-clone
|
|
||||||
// go get golang.org/x/term
|
|
||||||
// is now supposed to be:
|
|
||||||
// git clone https://go.googlesource.com/term
|
|
||||||
// if url, err = findGoImport("http://" + path); err != nil {
|
|
||||||
switch path {
|
|
||||||
case "golang.org/x/crypto":
|
|
||||||
path = "go.googlesource.com/crypto"
|
|
||||||
case "golang.org/x/mod":
|
|
||||||
path = "go.googlesource.com/mod"
|
|
||||||
case "golang.org/x/net":
|
|
||||||
path = "go.googlesource.com/net"
|
|
||||||
case "golang.org/x/sys":
|
|
||||||
path = "go.googlesource.com/sys"
|
|
||||||
case "golang.org/x/sync":
|
|
||||||
path = "go.googlesource.com/sync"
|
|
||||||
case "golang.org/x/term":
|
|
||||||
path = "go.googlesource.com/term"
|
|
||||||
case "golang.org/x/text":
|
|
||||||
path = "go.googlesource.com/text"
|
|
||||||
case "golang.org/x/tools":
|
|
||||||
path = "go.googlesource.com/tools"
|
|
||||||
case "golang.org/x/xerrors":
|
|
||||||
path = "go.googlesource.com/xerrors"
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
var url string
|
|
||||||
|
|
||||||
// this creates a valid URL for git clone
|
|
||||||
if url, err = runGoList(path); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
log.Info("URL:", url)
|
|
||||||
shell.PathRunRealtime(fulldir, []string{"git", "clone", url, base})
|
|
||||||
if IsDirectory(fullpath) {
|
|
||||||
// clone worked
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return errors.New("resolve go import")
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// attempt to git clone if the go path doesn't exist
|
||||||
// does a git clone, if it works, returns true
|
// does a git clone, if it works, returns true
|
||||||
// workdir = /home/jcarr/go/src/
|
// workdir = /home/jcarr/go/src/
|
||||||
// gopath = go.wit.com/apps/helloworld
|
// gopath = go.wit.com/apps/helloworld
|
||||||
func CloneNew(workdir, gopath string) error {
|
func Clone(workdir, gopath string) error {
|
||||||
|
// temp hack to fix paths.
|
||||||
|
gopath = pathHack(gopath)
|
||||||
fullpath := filepath.Join(workdir, gopath)
|
fullpath := filepath.Join(workdir, gopath)
|
||||||
dirname := filepath.Base(fullpath)
|
dirname := filepath.Base(fullpath)
|
||||||
|
|
||||||
|
@ -160,9 +118,6 @@ func CloneNew(workdir, gopath string) error {
|
||||||
url := "http://" + gopath
|
url := "http://" + gopath
|
||||||
log.Info("trying git clone")
|
log.Info("trying git clone")
|
||||||
log.Info("gopath =", gopath)
|
log.Info("gopath =", gopath)
|
||||||
log.Info("dirname =", dirname)
|
|
||||||
log.Info("basedir =", basedir)
|
|
||||||
log.Info("url =", url)
|
|
||||||
|
|
||||||
// try a direct git clone against the gopath
|
// try a direct git clone against the gopath
|
||||||
// cloneActual("helloworld", "/home/jcarr/go/src/go.wit.com/apps", "http://go.wit.com/apps/helloworld")
|
// cloneActual("helloworld", "/home/jcarr/go/src/go.wit.com/apps", "http://go.wit.com/apps/helloworld")
|
||||||
|
@ -172,10 +127,21 @@ func CloneNew(workdir, gopath string) error {
|
||||||
}
|
}
|
||||||
log.Info("direct attempt at git clone failed", url)
|
log.Info("direct attempt at git clone failed", url)
|
||||||
|
|
||||||
|
// if direct git clone doesn't work, look for a redirect
|
||||||
|
// go directly to the URL as that is autoritive. If that failes
|
||||||
|
// try the go package system as maybe the git site no longer exists
|
||||||
|
if url, err = findGoImport(url); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := cloneActual(dirname, basedir, url); err == nil {
|
||||||
|
// git clone worked!
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// query the golang package system for the last known location
|
// query the golang package system for the last known location
|
||||||
// NOTE: take time to thank the go developers and google for designing this wonderful system
|
// NOTE: take time to thank the go developers and google for designing this wonderful system
|
||||||
if url, err = runGoList(gopath); err != nil {
|
if url, err = runGoList(gopath); err != nil {
|
||||||
return err
|
log.Info("go list failed", err)
|
||||||
}
|
}
|
||||||
if err := cloneActual(dirname, basedir, url); err == nil {
|
if err := cloneActual(dirname, basedir, url); err == nil {
|
||||||
// git clone worked!
|
// git clone worked!
|
||||||
|
@ -192,6 +158,9 @@ func CloneNew(workdir, gopath string) error {
|
||||||
// basedir = /home/jcarr/go/src/go.wit.com/apps
|
// basedir = /home/jcarr/go/src/go.wit.com/apps
|
||||||
// giturl = https://gitea.wit.com/gui/helloworld
|
// giturl = https://gitea.wit.com/gui/helloworld
|
||||||
func cloneActual(newdir, basedir, giturl string) error {
|
func cloneActual(newdir, basedir, giturl string) error {
|
||||||
|
log.Info("cloneActual() newdir =", newdir)
|
||||||
|
log.Info("cloneActual() basedir =", basedir)
|
||||||
|
log.Info("cloneActual() giturl =", giturl)
|
||||||
if !IsDirectory(basedir) {
|
if !IsDirectory(basedir) {
|
||||||
os.MkdirAll(basedir, 0750)
|
os.MkdirAll(basedir, 0750)
|
||||||
}
|
}
|
||||||
|
@ -201,7 +170,9 @@ func cloneActual(newdir, basedir, giturl string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
r := shell.PathRunRealtime(basedir, []string{"git", "clone", "--verbose", "--progress", giturl})
|
cmd := []string{"git", "clone", "--verbose", "--progress", giturl}
|
||||||
|
log.Info("Running:", cmd)
|
||||||
|
r := shell.PathRunRealtime(basedir, cmd)
|
||||||
if r.Error != nil {
|
if r.Error != nil {
|
||||||
log.Warn("git clone error", r.Error)
|
log.Warn("git clone error", r.Error)
|
||||||
return r.Error
|
return r.Error
|
||||||
|
@ -214,7 +185,7 @@ func cloneActual(newdir, basedir, giturl string) error {
|
||||||
}
|
}
|
||||||
gitdir := filepath.Join(fullpath, ".git")
|
gitdir := filepath.Join(fullpath, ".git")
|
||||||
if IsDirectory(gitdir) {
|
if IsDirectory(gitdir) {
|
||||||
log.Info("git clone worked", gitdir)
|
log.Info("git cloned worked to", fullpath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// git clone didn't really work but did make a directory
|
// git clone didn't really work but did make a directory
|
||||||
|
|
Loading…
Reference in New Issue