summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-07 20:39:30 -0600
committerJeff Carr <[email protected]>2025-01-07 20:39:30 -0600
commitfcb74ce2e8ef9c62a30288ec028a69f275e2f8b3 (patch)
treeddb494c48bb8286dd242824bfa808e4d36f31b46
parent648d3ac6b6e4213b43cc9362e25d5ed0d74e63be (diff)
attempt to set pb.State
-rw-r--r--git.go66
-rw-r--r--gitConfig.go103
-rw-r--r--new.go2
-rw-r--r--update.go48
4 files changed, 37 insertions, 182 deletions
diff --git a/git.go b/git.go
index 6ab4bbe..e0be1e9 100644
--- a/git.go
+++ b/git.go
@@ -9,34 +9,6 @@ import (
"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
func (rs *RepoStatus) Path() string {
return rs.realPath.String()
@@ -46,48 +18,10 @@ func (rs *RepoStatus) GitState() string {
return rs.gitState.String()
}
-func (rs *RepoStatus) CheckGitState() string {
- rs.setState()
- return rs.gitState.String()
-}
-
func (rs *RepoStatus) GetStatus() 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 {
return rs.lasttag.String()
}
diff --git a/gitConfig.go b/gitConfig.go
index 006ce8a..d863cd7 100644
--- a/gitConfig.go
+++ b/gitConfig.go
@@ -33,50 +33,6 @@ type GitConfig struct {
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
func (rs *RepoStatus) readGitConfig() error {
filename := filepath.Join(rs.realPath.String(), "/.git/config")
@@ -211,47 +167,6 @@ func (rs *RepoStatus) readGitConfig() error {
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) {
fullpath := rs.realPath.String()
log.Log(INFO, " ", branch)
@@ -277,21 +192,3 @@ func (rs *RepoStatus) processBranch(branch string) {
rs.gitConfig.versions[newhash] = 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
-}
diff --git a/new.go b/new.go
index 2dc9f00..542857c 100644
--- a/new.go
+++ b/new.go
@@ -14,6 +14,7 @@ func init() {
windowMap = make(map[string]*RepoStatus)
}
+/*
// deprecate this
func ListAllOld() {
}
@@ -31,6 +32,7 @@ func FindPathOld(path string) *RepoStatus {
func SetWorkPath(path string) {
os.Setenv("REPO_WORK_PATH", path)
}
+*/
// makes a window of the status of the repo
// don't worry, you can think of it like Sierpinski carpet
diff --git a/update.go b/update.go
index 55d529f..a30b35c 100644
--- a/update.go
+++ b/update.go
@@ -6,12 +6,7 @@ import (
"go.wit.com/log"
)
-func (rs *RepoStatus) UpdateNew() {
- log.Info("gui update", rs.pb.GetFullPath())
- rs.updateNew()
-}
-
-func (rs *RepoStatus) updateNew() {
+func (rs *RepoStatus) Update() {
if !rs.Ready() {
log.Log(WARN, "can't update yet. ready is false")
log.Error(errors.New("Update() is not ready yet"))
@@ -45,13 +40,40 @@ func (rs *RepoStatus) updateNew() {
rs.CheckGitState()
}
-func (rs *RepoStatus) Update() {
- if !rs.Ready() {
- log.Log(WARN, "can't update yet. ready is false")
- log.Error(errors.New("Update() is not ready yet"))
+func (rs *RepoStatus) CheckGitState() string {
+ rs.setState()
+ 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(INFO, "Update() START")
- rs.updateNew()
- log.Log(INFO, "Update() END")
+ 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")
}