minor syntax changes

This commit is contained in:
Jeff Carr 2025-08-29 10:29:36 -05:00
parent d47d25e3a6
commit f585edc192
2 changed files with 26 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package gitpb
import (
"fmt"
"os"
"os/user"
"path/filepath"
"go.wit.com/log"
@ -42,12 +43,20 @@ func (repo *Repo) CheckoutDevel() bool {
func (repo *Repo) CheckoutUser() error {
bName := repo.GetUserBranchName()
// log.Info("attempting checkout user", repo.GetGoPath(), bName)
err := repo.createUserBranchNew(bName)
if err != nil {
log.Info("attempting checkout user error", repo.GetGoPath(), bName, err)
if bName == "uerr" {
usr, _ := user.Current()
repo.SetUserBranchName(usr.Username)
bName = usr.Username
log.Info("gitpb CheckoutUser() somehow got user 'uerr'")
}
return err
return repo.createUserBranch(bName)
/*
if err != nil {
log.Info("attempting checkout user error", repo.GetGoPath(), bName, err)
}
return err
*/
}
func (repo *Repo) BranchExists(bName string) bool {
@ -83,15 +92,16 @@ func (repo *Repo) checkoutBranch(bName string) bool {
return true
}
func (repo *Repo) createUserBranchNew(branch string) error {
if branch == "" || branch == "uerr" {
return fmt.Errorf("forge.gitpb logic err. branch name was: %s", branch)
// actually creates a local user branch
func (repo *Repo) createUserBranch(branch string) error {
if branch == "" {
// get the username here?
return fmt.Errorf("gitpb createuserBranch() logic err. git branch name can not be blank")
}
if repo.IsDirty() {
// never change repos on dirty branches
return fmt.Errorf("repo is dirty")
}
// log.Info("forge.gitpb look for branch name was:", branch, repo.GetGoPath())
if repo.Exists(filepath.Join(".git/refs/heads", branch)) {
var err error
@ -125,8 +135,6 @@ func (repo *Repo) createUserBranchNew(branch string) error {
// return fmt.Errorf("repo must be on devel branch %s", repo.GetGoPath())
}
// log.Info("forge.gitpb try to create", branch, repo.GetGoPath())
// create the branch from devel
cmd := []string{"git", "branch", branch}
if _, err := repo.RunVerboseOnError(cmd); err != nil {

View File

@ -14,8 +14,8 @@ import (
"go.wit.com/log"
)
// reads and parses the go.sum file
// does not change anything
// reads and parses the go.sum file into a protobuf struct
// this function isn't supposed to change anything, just parse the existing files
func (repo *Repo) ParseGoSum() bool {
// empty out what was there before
repo.GoDeps = nil
@ -75,7 +75,7 @@ func (repo *Repo) ParseGoSum() bool {
// attempt to parse go.* files in a directory
func GoSumParseDir(moddir string) (*GoDeps, error) {
isprim, err := computePrimitiveNew(moddir)
isprim, err := computePrimitive(moddir)
if err != nil {
// "go mod init" failed
return nil, err
@ -85,14 +85,14 @@ func GoSumParseDir(moddir string) (*GoDeps, error) {
return nil, nil
}
// go.sum exists. parse the go.sum file
return parseGoSumNew(moddir)
return parseGoSum(moddir)
}
// Detect a 'Primitive' package. Sets the isPrimitive flag
// will return true if the repo is truly not dependent on _anything_ else
// like spew or lib/widget
// it assumes 'go mod init' and 'go mod tidy' ran without error
func computePrimitiveNew(moddir string) (bool, error) {
func computePrimitive(moddir string) (bool, error) {
// go mod init & go mod tidy ran without errors
log.Log(INFO, "isPrimitiveGoMod()", moddir)
gomod, err := os.Open(filepath.Join(moddir, "go.mod"))
@ -131,7 +131,8 @@ func computePrimitiveNew(moddir string) (bool, error) {
return true, nil
}
func parseGoSumNew(moddir string) (*GoDeps, error) {
// parse the go.sum file into a protobuf
func parseGoSum(moddir string) (*GoDeps, error) {
godeps := new(GoDeps)
tmp, err := os.Open(filepath.Join(moddir, "go.sum"))