summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-11 23:24:09 -0600
committerJeff Carr <[email protected]>2024-01-11 23:24:09 -0600
commite2acf6511eb908cbc7813b8bda925c065e0b673a (patch)
tree559750c7fef0a49887f3b0c0064874a0ba5b4e57
parent1248e21394afa41f5a5a42e843c3bd4cae71c5d6 (diff)
skip HEAD
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--draw.go42
-rw-r--r--git.go50
-rw-r--r--unix.go2
3 files changed, 68 insertions, 26 deletions
diff --git a/draw.go b/draw.go
index d52482f..e4f1fa4 100644
--- a/draw.go
+++ b/draw.go
@@ -1,7 +1,6 @@
package repostatus
import (
- "io/ioutil"
"strconv"
"strings"
@@ -62,23 +61,15 @@ func (rs *RepoStatus) drawGitBranches() {
newgrid.NewButton("show branches", func() {
all := rs.getBranches()
i := len(all)
- count.Set(strconv.Itoa(i))
+ count.Set(strconv.Itoa(i) + " branches")
})
count = newgrid.NewLabel("")
+
newgrid.NewButton("check branches", func() {
- all := rs.getBranches()
- path := fullpath(rs.repopath + "/.git/refs/")
- for _, b := range all {
- parts := strings.Split(b, "/")
- rdir := "heads"
- if len(parts) == 2 {
- rdir = "remotes"
- }
- fullfile := path + "/" + rdir + "/" + b
- content, _ := ioutil.ReadFile(fullfile)
- hash := strings.TrimSpace(string(content))
- // log.Warn(fullfile)
- log.Warn(hash, b)
+ if rs.checkBranches() {
+ log.Warn("Branches are perfect")
+ } else {
+ log.Warn("Branches are not perfect")
}
})
}
@@ -121,12 +112,13 @@ func (rs *RepoStatus) drawGitCommands() {
log.Warn("something went wrong switching to the master branch. full stop!")
return
}
- if rs.runGitCommands() {
- log.Warn("THINGS SEEM OK")
- } else {
+ if ! rs.runGitCommands() {
log.Warn("SOMETHING WENT WRONG")
+ return
}
rs.develMerge.Disable() // don't let this run twice for now
+ rs.Update()
+ log.Warn("THINGS SEEM OK")
})
rs.major = gadgets.NewBasicCombobox(newgrid, "major")
@@ -159,11 +151,11 @@ func (rs *RepoStatus) drawGitCommands() {
return
}
log.Warn("COMMIT IT HERE")
- if rs.runGitCommands() {
- log.Warn("THINGS SEEM OK")
- } else {
+ if ! rs.runGitCommands() {
log.Warn("SOMETHING WENT WRONG")
}
+ rs.Update()
+ log.Warn("THINGS SEEM OK")
})
newgrid.Margin()
@@ -183,12 +175,10 @@ func (rs *RepoStatus) setTag() bool {
log.Warn("current release a,b,c =", major, minor, revision)
newa, _ := strconv.Atoi(rs.major.Get())
- newb, _ := strconv.Atoi(rs.minor.Get())
- newc, _ := strconv.Atoi(rs.revision.Get())
newver := strconv.Itoa(newa)
if newa < olda {
- log.Warn("new version bad", newver, "vs old version", lasttag)
+ log.Warn("new version bad", newver, "vs old version", lasttag, "newa =", newa, "olda =", olda)
rs.newversion.Set("bad")
return false
}
@@ -200,9 +190,10 @@ func (rs *RepoStatus) setTag() bool {
return true
}
+ newb, _ := strconv.Atoi(rs.minor.Get())
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb)
if newb < oldb {
- log.Warn("new version bad", newver, "vs old version", lasttag)
+ log.Warn("new version bad", newver, "vs old version", lasttag, "newb =", newb, "oldb =", oldb)
rs.newversion.Set("bad")
return false
}
@@ -214,6 +205,7 @@ func (rs *RepoStatus) setTag() bool {
return true
}
+ newc, _ := strconv.Atoi(rs.revision.Get())
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb) + "." + strconv.Itoa(newc)
if newc <= oldc {
log.Warn("new version bad", newver, "vs old version", lasttag)
diff --git a/git.go b/git.go
index f51efe9..7f36ed8 100644
--- a/git.go
+++ b/git.go
@@ -1,6 +1,10 @@
package repostatus
import (
+ "strings"
+ "unicode/utf8"
+
+ "io/ioutil"
"go.wit.com/log"
)
@@ -110,3 +114,49 @@ func (rs *RepoStatus) checkoutBranch(level string, branch string) {
default:
}
}
+
+func (rs *RepoStatus) checkBranches() bool {
+ var hashCheck string
+ var perfect bool = true
+ all := rs.getBranches()
+ path := fullpath(rs.repopath + "/.git/refs/")
+ for _, b := range all {
+ parts := strings.Split(b, "/")
+ rdir := "heads"
+ if len(parts) == 2 {
+ rdir = "remotes"
+ }
+ fullfile := path + "/" + rdir + "/" + b
+
+ // check if the ref name is "HEAD". if so, skip
+ runeCount := utf8.RuneCountInString(fullfile)
+ // Convert the string to a slice of runes
+ runes := []rune(fullfile)
+ // Slice the last 4 runes
+ lastFour := runes[runeCount-4:]
+ if string(lastFour) == "HEAD" {
+ log.Warn("skip HEAD fullfile", fullfile)
+ continue
+ }
+
+ content, _ := ioutil.ReadFile(fullfile)
+ hash := strings.TrimSpace(string(content))
+ if hashCheck == "" {
+ hashCheck = hash
+ }
+ var cmd []string
+ cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash)
+ _, _, output := runCmd(rs.repopath, cmd)
+ // git show -s --format=%ci <hash> will give you the time
+ // log.Warn(fullfile)
+ if hash == hashCheck {
+ log.Warn(hash, output, b)
+ } else {
+ log.Warn(hash, output, b, "NOT THE SAME")
+ perfect = false
+ parts := strings.Split(b, "/")
+ log.Warn("git push", parts)
+ }
+ }
+ return perfect
+}
diff --git a/unix.go b/unix.go
index 45a1cbc..772e3b7 100644
--- a/unix.go
+++ b/unix.go
@@ -125,7 +125,7 @@ func runCmd(path string, parts []string) (error, bool, string) {
thing := parts[0]
parts = parts[1:]
- log.Warn("path =", path, "thing =", thing, "cmdline =", parts)
+ log.Info("path =", path, "thing =", thing, "cmdline =", parts)
// Create the command
cmd := exec.Command(thing, parts...)