From cb04f3585c1abe95f6bddfa282e829896c2bb19a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 7 Dec 2024 16:50:26 -0600 Subject: [PATCH] debugging switching go/src dirs --- config.go | 14 +++++++------- currentVersions.go | 4 ++++ repo.new.go | 8 ++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/config.go b/config.go index 99ba64d..3f344e3 100644 --- a/config.go +++ b/config.go @@ -11,12 +11,12 @@ import ( "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 { - if os.Getenv("FORGE_CONFIG") == "" { + if os.Getenv("FORGE_GOSRC") == "" { homeDir, _ := os.UserHomeDir() fullpath := filepath.Join(homeDir, ".config/forge") - os.Setenv("FORGE_CONFIG", fullpath) + os.Setenv("FORGE_GOSRC", fullpath) } if all == nil { log.Warn("gitpb all == nil") @@ -35,10 +35,10 @@ func (all *Repos) ConfigSave() error { // load the ~/.config/forge/ files func (all *Repos) ConfigLoad() error { - if os.Getenv("FORGE_CONFIG") == "" { + if os.Getenv("FORGE_GOSRC") == "" { homeDir, _ := os.UserHomeDir() fullpath := filepath.Join(homeDir, ".config/forge") - os.Setenv("FORGE_CONFIG", fullpath) + os.Setenv("FORGE_GOSRC", fullpath) } var data []byte var err error @@ -78,7 +78,7 @@ func (all *Repos) ConfigLoad() 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) if errors.Is(err, os.ErrNotExist) { // 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 { - 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) defer cfgfile.Close() diff --git a/currentVersions.go b/currentVersions.go index 4e9d843..b9329f6 100644 --- a/currentVersions.go +++ b/currentVersions.go @@ -86,6 +86,10 @@ func (repo *Repo) GetCurrentBranchName() string { } func (repo *Repo) GetCurrentBranchVersion() string { + if repo == nil { + log.Info("repo.GetCurrentBranchVersion() repo == nil") + return "" + } r := repo.RunQuiet([]string{"git", "describe", "--tags", "--always"}) output := strings.Join(r.Stdout, "\n") if r.Error != nil { diff --git a/repo.new.go b/repo.new.go index 9404d7b..9d0f7ba 100644 --- a/repo.new.go +++ b/repo.new.go @@ -19,7 +19,7 @@ func (all *Repos) NewGoPath(basepath string, gopath string, url string) (*Repo, } if r := all.FindByGoPath(gopath); r != nil { // 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) @@ -58,7 +58,11 @@ func (all *Repos) NewGoPath(basepath string, gopath string, url string) (*Repo, // worked 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) {