cleaning up obscure git cases

This commit is contained in:
Jeff Carr 2025-09-13 05:33:31 -05:00
parent 719287c3bf
commit 2a47f1e547
4 changed files with 12 additions and 20 deletions

View File

@ -2,7 +2,6 @@ package gitpb
import (
"fmt"
"os"
"os/user"
"path/filepath"
@ -11,20 +10,6 @@ import (
func (repo *Repo) CheckoutMaster() bool {
bName := repo.GetMasterBranchName()
if bName == "giterr" {
cmd := []string{"git", "checkout", "main"} // todo: figure out main
repo.RunVerboseOnError(cmd)
os.Exit(-1)
// TODO: try to fix this
if repo.checkoutBranch("main") {
repo.MasterBranchName = "main"
return true
} else {
cmd := []string{"git", "checkout", "main"} // todo: figure out main
repo.RunVerboseOnError(cmd)
return false
}
}
if repo.checkoutBranch(bName) {
return true
}

View File

@ -14,7 +14,10 @@ func (repo *Repo) SetMasterBranchName(s string) {
func (repo *Repo) GetGoPath() string {
if repo.GoInfo == nil {
return ""
return repo.Namespace
}
if repo.GoInfo.GoPath == "" {
return repo.Namespace
}
return repo.GoInfo.GoPath
}

View File

@ -19,6 +19,11 @@ func (all *Repos) ConfigSave(fname string) error {
return errors.New("gitpb.ConfigSave() repos == nil")
}
if _, s := filepath.Split(fname); s != "repos.pb" {
log.Infof("ConfigSave() filename '%s' invalid\n", fname)
return log.Errorf("ConfigSave() filename '%s' invalid\n", fname)
}
data, err := all.Marshal()
if err != nil {
log.Info("gitpb proto.Marshal() failed len", len(data), err)

View File

@ -38,7 +38,6 @@ func (repo *Repo) setMasterVersion() {
repo.MasterVersion = v
} else {
log.Log(WARN, "gitpb.GitMasterVersion() error:", err)
repo.MasterVersion = "giterr"
}
}
@ -134,11 +133,11 @@ func (repo *Repo) gitVersionByName(name string) (string, error) {
if name == "" {
// git will return the current tag
r, err := repo.RunQuiet([]string{"git", "describe", "--tags"})
cmd := []string{"git", "describe", "--tags"}
r, err := repo.RunQuiet(cmd)
output := strings.Join(r.Stdout, "\n")
if err != nil {
log.Log(WARN, "gitDescribeByName() output might have worked anyway:", output)
log.Log(WARN, "gitDescribeByName() not in a git repo?", err, repo.GetGoPath())
log.Log(WARN, repo.FullPath, "gitDescribeByName() ", output, err, cmd)
return "", err
}
return strings.TrimSpace(output), nil