diff --git a/deps.go b/deps.go index 5d09782..5fb2265 100644 --- a/deps.go +++ b/deps.go @@ -13,7 +13,7 @@ func (rs *RepoStatus) GetGoDeps() GoConfig { tmp := filepath.Join(rs.realPath.String(), "go.sum") gosum, err := os.Open(tmp) if err != nil { - log.Log(WARN, "\tmissing go.sum", rs.realPath.String()) + log.Log(REPO, "\tmissing go.sum", rs.realPath.String()) return nil } defer gosum.Close() @@ -22,7 +22,7 @@ func (rs *RepoStatus) GetGoDeps() GoConfig { deps = make(GoConfig) scanner := bufio.NewScanner(gosum) - log.Info("\tgosum:", tmp) + log.Log(REPO, "\tgosum:", tmp) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) @@ -36,15 +36,15 @@ func (rs *RepoStatus) GetGoDeps() GoConfig { currentversion, ok := deps[godep] if ok { if currentversion != version { - log.Info("\tREPO:", rs.String(), rs.realPath.String()) - log.Info("\t version mismatch:", godep, version, currentversion) + log.Log(REPO, "\tREPO:", rs.String(), rs.realPath.String()) + log.Log(REPO, "\t version mismatch:", godep, version, currentversion) } } else { deps[godep] = version - log.Info("\t", godep, "=", version) + log.Log(REPO, "\t", godep, "=", version) } } else { - log.Info("\t INVALID:", parts) + log.Log(REPO, "\t INVALID:", parts) return nil } } diff --git a/gitConfig.go b/gitConfig.go index 595345f..abfc72a 100644 --- a/gitConfig.go +++ b/gitConfig.go @@ -2,7 +2,6 @@ package repostatus import ( "bufio" - "errors" "os" "path/filepath" "strings" @@ -24,11 +23,12 @@ type branch struct { } type GitConfig struct { - core map[string]string // map[origin] = "https:/git.wit.org/gui/gadgets" - remotes map[string]*remote // map[origin] = "https:/git.wit.org/gui/gadgets" - branches map[string]*branch // map[guimaster] = origin guimaster - hashes map[string]string - versions map[string]string + core map[string]string // map[origin] = "https:/git.wit.org/gui/gadgets" + remotes map[string]*remote // map[origin] = "https:/git.wit.org/gui/gadgets" + branches map[string]*branch // map[guimaster] = origin guimaster + submodules map[string]string + hashes map[string]string + versions map[string]string } type GoConfig map[string]string @@ -85,7 +85,7 @@ func (rs *RepoStatus) readGitConfig() error { log.Log(WARN, "readGitConfig() trying up one directory instead", filename) file, err = os.Open(filename) if err != nil { - return errors.New("couldn't open .git/config") + return err } } defer file.Close() @@ -97,6 +97,7 @@ func (rs *RepoStatus) readGitConfig() error { rs.gitConfig.core = make(map[string]string) rs.gitConfig.remotes = make(map[string]*remote) rs.gitConfig.branches = make(map[string]*branch) + rs.gitConfig.submodules = make(map[string]string) rs.gitConfig.versions = make(map[string]string) rs.gitConfig.hashes = make(map[string]string) @@ -155,7 +156,7 @@ func (rs *RepoStatus) readGitConfig() error { test.url = value continue } - log.Log(WARN, "error url mismatch", test.url, value) + log.Log(REPO, "error url mismatch", test.url, value) case "fetch": if test.fetch == value { continue @@ -164,9 +165,9 @@ func (rs *RepoStatus) readGitConfig() error { test.fetch = value continue } - log.Log(WARN, "error fetch mismatch", test.fetch, value) + log.Log(REPO, "error fetch mismatch", test.fetch, value) default: - log.Log(WARN, "error unknown remote:", currentSection, currentName, "key", key, "value", value) + log.Log(REPO, "unknown remote:", rs.Path(), line) } case "branch": test, ok := rs.gitConfig.branches[currentName] @@ -181,10 +182,21 @@ func (rs *RepoStatus) readGitConfig() error { case "merge": rs.gitConfig.branches[currentName].merge = value default: - log.Log(WARN, "error unknown remote:", currentSection, currentName, key, value) + log.Log(REPO, "error unknown remote:", currentSection, currentName, key, value) + log.Log(REPO, "unknown branch:", rs.Path(), line) + } + case "submodule": + // test, ok := rs.gitConfig.submodules[currentName] + switch key { + case "active": + // probably 'true' or 'false' + case "url": + rs.gitConfig.submodules[currentName] = value + default: + log.Log(REPOWARN, "unknown submodule line:", rs.Path(), line) } default: - log.Log(WARN, "error unknown currentSection", currentSection, "line:", line) + log.Log(REPOWARN, "unknown line:", rs.Path(), line) } } 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