attempt to set pb.State

This commit is contained in:
Jeff Carr 2025-01-07 20:39:30 -06:00
parent 648d3ac6b6
commit fcb74ce2e8
4 changed files with 37 additions and 182 deletions

66
git.go
View File

@ -9,34 +9,6 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
/*
func (rs *RepoStatus) GetCurrentBranchName() string {
return rs.currentBranch.String()
}
func (rs *RepoStatus) GetCurrentBranchVersion() string {
return rs.currentVersion.String()
}
func (rs *RepoStatus) Age() time.Duration {
var t *Tag
t = rs.NewestTag()
if t != nil {
log.Log(REPO, "newest tag:", t.date.String(), t.tag.String(), t.Name())
return t.Age()
}
const gitLayout = "Mon Jan 2 15:04:05 2006 -0700"
const madeuptime = "Mon Jun 3 15:04:05 2013 -0700"
tagTime, _ := time.Parse(gitLayout, madeuptime)
return time.Since(tagTime)
}
var ErrorMissingGitConfig error = errors.New("missing .git/config")
var ErrorGitPullOnLocal error = errors.New("git pull on local only branch")
*/
// remove this everything // remove this everything
func (rs *RepoStatus) Path() string { func (rs *RepoStatus) Path() string {
return rs.realPath.String() return rs.realPath.String()
@ -46,48 +18,10 @@ func (rs *RepoStatus) GitState() string {
return rs.gitState.String() return rs.gitState.String()
} }
func (rs *RepoStatus) CheckGitState() string {
rs.setState()
return rs.gitState.String()
}
func (rs *RepoStatus) GetStatus() string { func (rs *RepoStatus) GetStatus() string {
return rs.gitState.String() return rs.gitState.String()
} }
func (rs *RepoStatus) setState() {
pb := rs.pb
rs.changed = false
if pb.CheckDirty() {
log.Log(REPO, "CheckDirty() true")
rs.gitState.SetText("dirty")
return
}
if pb.GetUserVersion() != pb.GetDevelVersion() {
rs.gitState.SetText("merge to devel")
return
}
if pb.GetDevelVersion() != pb.GetMasterVersion() {
rs.gitState.SetText("merge to main")
return
}
if pb.GetLastTag() != pb.GetMasterVersion() {
rs.gitState.SetText("unchanged")
return
}
if pb.CheckBranches() {
log.Log(REPO, "Branches are Perfect")
rs.gitState.SetText("PERFECT")
return
}
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
rs.gitState.SetText("unknown branches")
}
func (rs *RepoStatus) GetLastTagVersion() string { func (rs *RepoStatus) GetLastTagVersion() string {
return rs.lasttag.String() return rs.lasttag.String()
} }

View File

@ -33,50 +33,6 @@ type GitConfig struct {
versions map[string]string versions map[string]string
} }
// 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 // readGitConfig reads and parses the .git/config file
func (rs *RepoStatus) readGitConfig() error { func (rs *RepoStatus) readGitConfig() error {
filename := filepath.Join(rs.realPath.String(), "/.git/config") filename := filepath.Join(rs.realPath.String(), "/.git/config")
@ -211,47 +167,6 @@ func (rs *RepoStatus) readGitConfig() error {
return nil return nil
} }
func (rs *RepoStatus) GitURL() string {
origin, ok := rs.gitConfig.remotes["origin"]
if ok {
return origin.url
}
for i, s := range rs.gitConfig.remotes {
log.Log(WARN, "remote:", i, s.url)
}
log.Log(WARN, "GitURL() repo has non-standard origin or is not uploaded")
return ""
}
/*
func (rs *RepoStatus) GitLsFiles() (bool, string) {
r := rs.Run([]string{"git", "ls-files"})
output := strings.Join(r.Stdout, "\n")
if r.Error != nil {
log.Warn("git ls-files failed err =", r.Error)
log.Warn("git ls-files failed output =", output)
return false, output
}
return true, output
}
*/
func (rs *RepoStatus) ReadOnly() bool {
if rs.readOnly.String() == "true" {
return true
} else {
return false
}
}
func (rs *RepoStatus) SetReadOnly(b bool) {
if b {
rs.readOnly.SetText("true")
} else {
rs.readOnly.SetText("false")
}
}
func (rs *RepoStatus) processBranch(branch string) { func (rs *RepoStatus) processBranch(branch string) {
fullpath := rs.realPath.String() fullpath := rs.realPath.String()
log.Log(INFO, " ", branch) log.Log(INFO, " ", branch)
@ -277,21 +192,3 @@ func (rs *RepoStatus) processBranch(branch string) {
rs.gitConfig.versions[newhash] = name rs.gitConfig.versions[newhash] = name
log.Log(INFO, " hash: version", name) log.Log(INFO, " hash: version", name)
} }
func (rs *RepoStatus) BranchExists(branch string) bool {
hash, ok := rs.gitConfig.hashes[branch]
if ok {
log.Log(REPOWARN, rs.Path(), "found branch", branch, hash)
return true
}
for i, t := range rs.Tags.tags {
base := filepath.Base(t.tag.String())
if base == branch {
log.Info("found branch tag:", i, t.tag.String())
return true
}
// log.Info("not tag:", i, t.tag.String())
}
log.Log(REPOWARN, rs.Path(), "did not find branch", branch)
return false
}

2
new.go
View File

@ -14,6 +14,7 @@ func init() {
windowMap = make(map[string]*RepoStatus) windowMap = make(map[string]*RepoStatus)
} }
/*
// deprecate this // deprecate this
func ListAllOld() { func ListAllOld() {
} }
@ -31,6 +32,7 @@ func FindPathOld(path string) *RepoStatus {
func SetWorkPath(path string) { func SetWorkPath(path string) {
os.Setenv("REPO_WORK_PATH", path) os.Setenv("REPO_WORK_PATH", path)
} }
*/
// makes a window of the status of the repo // makes a window of the status of the repo
// don't worry, you can think of it like Sierpinski carpet // don't worry, you can think of it like Sierpinski carpet

View File

@ -6,12 +6,7 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
func (rs *RepoStatus) UpdateNew() { func (rs *RepoStatus) Update() {
log.Info("gui update", rs.pb.GetFullPath())
rs.updateNew()
}
func (rs *RepoStatus) updateNew() {
if !rs.Ready() { if !rs.Ready() {
log.Log(WARN, "can't update yet. ready is false") log.Log(WARN, "can't update yet. ready is false")
log.Error(errors.New("Update() is not ready yet")) log.Error(errors.New("Update() is not ready yet"))
@ -45,13 +40,40 @@ func (rs *RepoStatus) updateNew() {
rs.CheckGitState() rs.CheckGitState()
} }
func (rs *RepoStatus) Update() { func (rs *RepoStatus) CheckGitState() string {
if !rs.Ready() { rs.setState()
log.Log(WARN, "can't update yet. ready is false") return rs.gitState.String()
log.Error(errors.New("Update() is not ready yet")) }
func (rs *RepoStatus) setState() {
pb := rs.pb
rs.changed = false
if pb.CheckDirty() {
log.Log(REPO, "CheckDirty() true")
rs.gitState.SetText("dirty")
return return
} }
log.Log(INFO, "Update() START") if pb.GetUserVersion() != pb.GetDevelVersion() {
rs.updateNew() rs.gitState.SetText("merge to devel")
log.Log(INFO, "Update() END") return
}
if pb.GetDevelVersion() != pb.GetMasterVersion() {
rs.gitState.SetText("merge to main")
return
}
if pb.GetLastTag() != pb.GetMasterVersion() {
rs.gitState.SetText("unchanged")
return
}
if pb.CheckBranches() {
log.Log(REPO, "Branches are Perfect")
rs.gitState.SetText("PERFECT")
return
}
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
rs.gitState.SetText("unknown branches")
} }