fix the dumb names

This commit is contained in:
Jeff Carr 2025-01-08 03:13:09 -06:00
parent ebda2ea222
commit b0fca659c5
13 changed files with 59 additions and 59 deletions

2
age.go
View File

@ -65,6 +65,6 @@ func (repo *Repo) oldMtime(filename string) (time.Time, error) {
if err == nil { if err == nil {
return statf.ModTime(), nil return statf.ModTime(), nil
} }
log.Log(GITPBWARN, "Mtime() os.Stat() error", pathf, err) log.Log(WARN, "Mtime() os.Stat() error", pathf, err)
return time.Now(), err return time.Now(), err
} }

View File

@ -42,21 +42,21 @@ func (repo *Repo) checkoutBranch(bName string) bool {
return false return false
} }
if repo.CheckDirty() { if repo.CheckDirty() {
log.Log(GITPB, repo.GetFullPath(), "is dirty") log.Log(INFO, repo.GetFullPath(), "is dirty")
return false return false
} }
cmd := []string{"git", "checkout", bName} cmd := []string{"git", "checkout", bName}
r := repo.Run(cmd) r := repo.Run(cmd)
if r.Error != nil { if r.Error != nil {
log.Log(GITPB, "git checkout error:", r.Error) log.Log(INFO, "git checkout error:", r.Error)
} }
realname := repo.GetCurrentBranchName() realname := repo.GetCurrentBranchName()
realversion := repo.GetCurrentBranchVersion() realversion := repo.GetCurrentBranchVersion()
log.Log(GITPB, repo.GetFullPath(), "realname =", realname, "realversion =", realversion) log.Log(INFO, repo.GetFullPath(), "realname =", realname, "realversion =", realversion)
if realname != bName { if realname != bName {
log.Log(GITPB, "git checkout failed", repo.GetFullPath(), bName, "!=", realname) log.Log(INFO, "git checkout failed", repo.GetFullPath(), bName, "!=", realname)
return false return false
} }
return true return true

View File

@ -37,7 +37,7 @@ func (repo *Repo) setMasterVersion() {
if err == nil { if err == nil {
repo.MasterVersion = v repo.MasterVersion = v
} else { } else {
log.Log(GITPBWARN, "gitpb.GitMasterVersion() error:", err) log.Log(WARN, "gitpb.GitMasterVersion() error:", err)
repo.MasterVersion = "giterr" repo.MasterVersion = "giterr"
} }
} }
@ -48,7 +48,7 @@ func (repo *Repo) setDevelVersion() {
if err == nil { if err == nil {
repo.DevelVersion = v repo.DevelVersion = v
} else { } else {
log.Log(GITPBWARN, "gitpb.GitDevelVersion() error:", err) log.Log(WARN, "gitpb.GitDevelVersion() error:", err)
repo.DevelVersion = "deverr" repo.DevelVersion = "deverr"
} }
} }
@ -59,7 +59,7 @@ func (repo *Repo) setUserVersion() {
if err == nil { if err == nil {
repo.UserVersion = v repo.UserVersion = v
} else { } else {
log.Log(GITPBWARN, "gitpb.GitUserVersion() error:", err) log.Log(WARN, "gitpb.GitUserVersion() error:", err)
repo.UserVersion = "uerr" repo.UserVersion = "uerr"
} }
} }
@ -70,8 +70,8 @@ func (repo *Repo) GetCurrentBranchName() string {
r := repo.RunQuiet([]string{"git", "branch", "--show-current"}) r := repo.RunQuiet([]string{"git", "branch", "--show-current"})
output := strings.Join(r.Stdout, "\n") output := strings.Join(r.Stdout, "\n")
if r.Error != nil { if r.Error != nil {
log.Log(GITPBWARN, "GetCurrentBranchName() not in a git repo?", r.Error, repo.GetGoPath()) log.Log(WARN, "GetCurrentBranchName() not in a git repo?", r.Error, repo.GetGoPath())
log.Log(GITPBWARN, "GetCurrentBranchName() output might have worked anyway:", output) log.Log(WARN, "GetCurrentBranchName() output might have worked anyway:", output)
} }
return strings.TrimSpace(output) return strings.TrimSpace(output)
} }
@ -145,25 +145,25 @@ func (repo *Repo) gitVersionByName(name string) (string, error) {
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 {
log.Log(GITPBWARN, "gitDescribeByName() output might have worked anyway:", output) log.Log(WARN, "gitDescribeByName() output might have worked anyway:", output)
log.Log(GITPBWARN, "gitDescribeByName() not in a git repo?", r.Error, repo.GetGoPath()) log.Log(WARN, "gitDescribeByName() not in a git repo?", r.Error, repo.GetGoPath())
return "", r.Error return "", r.Error
} }
return strings.TrimSpace(output), nil return strings.TrimSpace(output), nil
} }
if !repo.IsBranch(name) { if !repo.IsBranch(name) {
// tag does not exist // tag does not exist
log.Log(GITPBWARN, "LocalTagExists()", name, "did not exist") log.Log(WARN, "LocalTagExists()", name, "did not exist")
return "", errors.New("gitDescribeByName() git fatal: Not a valid object name: " + name) return "", errors.New("gitDescribeByName() git fatal: Not a valid object name: " + name)
} }
cmd := []string{"git", "describe", "--tags", "--always", name} cmd := []string{"git", "describe", "--tags", "--always", name}
result := repo.RunQuiet(cmd) result := repo.RunQuiet(cmd)
output := strings.Join(result.Stdout, "\n") output := strings.Join(result.Stdout, "\n")
if result.Error != nil { if result.Error != nil {
log.Log(GITPBWARN, "cmd =", cmd) log.Log(WARN, "cmd =", cmd)
log.Log(GITPBWARN, "err =", result.Error) log.Log(WARN, "err =", result.Error)
log.Log(GITPBWARN, "output (might have worked with error?) =", output) log.Log(WARN, "output (might have worked with error?) =", output)
log.Log(GITPBWARN, "not in a git repo or bad tag?", repo.GetGoPath()) log.Log(WARN, "not in a git repo or bad tag?", repo.GetGoPath())
return "", result.Error return "", result.Error
} }
@ -188,13 +188,13 @@ func (repo *Repo) IsBranch(findname string) bool {
continue continue
} }
path, filename := filepath.Split(tagname) path, filename := filepath.Split(tagname)
log.Log(GITPB, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath()) log.Log(INFO, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath())
if filename == findname { if filename == findname {
log.Log(GITPB, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath()) log.Log(INFO, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath())
return true return true
} }
} }
log.Log(GITPB, "did not find tag:", findname, "in", repo.GetGoPath()) log.Log(INFO, "did not find tag:", findname, "in", repo.GetGoPath())
return false return false
} }
@ -210,13 +210,13 @@ func (repo *Repo) IsLocalBranch(findname string) bool {
continue continue
} }
path, filename := filepath.Split(tagname) path, filename := filepath.Split(tagname)
log.Log(GITPB, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath()) log.Log(INFO, "gitpb.IsBranch() tag:", path, filename, "from", repo.GetGoPath())
if filename == findname { if filename == findname {
log.Log(GITPB, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath()) log.Log(INFO, "gitpb.IsBranch() found tag:", path, filename, "from", repo.GetGoPath())
return true return true
} }
} }
log.Log(GITPB, "did not find tag:", findname, "in", repo.GetGoPath()) log.Log(INFO, "did not find tag:", findname, "in", repo.GetGoPath())
return false return false
} }
@ -237,11 +237,11 @@ func normalizeVersion(s string) string {
} }
reg, err := regexp.Compile("[^0-9.]+") reg, err := regexp.Compile("[^0-9.]+")
if err != nil { if err != nil {
log.Log(GITPBWARN, "normalizeVersion() regexp.Compile() ERROR =", err) log.Log(WARN, "normalizeVersion() regexp.Compile() ERROR =", err)
return parts[0] return parts[0]
} }
clean := reg.ReplaceAllString(parts[0], "") clean := reg.ReplaceAllString(parts[0], "")
log.Log(GITPB, "normalizeVersion() s =", clean) log.Log(INFO, "normalizeVersion() s =", clean)
return clean return clean
} }

View File

@ -28,11 +28,11 @@ func (repo *Repo) setPrimitive() error {
// it assumes go mod ran init and tidy ran without error // it assumes go mod ran init and tidy ran without error
func (repo *Repo) computePrimitive() (bool, error) { func (repo *Repo) computePrimitive() (bool, error) {
// go mod init & go mod tidy ran without errors // go mod init & go mod tidy ran without errors
log.Log(GITPB, "isPrimitiveGoMod()", repo.FullPath) log.Log(INFO, "isPrimitiveGoMod()", repo.FullPath)
tmp := filepath.Join(repo.FullPath, "go.mod") tmp := filepath.Join(repo.FullPath, "go.mod")
gomod, err := os.Open(tmp) gomod, err := os.Open(tmp)
if err != nil { if err != nil {
log.Log(GITPB, "missing go.mod", repo.FullPath) log.Log(INFO, "missing go.mod", repo.FullPath)
return false, err return false, err
} }
defer gomod.Close() defer gomod.Close()
@ -47,17 +47,17 @@ func (repo *Repo) computePrimitive() (bool, error) {
line := strings.TrimSpace(scanner.Text()) line := strings.TrimSpace(scanner.Text())
parts := strings.Fields(line) parts := strings.Fields(line)
log.Log(GITPB, " gomod:", parts) log.Log(INFO, " gomod:", parts)
if len(parts) >= 1 { if len(parts) >= 1 {
log.Log(GITPB, " gomod: part[0] =", parts[0]) log.Log(INFO, " gomod: part[0] =", parts[0])
if parts[0] == "require" { if parts[0] == "require" {
log.Log(GITPB, " should return false here") log.Log(INFO, " should return false here")
return false, errors.New("go.mod file is not primitive") return false, errors.New("go.mod file is not primitive")
} }
/* /*
if parts[0] == "go" { if parts[0] == "go" {
if parts[1] != "1.21" { if parts[1] != "1.21" {
log.Log(GITPBWARN, "go not set to 1.21 for", repo.GetGoPath()) log.Log(WARN, "go not set to 1.21 for", repo.GetGoPath())
// return false, errors.New("go not set to 1.21 for " + repo.GetGoPath()) // return false, errors.New("go not set to 1.21 for " + repo.GetGoPath())
} }
} }

8
log.go
View File

@ -4,13 +4,13 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
var GITPB *log.LogFlag var INFO *log.LogFlag
var GITPBWARN *log.LogFlag var WARN *log.LogFlag
func init() { func init() {
full := "go.wit.com/lib/protobuf/gitpb" full := "go.wit.com/lib/protobuf/gitpb"
short := "gitpb" short := "gitpb"
GITPB = log.NewFlag("GITPB", false, full, short, "general gitpb things") INFO = log.NewFlag("INFO", false, full, short, "general gitpb things")
GITPBWARN = log.NewFlag("GITPBWARN", true, full, short, "gitpb warnings") WARN = log.NewFlag("WARN", true, full, short, "gitpb warnings")
} }

View File

@ -48,7 +48,7 @@ func (repo *Repo) setLastTag() {
// log.Info("getLastTagVersion()", result.Stdout) // log.Info("getLastTagVersion()", result.Stdout)
if len(result.Stdout) != 1 { if len(result.Stdout) != 1 {
log.Log(GITPBWARN, "git LastTag() error:", result.Stdout) log.Log(WARN, "git LastTag() error:", result.Stdout)
repo.LastTag = "" repo.LastTag = ""
return return
} }
@ -59,7 +59,7 @@ func (repo *Repo) setLastTag() {
result = repo.RunQuiet(cmd) result = repo.RunQuiet(cmd)
if len(result.Stdout) != 1 { if len(result.Stdout) != 1 {
log.Log(GITPBWARN, "git LastTag() error:", result.Stdout) log.Log(WARN, "git LastTag() error:", result.Stdout)
repo.LastTag = "" repo.LastTag = ""
return return
} }
@ -72,8 +72,8 @@ func (repo *Repo) setCurrentBranchName() {
r := repo.RunQuiet([]string{"git", "branch", "--show-current"}) r := repo.RunQuiet([]string{"git", "branch", "--show-current"})
output := strings.Join(r.Stdout, "\n") output := strings.Join(r.Stdout, "\n")
if r.Error != nil { if r.Error != nil {
log.Log(GITPBWARN, "GetCurrentBranchName() not in a git repo?", r.Error, repo.GetGoPath()) log.Log(WARN, "GetCurrentBranchName() not in a git repo?", r.Error, repo.GetGoPath())
log.Log(GITPBWARN, "GetCurrentBranchName() output might have worked anyway:", output) log.Log(WARN, "GetCurrentBranchName() output might have worked anyway:", output)
} }
repo.CurrentBranchName = strings.TrimSpace(output) repo.CurrentBranchName = strings.TrimSpace(output)
} }
@ -88,8 +88,8 @@ func (repo *Repo) setCurrentBranchVersion() {
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 {
log.Log(GITPBWARN, "GetCurrentBranchVersion() not in a git repo?", r.Error, repo.GetGoPath()) log.Log(WARN, "GetCurrentBranchVersion() not in a git repo?", r.Error, repo.GetGoPath())
log.Log(GITPBWARN, "GetCurrentBranchVersion() output might have worked anyway:", output) log.Log(WARN, "GetCurrentBranchVersion() output might have worked anyway:", output)
} }
repo.CurrentBranchVersion = strings.TrimSpace(output) repo.CurrentBranchVersion = strings.TrimSpace(output)
} }

View File

@ -52,17 +52,17 @@ func (repo *Repo) CheckBranches() bool {
} }
var cmd []string var cmd []string
cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash) cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash)
r := shell.PathRunLog(repo.GetFullPath(), cmd, GITPB) r := shell.PathRunLog(repo.GetFullPath(), cmd, INFO)
if r.Error != nil { if r.Error != nil {
log.Log(GITPBWARN, "CheckBranches() git show error:", r.Error) log.Log(WARN, "CheckBranches() git show error:", r.Error)
} }
// git show -s --format=%ci <hash> will give you the time // git show -s --format=%ci <hash> will give you the time
// log.Log(REPO, fullfile) // log.Log(REPO, fullfile)
if hash == hashCheck { if hash == hashCheck {
// log.Info("notsure why this git show is here", hash) // log.Info("notsure why this git show is here", hash)
} else { } else {
log.Log(GITPBWARN, repo.GetFullPath(), hash, r.Stdout, b) log.Log(WARN, repo.GetFullPath(), hash, r.Stdout, b)
log.Log(GITPBWARN, "UNKNOWN BRANCHES IN THIS REPO", cmd) log.Log(WARN, "UNKNOWN BRANCHES IN THIS REPO", cmd)
// repo.versionCmdOutput.SetText("UNKNOWN BRANCHES") // repo.versionCmdOutput.SetText("UNKNOWN BRANCHES")
perfect = false perfect = false
// parts := strings.Split(b, "/") // parts := strings.Split(b, "/")

View File

@ -25,7 +25,7 @@ func (repo *Repo) IsDirty() bool {
// actually os.Exec('git') // actually os.Exec('git')
func (repo *Repo) CheckDirty() bool { func (repo *Repo) CheckDirty() bool {
cmd := []string{"git", "status", "--porcelain"} cmd := []string{"git", "status", "--porcelain"}
r := shell.PathRunLog(repo.FullPath, cmd, GITPB) r := shell.PathRunLog(repo.FullPath, cmd, INFO)
if r.Error != nil { if r.Error != nil {
log.Warn("CheckDirty() status cmd =", cmd) log.Warn("CheckDirty() status cmd =", cmd)
out := strings.Join(r.Stdout, "\n") out := strings.Join(r.Stdout, "\n")

View File

@ -141,7 +141,7 @@ func (repo *Repo) IsOnlyLocalTag(taggy string) bool {
if strings.HasPrefix(tagname, "refs/remotes") { if strings.HasPrefix(tagname, "refs/remotes") {
path, filename := filepath.Split(tagname) path, filename := filepath.Split(tagname)
if filename == taggy { if filename == taggy {
log.Log(GITPB, "found tag:", path, filename, "from", repo.GetGoPath()) log.Log(INFO, "found tag:", path, filename, "from", repo.GetGoPath())
return false return false
} }
} }

View File

@ -18,7 +18,7 @@ func (rs *Repo) MergeUserToDevel() (*cmd.Status, error) {
all = append(all, []string{"git", "push"}) all = append(all, []string{"git", "push"})
if result, err := rs.RunStrictAll(all); err != nil { if result, err := rs.RunStrictAll(all); err != nil {
log.Log(GITPBWARN, "MergeUserToDevel() failed", rs.GetFullPath()) log.Log(WARN, "MergeUserToDevel() failed", rs.GetFullPath())
return result, err return result, err
} }
return nil, nil return nil, nil
@ -37,7 +37,7 @@ func (rs *Repo) MergeDevelToMaster() (*cmd.Status, error) {
all = append(all, []string{"git", "push"}) all = append(all, []string{"git", "push"})
if result, err := rs.RunStrictAll(all); err != nil { if result, err := rs.RunStrictAll(all); err != nil {
log.Log(GITPBWARN, "MergeDevelToMaster() failed", rs.GetFullPath()) log.Log(WARN, "MergeDevelToMaster() failed", rs.GetFullPath())
return result, err return result, err
} }
return nil, nil return nil, nil

View File

@ -64,7 +64,7 @@ func scanForProtobuf(srcDir string) ([]string, []string, error) {
var compiled []string var compiled []string
err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
log.Log(GITPBWARN, "Error accessing path:", path, err) log.Log(WARN, "Error accessing path:", path, err)
return err return err
} }
@ -97,7 +97,7 @@ func (repo *Repo) GetProtoFiles() ([]string, error) {
srcDir := repo.GetFullPath() srcDir := repo.GetFullPath()
err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
log.Log(GITPBWARN, "Error accessing path:", path, err) log.Log(WARN, "Error accessing path:", path, err)
return err return err
} }

View File

@ -38,15 +38,15 @@ func (repo *Repo) GitPull() cmd.Status {
/* /*
if r.Error == nil { if r.Error == nil {
if r.Exit == 0 { if r.Exit == 0 {
log.Log(GITPBWARN, "git pull ran ", repo.GetGoPath()) log.Log(WARN, "git pull ran ", repo.GetGoPath())
// log.Log(GITPBWARN, "git pull output", output) // log.Log(WARN, "git pull output", output)
return r return r
} else { } else {
log.Log(GITPBWARN, "git pull error", repo.GetGoPath(), strings.Join(r.Stderr, "\n")) log.Log(WARN, "git pull error", repo.GetGoPath(), strings.Join(r.Stderr, "\n"))
return r return r
} }
} }
log.Log(GITPBWARN, "git pull error", repo.GetGoPath(), r.Error) log.Log(WARN, "git pull error", repo.GetGoPath(), r.Error)
*/ */
return r return r
} }

View File

@ -129,11 +129,11 @@ func (repo *Repo) IsDirectory() bool {
func (repo *Repo) RunAll(all [][]string) bool { func (repo *Repo) RunAll(all [][]string) bool {
for _, cmd := range all { for _, cmd := range all {
log.Log(GITPBWARN, "doAll() RUNNING: cmd =", cmd) log.Log(WARN, "doAll() RUNNING: cmd =", cmd)
r := repo.Run(cmd) r := repo.Run(cmd)
if r.Error != nil { if r.Error != nil {
log.Log(GITPBWARN, "doAll() err =", r.Error) log.Log(WARN, "doAll() err =", r.Error)
log.Log(GITPBWARN, "doAll() out =", r.Stdout) log.Log(WARN, "doAll() out =", r.Stdout)
return false return false
} }
} }
@ -142,7 +142,7 @@ func (repo *Repo) RunAll(all [][]string) bool {
func (repo *Repo) RunStrictAll(all [][]string) (*cmd.Status, error) { func (repo *Repo) RunStrictAll(all [][]string) (*cmd.Status, error) {
for _, cmd := range all { for _, cmd := range all {
log.Log(GITPBWARN, "doAll() RUNNING: cmd =", cmd) log.Log(WARN, "doAll() RUNNING: cmd =", cmd)
if result, err := repo.RunStrictNew(cmd); err != nil { if result, err := repo.RunStrictNew(cmd); err != nil {
return result, err return result, err
} }