debugging switching go/src dirs
This commit is contained in:
parent
945ae6329b
commit
cb04f3585c
14
config.go
14
config.go
|
@ -11,12 +11,12 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// write to ~/.config/forge/ unless ENV{FORGE_CONFIG} is set
|
// write to ~/.config/forge/ unless ENV{FORGE_GOSRC} is set
|
||||||
func (all *Repos) ConfigSave() error {
|
func (all *Repos) ConfigSave() error {
|
||||||
if os.Getenv("FORGE_CONFIG") == "" {
|
if os.Getenv("FORGE_GOSRC") == "" {
|
||||||
homeDir, _ := os.UserHomeDir()
|
homeDir, _ := os.UserHomeDir()
|
||||||
fullpath := filepath.Join(homeDir, ".config/forge")
|
fullpath := filepath.Join(homeDir, ".config/forge")
|
||||||
os.Setenv("FORGE_CONFIG", fullpath)
|
os.Setenv("FORGE_GOSRC", fullpath)
|
||||||
}
|
}
|
||||||
if all == nil {
|
if all == nil {
|
||||||
log.Warn("gitpb all == nil")
|
log.Warn("gitpb all == nil")
|
||||||
|
@ -35,10 +35,10 @@ func (all *Repos) ConfigSave() error {
|
||||||
|
|
||||||
// load the ~/.config/forge/ files
|
// load the ~/.config/forge/ files
|
||||||
func (all *Repos) ConfigLoad() error {
|
func (all *Repos) ConfigLoad() error {
|
||||||
if os.Getenv("FORGE_CONFIG") == "" {
|
if os.Getenv("FORGE_GOSRC") == "" {
|
||||||
homeDir, _ := os.UserHomeDir()
|
homeDir, _ := os.UserHomeDir()
|
||||||
fullpath := filepath.Join(homeDir, ".config/forge")
|
fullpath := filepath.Join(homeDir, ".config/forge")
|
||||||
os.Setenv("FORGE_CONFIG", fullpath)
|
os.Setenv("FORGE_GOSRC", fullpath)
|
||||||
}
|
}
|
||||||
var data []byte
|
var data []byte
|
||||||
var err error
|
var err error
|
||||||
|
@ -78,7 +78,7 @@ func (all *Repos) ConfigLoad() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFile(filename string) ([]byte, error) {
|
func loadFile(filename string) ([]byte, error) {
|
||||||
fullname := filepath.Join(os.Getenv("FORGE_CONFIG"), filename)
|
fullname := filepath.Join(os.Getenv("FORGE_GOSRC"), filename)
|
||||||
data, err := os.ReadFile(fullname)
|
data, err := os.ReadFile(fullname)
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
// if file does not exist, just return nil. this
|
// if file does not exist, just return nil. this
|
||||||
|
@ -94,7 +94,7 @@ func loadFile(filename string) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func configWrite(filename string, data []byte) error {
|
func configWrite(filename string, data []byte) error {
|
||||||
fullname := filepath.Join(os.Getenv("FORGE_CONFIG"), filename)
|
fullname := filepath.Join(os.Getenv("FORGE_GOSRC"), filename)
|
||||||
|
|
||||||
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
|
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
|
||||||
defer cfgfile.Close()
|
defer cfgfile.Close()
|
||||||
|
|
|
@ -86,6 +86,10 @@ func (repo *Repo) GetCurrentBranchName() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repo) GetCurrentBranchVersion() string {
|
func (repo *Repo) GetCurrentBranchVersion() string {
|
||||||
|
if repo == nil {
|
||||||
|
log.Info("repo.GetCurrentBranchVersion() repo == nil")
|
||||||
|
return ""
|
||||||
|
}
|
||||||
r := repo.RunQuiet([]string{"git", "describe", "--tags", "--always"})
|
r := repo.RunQuiet([]string{"git", "describe", "--tags", "--always"})
|
||||||
output := strings.Join(r.Stdout, "\n")
|
output := strings.Join(r.Stdout, "\n")
|
||||||
if r.Error != nil {
|
if r.Error != nil {
|
||||||
|
|
|
@ -19,7 +19,7 @@ func (all *Repos) NewGoPath(basepath string, gopath string, url string) (*Repo,
|
||||||
}
|
}
|
||||||
if r := all.FindByGoPath(gopath); r != nil {
|
if r := all.FindByGoPath(gopath); r != nil {
|
||||||
// already had this gopath
|
// already had this gopath
|
||||||
return nil, errors.New("duplicate gopath " + gopath)
|
return r, errors.New("gitpb.NewGoPath() duplicate gopath " + gopath)
|
||||||
}
|
}
|
||||||
log.Info("gitpb.NewGoPath() Attempting to add new path", basepath, gopath)
|
log.Info("gitpb.NewGoPath() Attempting to add new path", basepath, gopath)
|
||||||
|
|
||||||
|
@ -58,7 +58,11 @@ func (all *Repos) NewGoPath(basepath string, gopath string, url string) (*Repo,
|
||||||
// worked
|
// worked
|
||||||
return &newr, nil
|
return &newr, nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("repo already exists: " + gopath)
|
if r := all.FindByGoPath(gopath); r != nil {
|
||||||
|
// already had this gopath
|
||||||
|
return r, errors.New("gitpb.NewGoPath() AppendUnique() failed but Find() worked" + gopath)
|
||||||
|
}
|
||||||
|
return nil, errors.New("repo gitpb.NewGoPath() should never have gotten here " + gopath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repo) SetDevelBranchName(bname string) {
|
func (repo *Repo) SetDevelBranchName(bname string) {
|
||||||
|
|
Loading…
Reference in New Issue