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

View File

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