skip HEAD

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-11 23:24:09 -06:00
parent 1248e21394
commit e2acf6511e
3 changed files with 68 additions and 26 deletions

42
draw.go
View File

@ -1,7 +1,6 @@
package repostatus package repostatus
import ( import (
"io/ioutil"
"strconv" "strconv"
"strings" "strings"
@ -62,23 +61,15 @@ func (rs *RepoStatus) drawGitBranches() {
newgrid.NewButton("show branches", func() { newgrid.NewButton("show branches", func() {
all := rs.getBranches() all := rs.getBranches()
i := len(all) i := len(all)
count.Set(strconv.Itoa(i)) count.Set(strconv.Itoa(i) + " branches")
}) })
count = newgrid.NewLabel("") count = newgrid.NewLabel("")
newgrid.NewButton("check branches", func() { newgrid.NewButton("check branches", func() {
all := rs.getBranches() if rs.checkBranches() {
path := fullpath(rs.repopath + "/.git/refs/") log.Warn("Branches are perfect")
for _, b := range all { } else {
parts := strings.Split(b, "/") log.Warn("Branches are not perfect")
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)
} }
}) })
} }
@ -121,12 +112,13 @@ func (rs *RepoStatus) drawGitCommands() {
log.Warn("something went wrong switching to the master branch. full stop!") log.Warn("something went wrong switching to the master branch. full stop!")
return return
} }
if rs.runGitCommands() { if ! rs.runGitCommands() {
log.Warn("THINGS SEEM OK")
} else {
log.Warn("SOMETHING WENT WRONG") log.Warn("SOMETHING WENT WRONG")
return
} }
rs.develMerge.Disable() // don't let this run twice for now rs.develMerge.Disable() // don't let this run twice for now
rs.Update()
log.Warn("THINGS SEEM OK")
}) })
rs.major = gadgets.NewBasicCombobox(newgrid, "major") rs.major = gadgets.NewBasicCombobox(newgrid, "major")
@ -159,11 +151,11 @@ func (rs *RepoStatus) drawGitCommands() {
return return
} }
log.Warn("COMMIT IT HERE") log.Warn("COMMIT IT HERE")
if rs.runGitCommands() { if ! rs.runGitCommands() {
log.Warn("THINGS SEEM OK")
} else {
log.Warn("SOMETHING WENT WRONG") log.Warn("SOMETHING WENT WRONG")
} }
rs.Update()
log.Warn("THINGS SEEM OK")
}) })
newgrid.Margin() newgrid.Margin()
@ -183,12 +175,10 @@ func (rs *RepoStatus) setTag() bool {
log.Warn("current release a,b,c =", major, minor, revision) log.Warn("current release a,b,c =", major, minor, revision)
newa, _ := strconv.Atoi(rs.major.Get()) newa, _ := strconv.Atoi(rs.major.Get())
newb, _ := strconv.Atoi(rs.minor.Get())
newc, _ := strconv.Atoi(rs.revision.Get())
newver := strconv.Itoa(newa) newver := strconv.Itoa(newa)
if newa < olda { 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") rs.newversion.Set("bad")
return false return false
} }
@ -200,9 +190,10 @@ func (rs *RepoStatus) setTag() bool {
return true return true
} }
newb, _ := strconv.Atoi(rs.minor.Get())
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb) newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb)
if newb < oldb { 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") rs.newversion.Set("bad")
return false return false
} }
@ -214,6 +205,7 @@ func (rs *RepoStatus) setTag() bool {
return true return true
} }
newc, _ := strconv.Atoi(rs.revision.Get())
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb) + "." + strconv.Itoa(newc) newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb) + "." + strconv.Itoa(newc)
if newc <= oldc { if newc <= oldc {
log.Warn("new version bad", newver, "vs old version", lasttag) log.Warn("new version bad", newver, "vs old version", lasttag)

50
git.go
View File

@ -1,6 +1,10 @@
package repostatus package repostatus
import ( import (
"strings"
"unicode/utf8"
"io/ioutil"
"go.wit.com/log" "go.wit.com/log"
) )
@ -110,3 +114,49 @@ func (rs *RepoStatus) checkoutBranch(level string, branch string) {
default: 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
}

View File

@ -125,7 +125,7 @@ func runCmd(path string, parts []string) (error, bool, string) {
thing := parts[0] thing := parts[0]
parts = parts[1:] parts = parts[1:]
log.Warn("path =", path, "thing =", thing, "cmdline =", parts) log.Info("path =", path, "thing =", thing, "cmdline =", parts)
// Create the command // Create the command
cmd := exec.Command(thing, parts...) cmd := exec.Command(thing, parts...)