summaryrefslogtreecommitdiff
path: root/new.go
diff options
context:
space:
mode:
Diffstat (limited to 'new.go')
-rw-r--r--new.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/new.go b/new.go
index fc7a6b1..b523c44 100644
--- a/new.go
+++ b/new.go
@@ -84,7 +84,11 @@ func guessPaths(path string) (string, string, string, bool, error) {
}
if os.Getenv("REPO_AUTO_CLONE") == "true" {
- clone(goSrcDir, path)
+ err := Clone(goSrcDir, path)
+ if err != nil {
+ // directory doesn't exist. exit with nil and error nil
+ return path, realpath, goSrcDir, false, errors.New("git clone")
+ }
}
if !IsDirectory(realpath) {
@@ -105,7 +109,7 @@ func guessPaths(path string) (string, string, string, bool, error) {
}
// attempt to git clone if the go path doesn't exist
-func clone(wdir string, path string) error {
+func Clone(wdir string, path string) error {
fullpath := filepath.Join(wdir, path)
if IsDirectory(fullpath) {
// directory already exists
@@ -116,13 +120,14 @@ func clone(wdir string, path string) error {
return err
}
- base := filepath.Join(wdir, filepath.Dir(path))
- os.MkdirAll(base, 0750)
- err = os.Chdir(base)
+ fulldir := filepath.Join(wdir, filepath.Dir(path))
+ base := filepath.Base(path)
+ os.MkdirAll(fulldir, 0750)
+ err = os.Chdir(fulldir)
if err != nil {
return err
}
- shell.RunPath(base, []string{"git", "clone", "http://" + path})
+ shell.RunPath(fulldir, []string{"git", "clone", "http://" + path})
if IsDirectory(fullpath) {
// clone worked
return nil
@@ -132,7 +137,7 @@ func clone(wdir string, path string) error {
return err
}
log.Info("URL:", url)
- shell.RunPath(base, []string{"git", "clone", url})
+ shell.RunPath(fulldir, []string{"git", "clone", url, base})
if IsDirectory(fullpath) {
// clone worked
return nil
@@ -174,7 +179,7 @@ func findGoImport(url string) (string, error) {
}
tmp := strings.TrimSpace(parts[0])
fields := strings.Split(tmp, " ")
- log.Info("FIELDS:", fields)
+ // log.Info("FIELDS:", fields)
if len(fields) == 3 {
newurl = fields[2]
break