buttons for scanning .git/config and go.sum

common branch handling
    scan go.sum & .git/config on New()
    parse go & git config files
    cleaner debugging
    cleaning up logging

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-23 10:52:17 -06:00
parent 7546209d24
commit 294119e7c2
13 changed files with 475 additions and 102 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.swp

View File

@ -3,6 +3,9 @@ all:
@echo Run: make redomod @echo Run: make redomod
@echo @echo
goimports:
goimports -w *.go
redomod: redomod:
rm -f go.* rm -f go.*
goimports -w *.go goimports -w *.go

14
args.go
View File

@ -8,25 +8,15 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
var NOW *log.LogFlag
var INFO *log.LogFlag var INFO *log.LogFlag
var SPEW *log.LogFlag
var WARN *log.LogFlag var WARN *log.LogFlag
var CHANGE *log.LogFlag var CHANGE *log.LogFlag
var STATUS *log.LogFlag
func init() { func init() {
full := "go.wit.com/gui/gadgets/repostatus" full := "go.wit.com/lib/gui/repostatus"
short := "repostatus" short := "repostatus"
NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff") INFO = log.NewFlag("INFO", false, full, short, "general repo things")
INFO = log.NewFlag("INFO", false, full, short, "normal debugging stuff")
WARN = log.NewFlag("WARN", true, full, short, "bad things") WARN = log.NewFlag("WARN", true, full, short, "bad things")
SPEW = log.NewFlag("SPEW", false, full, short, "spew stuff")
CHANGE = log.NewFlag("CHANGE", true, full, short, "when repo changes") CHANGE = log.NewFlag("CHANGE", true, full, short, "when repo changes")
STATUS = log.NewFlag("STATUS", false, full, short, "current status")
} }

View File

@ -56,7 +56,6 @@ func (rs *RepoStatus) Toggle() {
} }
func (rs *RepoStatus) Ready() bool { func (rs *RepoStatus) Ready() bool {
log.Log(SPEW, "Ready() maybe not ready? rs =", rs)
if rs == nil { if rs == nil {
return false return false
} }

161
draw.go
View File

@ -1,6 +1,7 @@
package repostatus package repostatus
import ( import (
"path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -37,10 +38,20 @@ func (rs *RepoStatus) drawGitBranches() {
rs.masterDrop = gadgets.NewBasicDropdown(newgrid, "main branch") rs.masterDrop = gadgets.NewBasicDropdown(newgrid, "main branch")
rs.develDrop = gadgets.NewBasicDropdown(newgrid, "devel branch") rs.develDrop = gadgets.NewBasicDropdown(newgrid, "devel branch")
rs.userDrop = gadgets.NewBasicDropdown(newgrid, "user branch") rs.userDrop = gadgets.NewBasicDropdown(newgrid, "user branch")
rs.lasttag = gadgets.NewOneLiner(newgrid, "last tag")
rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master")
rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel")
rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user")
rs.currentBranch = gadgets.NewOneLiner(newgrid, "current branch")
rs.currentVersion = gadgets.NewOneLiner(newgrid, "current version")
var master = "" var master = ""
all := rs.getBranches() all := rs.getBranches()
for _, branch := range all { for _, branch := range all {
log.Warn("getBranches()", branch) log.Log(INFO, "getBranches()", branch)
rs.masterDrop.AddText(branch) rs.masterDrop.AddText(branch)
rs.develDrop.AddText(branch) rs.develDrop.AddText(branch)
rs.userDrop.AddText(branch) rs.userDrop.AddText(branch)
@ -51,6 +62,7 @@ func (rs *RepoStatus) drawGitBranches() {
master = "main" master = "main"
} }
} }
// relabel the various gadgets with the right branch name // relabel the various gadgets with the right branch name
rs.masterBranchVersion.SetLabel(master) rs.masterBranchVersion.SetLabel(master)
@ -65,11 +77,82 @@ func (rs *RepoStatus) drawGitBranches() {
rs.checkBranchesButton = newgrid.NewButton("check branches", func() { rs.checkBranchesButton = newgrid.NewButton("check branches", func() {
if rs.CheckBranches() { if rs.CheckBranches() {
log.Warn("Branches are perfect") log.Log(INFO, "Branches are perfect")
} else { } else {
log.Warn("Branches are not perfect") log.Log(INFO, "Branches are not perfect")
} }
}) })
newgrid.NewButton("parse git and go config", func() {
ScanGoSrc()
})
newgrid.NewButton("show .git/config", func() {
if rs.gitConfig == nil {
log.Log(WARN, "Nonexistant or damaged .git/config", rs.GetPath())
return
}
log.Log(WARN, ".git/config:", rs.realPath.String())
// The info:
for name, remote := range rs.gitConfig.remotes {
log.Log(WARN, " ", name, remote.url)
}
for name, branch := range rs.gitConfig.branches {
log.Log(WARN, " ", name, "remote:", branch.remote, "merge", branch.merge)
}
})
newgrid.NewButton("check go.sum", func() {
if rs.ReadGoMod() {
log.Log(INFO, "parsed go.mod", rs.realPath.String())
} else {
log.Log(WARN, "Something went wrong parsing go.mod", rs.realPath.String())
}
log.Log(WARN, "go.sum:", rs.realPath.String())
for depname, version := range rs.goConfig {
log.Log(WARN, " ", depname, version)
}
})
}
/*
func (rs *RepoStatus) ScanConfig(path string) {
log.Log(WARN, "repo =", path)
filename := filepath.Join(path, ".git/config")
rs.gitConfig, err := ReadGitConfig(filename)
if err != nil {
log.Log(WARN, "Error reading .git/config:", err)
continue
}
rs.goConfig, err := ReadGoMod(path)
}
*/
func ScanGoSrc() {
for i, path := range listGitDirectories() {
log.Log(WARN, "repo =", i, path)
filename := filepath.Join(path, ".git/config")
gitConfig, err := readGitConfig(filename)
if err != nil {
log.Log(WARN, "Error reading .git/config:", err)
continue
}
// Example of printing the parsed config
for section, options := range gitConfig.branches {
log.Log(WARN, "\t", section, options)
}
/*
_, err = ReadGoMod(path) // map[string]string {
if err != nil {
log.Log(WARN, "\tgo.sum scan failed")
}
*/
}
} }
func (rs *RepoStatus) drawGitStatus() { func (rs *RepoStatus) drawGitStatus() {
@ -79,23 +162,29 @@ func (rs *RepoStatus) drawGitStatus() {
newgrid.Pad() newgrid.Pad()
rs.path = gadgets.NewOneLiner(newgrid, "path") rs.path = gadgets.NewOneLiner(newgrid, "path")
rs.currentBranch = gadgets.NewOneLiner(newgrid, "branch") rs.goSrcPath = gadgets.NewOneLiner(newgrid, "go/src")
rs.lasttag = gadgets.NewOneLiner(newgrid, "last tag") rs.realPath = gadgets.NewOneLiner(newgrid, "fullpath")
rs.currentVersion = gadgets.NewOneLiner(newgrid, "Version") rs.realPath.Hide()
rs.tagsDrop = gadgets.NewBasicDropdown(newgrid, "existing tags") rs.mainWorkingName = gadgets.NewOneLiner(newgrid, "main working branch")
rs.mainWorkingName.SetValue("???")
rs.develWorkingName = gadgets.NewOneLiner(newgrid, "devel working branch")
rs.develWorkingName.SetValue("devel")
rs.userWorkingName = gadgets.NewOneLiner(newgrid, "user working branch")
rs.userWorkingName.SetValue("uid")
rs.tagsDrop = gadgets.NewBasicDropdown(newgrid, "all releases")
// git for-each-ref --sort=taggerdate --format '%(tag) ,,,_,,, %(subject)' refs/tags // git for-each-ref --sort=taggerdate --format '%(tag) ,,,_,,, %(subject)' refs/tags
var cmd []string var cmd []string
cmd = append(cmd, "git", "for-each-ref", "--sort=taggerdate", "--format", "%(tag) %(subject)", "refs/tags") cmd = append(cmd, "git", "for-each-ref", "--sort=taggerdate", "--format", "%(tag) %(subject)", "refs/tags")
_, _, output := RunCmd("/home/jcarr/go/src/"+rs.repopath, cmd) _, _, output := RunCmd("/home/jcarr/go/src/"+rs.repopath, cmd)
log.Info(output) log.Log(INFO, output)
for _, line := range strings.Split(output, "\n") { for _, line := range strings.Split(output, "\n") {
rs.tagsDrop.AddText(line) rs.tagsDrop.AddText(line)
} }
rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master") // rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master")
rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel") // rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel")
rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user") // rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user")
rs.dirtyLabel = gadgets.NewOneLiner(newgrid, "dirty") rs.dirtyLabel = gadgets.NewOneLiner(newgrid, "dirty")
@ -187,8 +276,8 @@ func (rs *RepoStatus) setTag() bool {
oldb, _ := strconv.Atoi(minor) oldb, _ := strconv.Atoi(minor)
oldc, _ := strconv.Atoi(revision) oldc, _ := strconv.Atoi(revision)
log.Warn("current version here", lasttag) log.Log(INFO, "current version here", lasttag)
log.Warn("current release a,b,c =", major, minor, revision) log.Log(INFO, "current release a,b,c =", major, minor, revision)
newa, _ := strconv.Atoi(rs.major.String()) newa, _ := strconv.Atoi(rs.major.String())
@ -199,7 +288,7 @@ func (rs *RepoStatus) setTag() bool {
return false return false
} }
if newa > olda { if newa > olda {
log.Warn("new version ok", newver, "vs old version", lasttag) log.Log(INFO, "new version ok", newver, "vs old version", lasttag)
rs.newversion.SetLabel(newver) rs.newversion.SetLabel(newver)
rs.minor.SetText("") rs.minor.SetText("")
rs.revision.SetText("") rs.revision.SetText("")
@ -215,7 +304,7 @@ func (rs *RepoStatus) setTag() bool {
} }
if newb > oldb { if newb > oldb {
log.Warn("new version ok", newver, "vs old version", lasttag) log.Log(INFO, "new version ok", newver, "vs old version", lasttag)
rs.newversion.SetLabel(newver) rs.newversion.SetLabel(newver)
rs.revision.SetText("") rs.revision.SetText("")
return true return true
@ -228,7 +317,7 @@ func (rs *RepoStatus) setTag() bool {
rs.newversion.SetLabel("bad") rs.newversion.SetLabel("bad")
return false return false
} }
log.Warn("new version ok", newver, "vs old version", lasttag) log.Log(INFO, "new version ok", newver, "vs old version", lasttag)
rs.newversion.SetLabel(newver) rs.newversion.SetLabel(newver)
return true return true
} }
@ -238,7 +327,7 @@ func (rs *RepoStatus) incrementVersion() {
var major, minor, revision string var major, minor, revision string
major, minor, revision = splitVersion(lasttag) major, minor, revision = splitVersion(lasttag)
log.Warn("Should release version here", lasttag) log.Warn("Should release version here", lasttag)
log.Warn("Should release a,b,c", major, minor, revision) log.Log(INFO, "Should release a,b,c", major, minor, revision)
a, _ := strconv.Atoi(major) a, _ := strconv.Atoi(major)
b, _ := strconv.Atoi(minor) b, _ := strconv.Atoi(minor)
@ -259,23 +348,23 @@ func (rs *RepoStatus) incrementVersion() {
} }
func (rs *RepoStatus) recommend() { func (rs *RepoStatus) recommend() {
log.Warn("Is repo dirty?", rs.dirtyLabel.String()) log.Log(INFO, "Is repo dirty?", rs.dirtyLabel.String())
log.Warn("list the known tags") log.Log(INFO, "list the known tags")
rs.DisableEverything() rs.DisableEverything()
rs.populateTags() rs.populateTags()
log.Warn("Does devel == user?", rs.develBranchVersion.String(), rs.userBranchVersion.String()) log.Log(INFO, "Does devel == user?", rs.develBranchVersion.String(), rs.userBranchVersion.String())
if rs.develBranchVersion.String() != rs.userBranchVersion.String() { if rs.develBranchVersion.String() != rs.userBranchVersion.String() {
log.Warn("devel does not equal user") log.Log(INFO, "devel does not equal user")
log.Warn("merge or squash?") log.Log(INFO, "merge or squash?")
rs.EnableMergeDevel() rs.EnableMergeDevel()
rs.setMergeUserCommands() rs.setMergeUserCommands()
label := "merge user into " + rs.GetDevelBranchName() label := "merge user into " + rs.GetDevelBranchName()
rs.develMerge.SetLabel(label) rs.develMerge.SetLabel(label)
return return
} }
log.Warn("Does master == devel? ", rs.masterBranchVersion.String(), rs.develBranchVersion.String()) log.Log(INFO, "Does master == devel? ", rs.masterBranchVersion.String(), rs.develBranchVersion.String())
if rs.masterBranchVersion.String() != rs.develBranchVersion.String() { if rs.masterBranchVersion.String() != rs.develBranchVersion.String() {
log.Warn("master does not equal devel. merge devel into master") log.Log(INFO, "master does not equal devel. merge devel into master")
rs.EnableMergeDevel() rs.EnableMergeDevel()
rs.setMergeDevelCommands() rs.setMergeDevelCommands()
label := "merge devel into " + rs.GetMasterBranchName() label := "merge devel into " + rs.GetMasterBranchName()
@ -284,13 +373,13 @@ func (rs *RepoStatus) recommend() {
} }
rs.getLastTagVersion() rs.getLastTagVersion()
if rs.lasttag.String() != rs.masterBranchVersion.String() { if rs.lasttag.String() != rs.masterBranchVersion.String() {
log.Warn("master does not equal last tag") log.Log(INFO, "master does not equal last tag")
rs.incrementVersion() rs.incrementVersion()
rs.EnableSelectTag() rs.EnableSelectTag()
rs.setTag() rs.setTag()
return return
} }
log.Warn("Is repo pushed upstream? git.wit.org or github?") log.Log(INFO, "Is repo pushed upstream? git.wit.org or github?")
} }
func (rs *RepoStatus) generateCmd() bool { func (rs *RepoStatus) generateCmd() bool {
@ -300,17 +389,17 @@ func (rs *RepoStatus) generateCmd() bool {
// aka: "Topsy", "Picasso", "Buzz", etc // aka: "Topsy", "Picasso", "Buzz", etc
if !rs.setTag() { if !rs.setTag() {
log.Warn("tag sucked. fix your tag version") log.Log(INFO, "tag sucked. fix your tag version")
rs.versionMessage.SetLabel("tag message (bad version)") rs.versionMessage.SetLabel("tag message (bad version)")
rs.releaseVersion.Disable() rs.releaseVersion.Disable()
return false return false
} }
log.Warn("tag is valid!!!!") log.Log(INFO, "tag is valid!!!!")
rs.setGitCommands() rs.setGitCommands()
if rs.versionMessage.String() == "" { if rs.versionMessage.String() == "" {
log.Warn("tag message is empty!!!!") log.Log(INFO, "tag message is empty!!!!")
rs.releaseVersion.Disable() rs.releaseVersion.Disable()
return false return false
} }
@ -326,7 +415,7 @@ func (rs *RepoStatus) generateCmd() bool {
func (rs *RepoStatus) runGitCommands() bool { func (rs *RepoStatus) runGitCommands() bool {
for _, line := range rs.versionCmds { for _, line := range rs.versionCmds {
s := strings.Join(line, " ") s := strings.Join(line, " ")
log.Warn("NEED TO RUN:", s) log.Log(INFO, "NEED TO RUN:", s)
rs.develMerge.SetText(s) rs.develMerge.SetText(s)
err, b, output := runCmd(rs.repopath, line) err, b, output := runCmd(rs.repopath, line)
if err != nil { if err != nil {
@ -335,9 +424,9 @@ func (rs *RepoStatus) runGitCommands() bool {
log.Warn("output =", output) log.Warn("output =", output)
return false return false
} }
log.Warn("Returned with b =", b) log.Log(INFO, "Returned with b =", b)
log.Warn("output was =", output) log.Log(INFO, "output was =", output)
log.Warn("RUN DONE") log.Log(INFO, "RUN DONE")
} }
return true return true
} }
@ -360,7 +449,7 @@ func (rs *RepoStatus) setGitCommands() {
// convert to displayable to the user text // convert to displayable to the user text
for _, line := range all { for _, line := range all {
s := strings.Join(line, " ") s := strings.Join(line, " ")
log.Warn("s =", s) log.Log(INFO, "s =", s)
tmp = append(tmp, s) tmp = append(tmp, s)
} }
@ -387,7 +476,7 @@ func (rs *RepoStatus) setMergeDevelCommands() {
// convert to displayable to the user text // convert to displayable to the user text
for _, line := range all { for _, line := range all {
s := strings.Join(line, " ") s := strings.Join(line, " ")
log.Warn("s =", s) log.Log(INFO, "s =", s)
tmp = append(tmp, s) tmp = append(tmp, s)
} }
@ -414,7 +503,7 @@ func (rs *RepoStatus) setMergeUserCommands() {
// convert to displayable to the user text // convert to displayable to the user text
for _, line := range all { for _, line := range all {
s := strings.Join(line, " ") s := strings.Join(line, " ")
log.Warn("s =", s) log.Log(INFO, "s =", s)
tmp = append(tmp, s) tmp = append(tmp, s)
} }

57
git.go
View File

@ -31,21 +31,21 @@ func (rs *RepoStatus) GetLastTagVersion() string {
func (rs *RepoStatus) getCurrentBranchName() string { func (rs *RepoStatus) getCurrentBranchName() string {
out := run(rs.repopath, "git", "branch --show-current") out := run(rs.repopath, "git", "branch --show-current")
log.Warn("getCurrentBranchName() =", out) log.Log(INFO, "getCurrentBranchName() =", out)
rs.currentBranch.SetValue(out) rs.currentBranch.SetValue(out)
return out return out
} }
func (rs *RepoStatus) getCurrentBranchVersion() string { func (rs *RepoStatus) getCurrentBranchVersion() string {
out := run(rs.repopath, "git", "describe --tags") out := run(rs.repopath, "git", "describe --tags")
log.Warn("getCurrentBranchVersion()", out) log.Log(INFO, "getCurrentBranchVersion()", out)
rs.currentVersion.SetValue(out) rs.currentVersion.SetValue(out)
return out return out
} }
func (rs *RepoStatus) getLastTagVersion() string { func (rs *RepoStatus) getLastTagVersion() string {
out := run(rs.repopath, "git", "rev-list --tags --max-count=1") out := run(rs.repopath, "git", "rev-list --tags --max-count=1")
log.Warn("getLastTagVersion()", out) log.Log(INFO, "getLastTagVersion()", out)
rs.lasttagrev = out rs.lasttagrev = out
lastreal := "describe --tags " + out lastreal := "describe --tags " + out
@ -59,10 +59,10 @@ func (rs *RepoStatus) getLastTagVersion() string {
func (rs *RepoStatus) populateTags() { func (rs *RepoStatus) populateTags() {
tmp := fullpath(rs.repopath + "/.git/refs/tags") tmp := fullpath(rs.repopath + "/.git/refs/tags")
log.Warn("populateTags() path =", tmp) log.Log(INFO, "populateTags() path =", tmp)
for _, tag := range listFiles(tmp) { for _, tag := range listFiles(tmp) {
if rs.tags[tag] == "" { if rs.tags[tag] == "" {
log.Warn("populateTags() Adding new tag", tag) log.Log(INFO, "populateTags() Adding new tag", tag)
rs.tagsDrop.AddText(tag) rs.tagsDrop.AddText(tag)
rs.tags[tag] = "origin" rs.tags[tag] = "origin"
} }
@ -94,7 +94,7 @@ func (rs *RepoStatus) getBranches() []string {
all = append(all, remotes...) all = append(all, remotes...)
for _, branch := range all { for _, branch := range all {
log.Warn("getBranches()", branch) log.Log(INFO, "getBranches()", branch)
} }
return all return all
} }
@ -113,12 +113,12 @@ func (rs *RepoStatus) CheckDirty() bool {
return true return true
} }
if b { if b {
log.Warn("CheckDirty() b =", b, "path =", path, "out =", out) log.Log(INFO, "CheckDirty() b =", b, "path =", path, "out =", out)
log.Warn("CheckDirty() no", rs.repopath) log.Log(INFO, "CheckDirty() no", rs.repopath)
rs.dirtyLabel.SetValue("no") rs.dirtyLabel.SetValue("no")
return false return false
} }
log.Warn("CheckDirty() true", rs.repopath) log.Log(INFO, "CheckDirty() true", rs.repopath)
rs.dirtyLabel.SetValue("dirty") rs.dirtyLabel.SetValue("dirty")
return true return true
@ -129,21 +129,21 @@ func (rs *RepoStatus) CheckoutBranch(branch string) (string, string) {
realname := rs.getCurrentBranchName() realname := rs.getCurrentBranchName()
realversion := rs.getCurrentBranchVersion() realversion := rs.getCurrentBranchVersion()
log.Warn(rs.repopath, "realname =", realname, "realversion =", realversion) log.Log(INFO, rs.repopath, "realname =", realname, "realversion =", realversion)
return realname, realversion return realname, realversion
} }
func (rs *RepoStatus) checkoutBranch(level string, branch string) { func (rs *RepoStatus) checkoutBranch(level string, branch string) {
if rs.CheckDirty() { if rs.CheckDirty() {
log.Warn("checkoutBranch() checkDirty() == true for repo", rs.repopath, "looking for branch:", branch) log.Log(INFO, "checkoutBranch() checkDirty() == true for repo", rs.repopath, "looking for branch:", branch)
return return
} }
out := run(rs.repopath, "git", "checkout "+branch) out := run(rs.repopath, "git", "checkout "+branch)
log.Warn(rs.repopath, "git checkout "+branch, "returned", out) log.Log(INFO, rs.repopath, "git checkout "+branch, "returned", out)
realname := rs.getCurrentBranchName() realname := rs.getCurrentBranchName()
realversion := rs.getCurrentBranchVersion() realversion := rs.getCurrentBranchVersion()
log.Warn(rs.repopath, "realname =", realname, "realversion =", realversion) log.Log(INFO, rs.repopath, "realname =", realname, "realversion =", realversion)
switch level { switch level {
case "master": case "master":
@ -156,20 +156,23 @@ func (rs *RepoStatus) checkoutBranch(level string, branch string) {
} }
} }
func (rs *RepoStatus) SetMasterBranchName(s string) { func (rs *RepoStatus) SetMainWorkingName(s string) {
rs.masterDrop.SetText(s) rs.mainWorkingName.SetValue(s)
rs.masterBranchVersion.SetLabel(s) rs.masterDrop.SetLabel(s)
// rs.major.SetTitle(s) rs.masterDrop.SetText("guimaster")
} }
func (rs *RepoStatus) SetDevelBranchName(s string) { func (rs *RepoStatus) SetDevelWorkingName(s string) {
rs.develDrop.SetText(s) rs.develWorkingName.SetValue(s)
rs.develBranchVersion.SetLabel(s) rs.develBranchVersion.SetLabel(s)
rs.develDrop.SetLabel(s)
rs.develDrop.SetText(s)
} }
func (rs *RepoStatus) SetUserBranchName(s string) { func (rs *RepoStatus) SetUserWorkingName(s string) {
rs.userDrop.SetText(s) rs.userWorkingName.SetValue(s)
rs.userBranchVersion.SetLabel(s) rs.userBranchVersion.SetLabel(s)
rs.userDrop.SetText(s)
} }
// returns "master", "devel", os.Username, etc // returns "master", "devel", os.Username, etc
@ -230,7 +233,7 @@ func (rs *RepoStatus) SetUserVersion(s string) {
func (rs *RepoStatus) GetStatus() string { func (rs *RepoStatus) GetStatus() string {
rs.changed = false rs.changed = false
if rs.CheckDirty() { if rs.CheckDirty() {
log.Warn("CheckDirty() true") log.Log(INFO, "CheckDirty() true")
return "dirty" return "dirty"
} }
if rs.userBranchVersion.String() != rs.develBranchVersion.String() { if rs.userBranchVersion.String() != rs.develBranchVersion.String() {
@ -244,10 +247,10 @@ func (rs *RepoStatus) GetStatus() string {
} }
if rs.CheckBranches() { if rs.CheckBranches() {
log.Info("Branches are Perfect") log.Log(INFO, "Branches are Perfect")
return "PERFECT" return "PERFECT"
} }
log.Warn(rs.GetPath(), "Branches are not Perfect") log.Log(INFO, rs.GetPath(), "Branches are not Perfect")
return "unknown branches" return "unknown branches"
} }
@ -272,7 +275,7 @@ func (rs *RepoStatus) CheckBranches() bool {
// Slice the last 4 runes // Slice the last 4 runes
lastFour := runes[runeCount-4:] lastFour := runes[runeCount-4:]
if string(lastFour) == "HEAD" { if string(lastFour) == "HEAD" {
log.Warn("skip HEAD fullfile", fullfile) log.Log(INFO, "skip HEAD fullfile", fullfile)
continue continue
} }
@ -285,9 +288,9 @@ func (rs *RepoStatus) CheckBranches() bool {
cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash) cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash)
_, _, output := RunCmd("/home/jcarr/go/src/"+rs.repopath, cmd) _, _, output := RunCmd("/home/jcarr/go/src/"+rs.repopath, cmd)
// git show -s --format=%ci <hash> will give you the time // git show -s --format=%ci <hash> will give you the time
// log.Warn(fullfile) // log.Log(INFO, fullfile)
if hash == hashCheck { if hash == hashCheck {
log.Warn(hash, output, b) log.Log(INFO, hash, output, b)
} else { } else {
log.Warn("UNKNOWN BRANCHES IN THIS REPO") log.Warn("UNKNOWN BRANCHES IN THIS REPO")
rs.versionMessage.SetText("UNKNOWN BRANCHES") rs.versionMessage.SetText("UNKNOWN BRANCHES")

235
gitConfig.go Normal file
View File

@ -0,0 +1,235 @@
package repostatus
import (
"bufio"
"os"
"path/filepath"
"strings"
"go.wit.com/log"
)
// GitConfig represents the parsed .git/config data
// type GitConfig map[string]map[string]string
type remote struct {
url string
fetch string
}
type branch struct {
remote string
merge string
}
type GitConfig struct {
core map[string]string // map[origin] = "https:/git.wit.org/gui/gadgets"
remotes map[string]*remote // map[origin] = "https:/git.wit.org/gui/gadgets"
branches map[string]*branch // map[guimaster] = origin guimaster
}
type GoConfig map[string]string
func listGitDirectories() []string {
var all []string
homeDir, err := os.UserHomeDir()
if err != nil {
log.Log(WARN, "Error getting home directory:", err)
return nil
}
srcDir := filepath.Join(homeDir, "go/src")
err = filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Log(WARN, "Error accessing path:", path, err)
return nil
}
// Check if the current path is a directory and has a .git subdirectory
if info.IsDir() && isGitDir(path) {
all = append(all, path)
// fmt.Println(path)
}
return nil
})
if err != nil {
log.Log(WARN, "Error walking the path:", srcDir, err)
}
return all
}
// isGitDir checks if a .git directory exists inside the given directory
func isGitDir(dir string) bool {
gitDir := filepath.Join(dir, ".git")
info, err := os.Stat(gitDir)
if os.IsNotExist(err) {
return false
}
return info.IsDir()
}
// readGitConfig reads and parses the .git/config file
func readGitConfig(filePath string) (*GitConfig, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer file.Close()
var currentSection string = ""
var currentName string = ""
config := new(GitConfig)
config.core = make(map[string]string)
config.remotes = make(map[string]*remote)
config.branches = make(map[string]*branch)
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
// Skip empty lines and comments
if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, ";") {
continue
}
// Check for section headers
if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
line = strings.Trim(line, "[]")
parts := strings.Split(line, " ")
currentSection = parts[0]
if len(parts) == 2 {
line = strings.Trim(line, "[]")
currentName = strings.Trim(parts[1], "[]")
}
continue
}
partsNew := strings.SplitN(line, "=", 2)
if len(partsNew) != 2 {
log.Log(WARN, "error on config section:", currentSection, "line:", line)
}
key := strings.TrimSpace(partsNew[0])
value := strings.TrimSpace(partsNew[1])
switch currentSection {
case "core":
config.core[key] = value
case "remote":
test, ok := config.remotes[currentName]
if !ok {
test = new(remote)
config.remotes[currentName] = test
}
log.Log(INFO, "switch currentSection", currentSection, currentName)
switch key {
case "url":
if test.url == value {
continue
}
if test.url == "" {
test.url = value
continue
}
log.Log(WARN, "error url mismatch", test.url, value)
case "fetch":
if test.fetch == value {
continue
}
if test.fetch == "" {
test.fetch = value
continue
}
log.Log(WARN, "error fetch mismatch", test.fetch, value)
default:
log.Log(WARN, "error unknown remote:", currentSection, currentName, "key", key, "value", value)
}
case "branch":
test, ok := config.branches[currentName]
if !ok {
test = new(branch)
config.branches[currentName] = test
}
switch key {
case "remote":
config.branches[currentName].remote = value
case "merge":
config.branches[currentName].merge = value
default:
log.Log(WARN, "error unknown remote:", currentSection, currentName, key, value)
}
default:
log.Log(WARN, "error unknown currentSection", currentSection, "line:", line)
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
return config, nil
}
// readGoMod reads and parses the go.sum file (TODO: do the go.mod file)
func (rs *RepoStatus) ReadGoMod() bool {
tmp := filepath.Join(rs.realPath.String(), "go.sum")
gomod, err := os.Open(tmp)
if err != nil {
log.Log(WARN, "missing go.mod", rs.realPath.String())
rs.goConfig = nil
return false
}
defer gomod.Close()
tmp = filepath.Join(rs.realPath.String(), "go.sum")
gosum, err := os.Open(tmp)
if err != nil {
log.Log(WARN, "missing go.sum", rs.realPath.String())
rs.goConfig = nil
return false
}
defer gosum.Close()
var deps GoConfig
deps = make(GoConfig)
scanner := bufio.NewScanner(gosum)
log.Log(INFO, "gosum:", tmp)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
parts := strings.Split(line, " ")
if len(parts) == 3 {
godep := strings.TrimSpace(parts[0])
version := strings.TrimSpace(parts[1])
if strings.HasSuffix(version, "/go.mod") {
version = strings.TrimSuffix(version, "/go.mod")
}
currentversion, ok := deps[godep]
if ok {
if currentversion != version {
log.Log(WARN, "versions do not match!!!", deps[godep], version, currentversion)
}
} else {
deps[godep] = version
log.Log(INFO, "\t", godep, "=", version)
}
} else {
log.Log(WARN, "\t INVALID:", parts)
}
}
if err := scanner.Err(); err != nil {
rs.goConfig = nil
return false
}
rs.goConfig = deps
return true
}

4
go.mod
View File

@ -3,8 +3,8 @@ module go.wit.com/lib/gui/repostatus
go 1.21.4 go 1.21.4
require ( require (
go.wit.com/gui v0.12.19 go.wit.com/gui v0.12.20
go.wit.com/lib/gadgets v0.12.15 go.wit.com/lib/gadgets v0.12.16
go.wit.com/log v0.5.6 go.wit.com/log v0.5.6
go.wit.com/widget v1.1.6 go.wit.com/widget v1.1.6
) )

8
go.sum
View File

@ -4,10 +4,10 @@ go.wit.com/dev/alexflint/scalar v1.2.1 h1:loXOcbVnd+8YeJRLey+XXidecBiedMDO00zQ26
go.wit.com/dev/alexflint/scalar v1.2.1/go.mod h1:+rYsfxqdI2cwA8kJ7GCMwWbNJvfvWUurOCXLiwdTtSs= go.wit.com/dev/alexflint/scalar v1.2.1/go.mod h1:+rYsfxqdI2cwA8kJ7GCMwWbNJvfvWUurOCXLiwdTtSs=
go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNek= go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNek=
go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA= go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA=
go.wit.com/gui v0.12.19 h1:OEnsnZnec7Q2jZVjwl413V0wuVAAB4r2mGTY0IouBuw= go.wit.com/gui v0.12.20 h1:mIc2DKGcpQjZdgtAj5qzkBrBDiteWfIaEpLyMnIBkh8=
go.wit.com/gui v0.12.19/go.mod h1:v2VgnOL3dlZ13KclYeedZ1cd20nQdvwjyJTNKvFX3DA= go.wit.com/gui v0.12.20/go.mod h1:v2VgnOL3dlZ13KclYeedZ1cd20nQdvwjyJTNKvFX3DA=
go.wit.com/lib/gadgets v0.12.15 h1:C9q6wc45Trh5SrizD8lOXOWoJLGq/ESWwzjCVylZrNY= go.wit.com/lib/gadgets v0.12.16 h1:xHz8zZiTe8xiGvfWs3s9drYUbePTT/Te58u7WXHjx0s=
go.wit.com/lib/gadgets v0.12.15/go.mod h1:Fxc7F8hGskpkWVAsXKhs4ilqUlAnikVXj4yzumtTYa0= go.wit.com/lib/gadgets v0.12.16/go.mod h1:9779QoRZlk+G3/MCcX4Io1eH3HTLImE0AXdAMMdw+0U=
go.wit.com/log v0.5.6 h1:rDC3ju95zfEads4f1Zm+QMkqjZ39CsYAT/UmQQs7VP4= go.wit.com/log v0.5.6 h1:rDC3ju95zfEads4f1Zm+QMkqjZ39CsYAT/UmQQs7VP4=
go.wit.com/log v0.5.6/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo= go.wit.com/log v0.5.6/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo=
go.wit.com/widget v1.1.6 h1:av2miF5vlohMfARA/QGPTPfgW/ADup1c+oeAOKgroPY= go.wit.com/widget v1.1.6 h1:av2miF5vlohMfARA/QGPTPfgW/ADup1c+oeAOKgroPY=

33
new.go
View File

@ -1,6 +1,9 @@
package repostatus package repostatus
import ( import (
"os"
"path/filepath"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/log" "go.wit.com/log"
@ -16,12 +19,40 @@ func ListAll() {
func NewRepoStatusWindow(path string) *RepoStatus { func NewRepoStatusWindow(path string) *RepoStatus {
if windowMap[path] == nil { if windowMap[path] == nil {
log.Warn("This doesn't exist yet for path", path) log.Log(INFO, "NewRepoStatusWindow() adding new", path)
} else { } else {
log.Warn("This already exists yet for path", path) log.Warn("This already exists yet for path", path)
log.Warn("should return windowMap[path] here") log.Warn("should return windowMap[path] here")
return windowMap[path]
} }
homeDir, err := os.UserHomeDir()
if err != nil {
log.Log(WARN, "Error getting home directory:", err)
return nil
}
goSrcDir := filepath.Join(homeDir, "go/src")
realpath := filepath.Join(goSrcDir, path)
filename := filepath.Join(realpath, ".git/config")
gitConfig, err := readGitConfig(filename)
// if the .git/config file fails to load, just nil out man
if err != nil {
log.Log(WARN, "Error reading .git/config:", err)
return nil
}
rs := New(gui.TreeRoot(), path) rs := New(gui.TreeRoot(), path)
// save ~/go/src & the whole path strings
rs.goSrcPath.SetValue(goSrcDir)
rs.realPath.SetValue(realpath)
// save .git/config
rs.gitConfig = gitConfig
windowMap[path] = rs windowMap[path] = rs
// todo check if a window already exists for this path // todo check if a window already exists for this path

View File

@ -23,6 +23,8 @@ type RepoStatus struct {
// status *gadgets.OneLiner // status *gadgets.OneLiner
dirtyLabel *gadgets.OneLiner dirtyLabel *gadgets.OneLiner
path *gadgets.OneLiner path *gadgets.OneLiner
goSrcPath *gadgets.OneLiner
realPath *gadgets.OneLiner
currentBranch *gadgets.OneLiner currentBranch *gadgets.OneLiner
currentVersion *gadgets.OneLiner currentVersion *gadgets.OneLiner
@ -33,6 +35,10 @@ type RepoStatus struct {
develBranchVersion *gadgets.OneLiner develBranchVersion *gadgets.OneLiner
userBranchVersion *gadgets.OneLiner userBranchVersion *gadgets.OneLiner
mainWorkingName *gadgets.OneLiner
develWorkingName *gadgets.OneLiner
userWorkingName *gadgets.OneLiner
develMerge *gui.Node develMerge *gui.Node
releaseVersion *gui.Node releaseVersion *gui.Node
@ -60,4 +66,7 @@ type RepoStatus struct {
speed *gadgets.OneLiner speed *gadgets.OneLiner
speedActual *gadgets.OneLiner speedActual *gadgets.OneLiner
gitConfig *GitConfig
goConfig GoConfig
} }

34
unix.go
View File

@ -27,16 +27,17 @@ func run(path string, thing string, cmdline string) string {
// Execute the command // Execute the command
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
tmp := string(output)
tmp = strings.TrimSpace(tmp)
if err != nil { if err != nil {
log.Log(WARN, "run()", path, thing, cmdline, "=", tmp)
log.Error(err, "cmd error'd out", parts) log.Error(err, "cmd error'd out", parts)
return "" return ""
} }
tmp := string(output)
tmp = strings.TrimSpace(tmp)
// Print the output // Print the output
log.Log(WARN, "run()", path, thing, cmdline, "=", tmp) log.Log(INFO, "run()", path, thing, cmdline, "=", tmp)
return tmp return tmp
} }
@ -100,7 +101,7 @@ func normalizeVersion(s string) string {
return parts[0] return parts[0]
} }
clean := reg.ReplaceAllString(parts[0], "") clean := reg.ReplaceAllString(parts[0], "")
log.Log(WARN, "normalizeVersion() s =", clean) log.Log(INFO, "normalizeVersion() s =", clean)
return clean return clean
} }
@ -134,8 +135,8 @@ func RunCmd(workingpath string, parts []string) (error, bool, string) {
} }
thing := parts[0] thing := parts[0]
parts = parts[1:] parts = parts[1:]
log.Log(INFO, "working path =", workingpath, "thing =", thing, "cmdline =", parts)
log.Warn("working path =", workingpath, "thing =", thing, "cmdline =", parts)
// Create the command // Create the command
cmd := exec.Command(thing, parts...) cmd := exec.Command(thing, parts...)
@ -145,9 +146,25 @@ func RunCmd(workingpath string, parts []string) (error, bool, string) {
// Execute the command // Execute the command
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
if err != nil { if err != nil {
if thing == "git" {
log.Log(INFO, "git ERROR. maybe okay", workingpath, "thing =", thing, "cmdline =", parts)
log.Log(INFO, "git ERROR. maybe okay err =", err)
if err.Error() == "exit status 1" {
log.Log(INFO, "git ERROR. normal exit status 1")
if parts[0] == "diff-index" {
log.Log(INFO, "git normal diff-index when repo dirty")
return nil, false, "git diff-index exit status 1"
}
}
}
log.Log(WARN, "ERROR working path =", workingpath, "thing =", thing, "cmdline =", parts)
log.Log(WARN, "ERROR working path =", workingpath, "thing =", thing, "cmdline =", parts)
log.Log(WARN, "ERROR working path =", workingpath, "thing =", thing, "cmdline =", parts)
log.Error(err) log.Error(err)
log.Warn("output was", string(output)) log.Warn("output was", string(output))
log.Warn("cmd exited with error", err) log.Warn("cmd exited with error", err)
// panic("fucknuts")
return err, false, string(output) return err, false, string(output)
} }
@ -159,12 +176,11 @@ func RunCmd(workingpath string, parts []string) (error, bool, string) {
} }
// Set the path to the package // Set the path to the package
// Replace this with the actual path to the github.com/coredns/coredns directory
func getfiles(pathToPackage string) { func getfiles(pathToPackage string) {
// List files in the directory // List files in the directory
err := filepath.Walk(pathToPackage, nil) // compiles but crashes err := filepath.Walk(pathToPackage, nil) // compiles but crashes
if err == nil { if err == nil {
log.Warn("directory ok", pathToPackage) log.Log(INFO, "directory ok", pathToPackage)
} else { } else {
log.Warn("directory wrong", pathToPackage) log.Warn("directory wrong", pathToPackage)
} }
@ -189,6 +205,6 @@ func VerifyLocalGoRepo(gorepo string) bool {
// Form the path to the home Git directory // Form the path to the home Git directory
gitDir := filepath.Join(usr.HomeDir, "go/src/", gorepo, ".git") gitDir := filepath.Join(usr.HomeDir, "go/src/", gorepo, ".git")
log.Warn("go directory:", gitDir) log.Log(INFO, "go directory:", gitDir)
return IsDirectory(gitDir) return IsDirectory(gitDir)
} }

View File

@ -14,7 +14,7 @@ func (rs *RepoStatus) Update() {
log.Error(errors.New("Update() is not ready yet")) log.Error(errors.New("Update() is not ready yet"))
return return
} }
log.Log(WARN, "Update() START") log.Log(INFO, "Update() START")
duration := timeFunction(func() { duration := timeFunction(func() {
// do things that are safe even if the git tree is dirty // do things that are safe even if the git tree is dirty
rs.path.SetValue(rs.repopath) rs.path.SetValue(rs.repopath)
@ -37,27 +37,24 @@ func (rs *RepoStatus) Update() {
user := rs.userDrop.String() user := rs.userDrop.String()
// rs.CheckDirty() this runs // rs.CheckDirty() this runs
log.Log(WARN, "") log.Log(INFO, "checkoutBranch", master)
log.Log(WARN, "checkoutBranch", master)
rs.checkoutBranch("master", master) rs.checkoutBranch("master", master)
log.Log(WARN, "") log.Log(INFO, "checkoutBranch", devel)
log.Log(WARN, "checkoutBranch", devel)
rs.checkoutBranch("devel", devel) rs.checkoutBranch("devel", devel)
log.Log(WARN, "") log.Log(INFO, "checkoutBranch", user)
log.Log(WARN, "checkoutBranch", user)
rs.checkoutBranch("user", user) rs.checkoutBranch("user", user)
rs.recommend() rs.recommend()
rs.CheckBranches() rs.CheckBranches()
}) })
rs.setSpeed(duration) rs.setSpeed(duration)
log.Log(WARN, "Update() END") log.Log(INFO, "Update() END")
} }
func (rs *RepoStatus) setSpeed(duration time.Duration) { func (rs *RepoStatus) setSpeed(duration time.Duration) {
s := fmt.Sprint(duration) s := fmt.Sprint(duration)
if rs.speedActual == nil { if rs.speedActual == nil {
log.Log(WARN, "can't actually warn") log.Log(WARN, "rs.speedActual == nil")
return return
} }
rs.speedActual.SetValue(s) rs.speedActual.SetValue(s)
@ -73,7 +70,7 @@ func (rs *RepoStatus) setSpeed(duration time.Duration) {
// disable all things besides Update() button // disable all things besides Update() button
func (rs *RepoStatus) DisableEverything() { func (rs *RepoStatus) DisableEverything() {
log.Warn("DisableEverything()") log.Log(INFO, "DisableEverything()")
// choosing a major, minor or revision // choosing a major, minor or revision
rs.major.Disable() rs.major.Disable()