pull out the namespace
This commit is contained in:
parent
e395456c53
commit
1d8380b9e7
|
@ -27,16 +27,28 @@ func (repo *Repo) updateGitConfig() error {
|
|||
repo.GitConfig.Submodules = make(map[string]string)
|
||||
repo.GitConfig.Versions = make(map[string]string)
|
||||
repo.GitConfig.Hashes = make(map[string]string)
|
||||
return repo.readGitConfig()
|
||||
url, err := repo.readGitConfig()
|
||||
if repo.URL != "" {
|
||||
log.Info("gitpb: url already set", url, repo.URL)
|
||||
}
|
||||
|
||||
if url == "" {
|
||||
log.Info(repo.FullPath, "url was blank. warn user this repo is only on the local disk")
|
||||
} else {
|
||||
repo.URL = url
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// readGitConfig reads and parses the .git/config file
|
||||
func (repo *Repo) readGitConfig() error {
|
||||
func (repo *Repo) readGitConfig() (string, error) {
|
||||
var foundURL string
|
||||
filename := filepath.Join(repo.GetFullPath(), ".git/config")
|
||||
file, err := os.Open(filename)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
var currentSection string = ""
|
||||
|
@ -92,6 +104,13 @@ func (repo *Repo) readGitConfig() error {
|
|||
log.Log(INFO, "switch currentSection", currentSection, currentName)
|
||||
switch key {
|
||||
case "url":
|
||||
if foundURL == "" {
|
||||
foundURL = value
|
||||
} else {
|
||||
if foundURL != value {
|
||||
log.Info("TODO: gitpb: handle multiple remotes in the parser", foundURL, value)
|
||||
}
|
||||
}
|
||||
if test.Url == value {
|
||||
continue
|
||||
}
|
||||
|
@ -164,10 +183,10 @@ func (repo *Repo) readGitConfig() error {
|
|||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
|
||||
return nil
|
||||
return foundURL, nil
|
||||
}
|
||||
|
||||
func (repo *Repo) processBranch(branch string) {
|
||||
|
|
29
repo.new.go
29
repo.new.go
|
@ -2,6 +2,8 @@ package gitpb
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
@ -103,16 +105,29 @@ func (all *Repos) NewRepo(fullpath string, namespace string) (*Repo, error) {
|
|||
|
||||
func NewRepo(fullpath string) (*Repo, error) {
|
||||
// add a new one here
|
||||
newr := Repo{
|
||||
repo := Repo{
|
||||
FullPath: fullpath,
|
||||
}
|
||||
newr.Times = new(GitTimes)
|
||||
repo.Times = new(GitTimes)
|
||||
|
||||
// everything happens in here
|
||||
newr.Reload()
|
||||
newr.ValidateUTF8()
|
||||
if newr.Namespace == "" {
|
||||
log.Info("GET Namespace from URL", newr.GetURL())
|
||||
repo.Reload()
|
||||
repo.ValidateUTF8()
|
||||
if repo.Namespace == "" {
|
||||
giturl := repo.GetURL()
|
||||
if giturl == "" {
|
||||
log.Info(repo.FullPath, "Namespace & URL are both blank. Warn the user of a local repo.")
|
||||
return &repo, nil
|
||||
}
|
||||
// log.Info("GET Namespace from URL", giturl)
|
||||
tmpURL, err := url.Parse(giturl)
|
||||
if err != nil {
|
||||
log.Info(repo.FullPath, "URL parse failed", giturl, err)
|
||||
return &repo, nil
|
||||
}
|
||||
// log.Info(repo.FullPath, "namespace might be:", tmpURL.Hostname(), tmpURL.Path)
|
||||
repo.Namespace = filepath.Join(tmpURL.Hostname(), tmpURL.Path)
|
||||
// log.Info(repo.FullPath, "Namesapce =", repo.Namespace)
|
||||
}
|
||||
return &newr, nil
|
||||
return &repo, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue