continue to redo the branch handling

This commit is contained in:
Jeff Carr 2024-02-16 20:36:31 -06:00
parent 0b4f4d7686
commit c7aaea4ae1
6 changed files with 431 additions and 465 deletions

View File

@ -13,7 +13,7 @@ func (rs *RepoStatus) makeBranchesBox(parent *gui.Node) {
rs.lasttag = gadgets.NewOneLiner(newgrid, "last tag") // `progname:"LASTTAG"`
newgrid.NextRow()
rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master") // `progname:"MASTERBRANCH"`
rs.mainBranchVersion = gadgets.NewOneLiner(newgrid, "master") // `progname:"MASTERBRANCH"`
newgrid.NextRow()
rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel") // `progname:"DEVELBRANCH"`
newgrid.NextRow()

365
draw.go
View File

@ -1,13 +1,8 @@
package repostatus
import (
"strconv"
"strings"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/log"
"go.wit.com/widget"
)
func (rs *RepoStatus) drawGitStatus(box *gui.Node) {
@ -28,19 +23,6 @@ func (rs *RepoStatus) drawGitStatus(box *gui.Node) {
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
var cmd []string
cmd = append(cmd, "git", "for-each-ref", "--sort=taggerdate", "--format", "%(tag) %(subject)", "refs/tags")
_, _, output := rs.RunCmd(cmd)
log.Log(INFO, output)
for _, line := range strings.Split(output, "\n") {
rs.tagsDrop.AddText(line)
}
*/
rs.dirtyLabel = gadgets.NewOneLiner(newgrid, "dirty")
rs.readOnly = gadgets.NewOneLiner(newgrid, "read only")
rs.goSumStatus = gadgets.NewOneLiner(newgrid, "go mod status")
@ -53,350 +35,3 @@ func (rs *RepoStatus) drawGitStatus(box *gui.Node) {
func (rs *RepoStatus) SetGoSumStatus(s string) {
rs.goSumStatus.SetText(s)
}
func (rs *RepoStatus) RunDevelMergeB() bool {
master := rs.mainWorkingName.String()
log.Warn("RunDevelMergeB() checking out master branch", master)
rs.checkoutBranch("master", master)
if rs.getCurrentBranchName() != master {
log.Warn("RunDevelMergeB() something went wrong switching to the master branch. full stop!")
return false
}
log.Warn("RunDevelMergeB() running runGitCommands()")
if !rs.runGitCommands(true) {
log.Warn("RunDevelMergeB() SOMETHING WENT WRONG")
return false
}
rs.UpdateNew()
log.Warn("RunDevelMergeB() THINGS SEEM OK runGitCommands() returned true.")
return true
}
func (rs *RepoStatus) runReleaseVersionB() bool {
if !rs.generateCmd() {
log.Warn("something is wrong. fix the errors first")
return false
}
rs.releaseVersion.Disable()
log.Warn("MAKING A RELEASE AND VERSION")
if !rs.runGitCommands(true) {
log.Warn("SOMETHING WENT WRONG")
rs.UpdateNew()
rs.Enable()
return false
}
log.Warn("THINGS SEEM OK. runReleaseVersionB worked. Release is finished. restart autotypist()")
rs.Hide()
return true
}
func (rs *RepoStatus) runFullAutomation() bool {
if !rs.RunDevelMergeB() {
log.Warn("THINGS FAILED returned false")
return false
}
log.Warn("THINGS SEEM OK returned true. can run this again?")
log.Warn("develMerge =", rs.develMergeB.String())
label := "merge devel into " + rs.GetMasterBranchName()
if label == rs.develMergeB.String() {
log.Warn("LABELS MATCH", label, rs.develMergeB.String())
if !rs.RunDevelMergeB() {
log.Warn("THINGS FAILED returned false")
return false
}
}
if rs.develMergeB.String() == "ready to release" {
log.Warn("THINGS SEEM OK ready to release")
if rs.releaseVersion.String() == "Release!" {
log.Warn("releaseVersion == 'Release!'. safe to do release version HERE?")
log.Warn("rs.newversion =", rs.newversion.String())
log.Warn("rs.targetReleaseVersion =", rs.targetReleaseVersion.String())
log.Warn("Are these equal?")
if rs.newversion.String() == rs.targetReleaseVersion.String() {
log.Warn("THEY ARE EQUAL!")
rs.runReleaseVersionB()
} else {
log.Warn("THEY ARE NOT EQUAL")
}
}
}
return true
}
var releaseRevision string = ""
// over ride the computation of this if a release is being created
func (rs *RepoStatus) setRevision(c string) {
if releaseRevision == "" {
rs.revision.SetText(c)
}
rs.revision.SetText(releaseRevision)
}
func (rs *RepoStatus) SetVersion(a, b, c string, reason string) {
rs.major.SetText(a)
rs.minor.SetText(b)
releaseRevision = c
rs.setRevision(c)
rs.targetReleaseVersion.SetText(a + "." + b + "." + c)
rs.versionMessage.SetLabel(reason)
rs.versionMessage.SetText(reason)
// rs.versionMessage.SetValue(reason)
}
func (rs *RepoStatus) setTag() bool {
lasttag := rs.lasttag.String()
var major, minor, revision string
major, minor, revision = splitVersion(lasttag)
olda, _ := strconv.Atoi(major)
oldb, _ := strconv.Atoi(minor)
oldc, _ := strconv.Atoi(revision)
log.Log(INFO, "current version here", lasttag)
log.Log(INFO, "current release a,b,c =", major, minor, revision)
newa, _ := strconv.Atoi(rs.major.String())
newver := strconv.Itoa(newa)
if newa < olda {
log.Warn("new version bad", newver, "vs old version", lasttag, "newa =", newa, "olda =", olda)
rs.newversion.SetLabel("bad")
return false
}
if newa > olda {
log.Log(INFO, "new version ok", newver, "vs old version", lasttag)
rs.minor.SetText("0")
rs.setRevision("0")
newver := strconv.Itoa(newa) + ".0.0"
rs.newversion.SetLabel(newver)
return true
}
newb, _ := strconv.Atoi(rs.minor.String())
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb)
if newb < oldb {
log.Warn("new version bad", newver, "vs old version", lasttag, "newb =", newb, "oldb =", oldb)
rs.newversion.SetLabel("bad")
return false
}
if newb > oldb {
log.Log(INFO, "new version ok", newver, "vs old version", lasttag)
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb) + ".0"
rs.newversion.SetLabel(newver)
rs.setRevision("0")
return true
}
newc, _ := strconv.Atoi(rs.revision.String())
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb) + "." + strconv.Itoa(newc)
if newc <= oldc {
log.Warn("new version bad", newver, "vs old version", lasttag)
rs.newversion.SetLabel("bad")
return false
}
log.Log(INFO, "new version ok", newver, "vs old version", lasttag)
rs.newversion.SetLabel(newver)
return true
}
func (rs *RepoStatus) incrementVersion() {
lasttag := rs.lasttag.String()
var major, minor, revision string
if rs.targetReleaseVersion.String() == "" {
major, minor, revision = splitVersion(lasttag)
log.Warn("Should release version here", lasttag)
log.Log(INFO, "Should release a,b,c", major, minor, revision)
} else {
// this means there is a specific release version trying to be done
// use the target release version instead
major, minor, revision = splitVersion(rs.targetReleaseVersion.String())
log.Warn("Should release version here", lasttag)
log.Log(INFO, "Should release a,b,c", major, minor, revision)
}
a, _ := strconv.Atoi(major)
b, _ := strconv.Atoi(minor)
c, _ := strconv.Atoi(revision)
rs.major.AddText(widget.GetString(a))
rs.major.AddText(widget.GetString(a + 1))
rs.major.SetText(widget.GetString(a))
rs.minor.AddText(widget.GetString(b))
rs.minor.AddText(widget.GetString(b + 1))
rs.minor.SetText(widget.GetString(b))
// rs.c := strconv.Atoi(revision)
rs.revision.AddText(widget.GetString(c + 1))
rs.revision.AddText(widget.GetString(c + 2))
rs.setRevision(widget.GetString(c + 1))
}
func (rs *RepoStatus) recommend() {
log.Log(INFO, "Is repo dirty?", rs.dirtyLabel.String())
log.Log(INFO, "list the known tags")
rs.DisableEverything()
rs.populateTags()
log.Log(INFO, "Does devel == user?", rs.develBranchVersion.String(), rs.userBranchVersion.String())
if rs.develBranchVersion.String() != rs.userBranchVersion.String() {
log.Log(INFO, "devel does not equal user")
log.Log(INFO, "merge or squash?")
rs.EnableMergeDevel()
rs.setMergeUserCommands()
label := "merge user into " + rs.GetDevelBranchName()
rs.develMergeB.SetLabel(label)
return
}
log.Log(INFO, "Does master == devel? ", rs.masterBranchVersion.String(), rs.develBranchVersion.String())
if rs.masterBranchVersion.String() != rs.develBranchVersion.String() {
log.Log(INFO, "master does not equal devel. merge devel into master")
rs.EnableMergeDevel()
rs.setMergeDevelCommands()
label := "merge devel into " + rs.GetMasterBranchName()
rs.develMergeB.SetLabel(label)
return
}
if rs.lasttag.String() != rs.masterBranchVersion.String() {
log.Log(INFO, "master does not equal last tag")
rs.incrementVersion()
rs.EnableSelectTag()
rs.setTag()
return
}
log.Log(INFO, "Is repo pushed upstream? git.wit.org or github?")
}
func (rs *RepoStatus) generateCmd() bool {
// the length of 24 is arbitrary, but should be short
// they should be things like perhaps, major release names
// or something the users might see.
// aka: "Topsy", "Picasso", "Buzz", etc
if !rs.setTag() {
log.Log(INFO, "tag sucked. fix your tag version")
rs.versionMessage.SetLabel("tag message (bad version)")
rs.releaseVersion.Disable()
return false
}
log.Log(INFO, "tag is valid!!!!")
rs.setGitCommands()
if rs.versionMessage.String() == "" {
log.Log(INFO, "tag message is empty!!!!")
rs.releaseVersion.Disable()
return false
}
if len(rs.versionMessage.String()) > 24 {
rs.versionMessage.SetLabel("tag message (too long)")
} else {
rs.versionMessage.SetLabel("tag message")
}
rs.releaseVersion.SetLabel("Release!")
rs.releaseVersion.Enable()
return true
}
func (rs *RepoStatus) runGitCommands(verbose bool) bool {
for _, line := range rs.versionCmds {
s := strings.Join(line, " ")
if verbose {
log.Log(WARN, "RUNNING:", s)
}
rs.develMergeB.SetText(s)
err, b, output := runCmd(rs.realPath.String(), line)
if err != nil {
log.Warn("ABEND EXECUTION")
log.Warn("error =", err)
log.Warn("output =", output)
return false
}
log.Log(INFO, "Returned with b =", b)
log.Log(INFO, "output was =", output)
log.Log(INFO, "RUN DONE")
}
return true
}
func (rs *RepoStatus) setGitCommands() {
var line1, line2, line3 []string
var all [][]string
newTag := rs.newversion.String()
line1 = append(line1, "git", "tag", "v"+newTag, "-m", rs.versionMessage.String())
all = append(all, line1)
line2 = append(line2, "git", "push", "--tags")
all = append(all, line2)
line3 = append(line3, "git", "push", "--prune", "--tags")
all = append(all, line3)
rs.versionCmds = all
var tmp []string
// convert to displayable to the user text
for _, line := range all {
s := strings.Join(line, " ")
log.Log(INFO, "s =", s)
tmp = append(tmp, s)
}
rs.versionCmdOutput.SetValue(strings.Join(tmp, "\n"))
}
func (rs *RepoStatus) setMergeDevelCommands() {
var line1, line2, line3 []string
var all [][]string
master := rs.GetMasterBranchName()
devel := rs.GetDevelBranchName()
line1 = append(line1, "git", "checkout", master)
all = append(all, line1)
line2 = append(line2, "git", "merge", devel)
all = append(all, line2)
line3 = append(line3, "git", "push")
all = append(all, line3)
rs.versionCmds = all
var tmp []string
// convert to displayable to the user text
for _, line := range all {
s := strings.Join(line, " ")
log.Log(INFO, "s =", s)
tmp = append(tmp, s)
}
rs.versionCmdOutput.SetValue(strings.Join(tmp, "\n"))
}
func (rs *RepoStatus) setMergeUserCommands() {
var line1, line2, line3 []string
var all [][]string
devel := rs.GetDevelBranchName()
user := rs.userWorkingName.String()
line1 = append(line1, "git", "checkout", devel)
all = append(all, line1)
line2 = append(line2, "git", "merge", user)
all = append(all, line2)
line3 = append(line3, "git", "push")
all = append(all, line3)
rs.versionCmds = all
var tmp []string
// convert to displayable to the user text
for _, line := range all {
s := strings.Join(line, " ")
log.Log(INFO, "s =", s)
tmp = append(tmp, s)
}
rs.versionCmdOutput.SetValue(strings.Join(tmp, "\n"))
}

140
git.go
View File

@ -2,6 +2,7 @@ package repostatus
import (
"errors"
"os/user"
"strings"
"time"
"unicode/utf8"
@ -43,10 +44,6 @@ func (rs *RepoStatus) checkCurrentBranchName() string {
return out
}
func (rs *RepoStatus) getCurrentBranchName() string {
return rs.currentBranch.String()
}
func (rs *RepoStatus) gitDescribeByHash(hash string) (string, error) {
if hash == "" {
return "", errors.New("hash was blank")
@ -97,10 +94,6 @@ func (rs *RepoStatus) checkCurrentBranchVersion() string {
return out
}
func (rs *RepoStatus) getCurrentBranchVersion() string {
return rs.currentVersion.String()
}
// this should get the most recent tag
func (rs *RepoStatus) setLastTagVersion() {
hash := run(rs.realPath.String(), "git", "rev-list --tags --max-count=1")
@ -141,6 +134,11 @@ func (rs *RepoStatus) getBranches() []string {
return all
}
// returns quickly based on the last time it was checked
func (rs *RepoStatus) IsDirty() bool {
return rs.dirty
}
func (rs *RepoStatus) CheckDirty() bool {
cmd := []string{"git", "status"}
path := rs.realPath.String()
@ -153,6 +151,7 @@ func (rs *RepoStatus) CheckDirty() bool {
log.Warn("CheckDirty() status err =", err)
log.Error(err, "CheckDirty() git status error")
rs.dirtyLabel.SetValue("error")
rs.dirty = true
return true
}
@ -162,6 +161,7 @@ func (rs *RepoStatus) CheckDirty() bool {
log.Log(INFO, "CheckDirty() b =", b, "path =", path, "out =", out)
log.Log(INFO, "CheckDirty() no", rs.realPath.String())
rs.dirtyLabel.SetValue("no")
rs.dirty = false
return false
}
// sometimes b gets exit status 1 when there isn't anything that has changed
@ -174,6 +174,7 @@ func (rs *RepoStatus) CheckDirty() bool {
log.Log(INFO, "CheckDirty() is normal err =", err)
rs.dirtyLabel.SetValue("dirty")
rs.dirty = true
return true
}
@ -210,21 +211,9 @@ func (rs *RepoStatus) CheckoutMaster() bool {
return false
}
mName := rs.GetMasterBranchName()
cmd := []string{"git", "checkout", mName}
err, b, output := RunCmd(rs.realPath.String(), cmd)
if err != nil {
log.Log(INFO, err, b, output)
if rs.CheckoutBranch(mName) {
return true
}
realname := rs.getCurrentBranchName()
realversion := rs.getCurrentBranchVersion()
log.Log(INFO, rs.realPath.String(), "realname =", realname, "realversion =", realversion)
if realname != mName {
log.Log(INFO, "git checkout failed", rs.realPath.String(), mName, "!=", realname)
return false
}
rs.masterBranchVersion.SetValue(realversion)
return true
}
@ -261,8 +250,8 @@ func (rs *RepoStatus) CheckoutUser() bool {
log.Log(INFO, err, b, output)
}
realname := rs.getCurrentBranchName()
realversion := rs.getCurrentBranchVersion()
realname := rs.GetCurrentBranchName()
realversion := rs.GetCurrentBranchVersion()
log.Log(INFO, rs.realPath.String(), "realname =", realname, "realversion =", realversion)
if realname != bName {
@ -281,13 +270,13 @@ func (rs *RepoStatus) checkoutBranch(level string, branch string) {
out := run(rs.realPath.String(), "git", "checkout "+branch)
log.Log(INFO, rs.realPath.String(), "git checkout "+branch, "returned", out)
realname := rs.getCurrentBranchName()
realversion := rs.getCurrentBranchVersion()
realname := rs.GetCurrentBranchName()
realversion := rs.GetCurrentBranchVersion()
log.Log(INFO, rs.realPath.String(), "realname =", realname, "realversion =", realversion)
switch level {
case "master":
rs.masterBranchVersion.SetValue(realversion)
rs.mainBranchVersion.SetValue(realversion)
case "devel":
rs.develBranchVersion.SetValue(realversion)
case "user":
@ -298,67 +287,58 @@ func (rs *RepoStatus) checkoutBranch(level string, branch string) {
// attempt's to guess at what master is.
// TODO: fix this properly
func (rs *RepoStatus) setMainWorkingName(s string) {
if rs == nil {
log.Info("rs == nil", s)
func (rs *RepoStatus) guessMainWorkingName() {
if !rs.Ready() {
return
}
if rs.gitConfig == nil {
log.Info("rs.gitConfig == nil", s)
rs.mainWorkingName.SetValue(s)
if rs.TagExists("guimaster") {
rs.mainWorkingName.SetText("guimaster")
rs.mainBranchVersion.SetLabel("guimaster")
return
}
if rs.gitConfig.branches == nil {
log.Info("rs.gitConfig.branches == nil", s)
rs.mainWorkingName.SetValue(s)
if rs.TagExists("master") {
rs.mainWorkingName.SetText("master")
rs.mainBranchVersion.SetLabel("master")
return
}
_, ok := rs.gitConfig.branches[s]
if ok {
// log.Info("git branch", s, "seems to exist")
rs.mainWorkingName.SetValue(s)
return
}
s = "guimaster"
_, ok = rs.gitConfig.branches[s]
if ok {
// log.Info("git branch", s, "seems to exist")
rs.mainWorkingName.SetValue(s)
if rs.TagExists("main") {
rs.mainWorkingName.SetText("main")
rs.mainBranchVersion.SetLabel("main")
return
}
s = "master"
_, ok = rs.gitConfig.branches[s]
if ok {
// log.Info("git branch", s, "seems to exist")
rs.mainWorkingName.SetValue(s)
return
}
s = "main"
_, ok = rs.gitConfig.branches[s]
if ok {
// log.Info("git branch", s, "seems to exist")
rs.mainWorkingName.SetValue(s)
return
}
s = "TODO: read .git/config"
log.Warn("git branch", s, "does not seem to exist. TODO: figure out the server default")
for name, _ := range rs.gitConfig.branches {
log.Warn("git branch found. use this?", name)
}
rs.mainWorkingName.SetValue(s)
// figure out what to do here
rs.mainWorkingName.SetText("FIXME")
rs.mainBranchVersion.SetLabel("FIXME")
}
func (rs *RepoStatus) setDevelWorkingName(s string) {
rs.develWorkingName.SetValue(s)
rs.develBranchVersion.SetLabel(s)
func (rs *RepoStatus) guessDevelWorkingName() {
if rs.TagExists("guidevel") {
rs.develWorkingName.SetValue("guidevel")
rs.develBranchVersion.SetLabel("guidevel")
return
}
if rs.TagExists("devel") {
rs.develWorkingName.SetValue("devel")
rs.develBranchVersion.SetLabel("devel")
return
}
// figure out what to do here
rs.develWorkingName.SetValue("develFIXME")
rs.develBranchVersion.SetLabel("develFIXME")
}
func (rs *RepoStatus) setUserWorkingName(s string) {
rs.userWorkingName.SetValue(s)
rs.userBranchVersion.SetLabel(s)
func (rs *RepoStatus) setUserWorkingName() {
usr, _ := user.Current()
uname := usr.Username
if rs.TagExists(uname) {
rs.userWorkingName.SetValue(uname)
rs.userBranchVersion.SetLabel(uname)
return
}
rs.userWorkingName.SetValue("need to create " + uname)
rs.userBranchVersion.SetLabel("need to create " + uname)
}
// returns "master", "devel", os.Username, etc
@ -378,7 +358,7 @@ func (rs *RepoStatus) GetUserBranchName() string {
// returns the git versions like "1.3-2-laksdjf" or whatever
func (rs *RepoStatus) GetMasterVersion() string {
name := rs.masterBranchVersion.String()
name := rs.mainBranchVersion.String()
return name
}
func (rs *RepoStatus) GetDevelVersion() string {
@ -395,7 +375,7 @@ func (rs *RepoStatus) setMasterVersion(s string) {
if old == s {
return
}
rs.masterBranchVersion.SetValue(s)
rs.mainBranchVersion.SetValue(s)
if old == "" {
return // don't note if there was nothing before
}
@ -434,13 +414,13 @@ func (rs *RepoStatus) GetStatus() string {
log.Log(INFO, "CheckDirty() true")
return "dirty"
}
if rs.userBranchVersion.String() != rs.develBranchVersion.String() {
if rs.GetUserVersion() != rs.GetDevelVersion() {
return "merge to devel"
}
if rs.develBranchVersion.String() != rs.masterBranchVersion.String() {
if rs.GetDevelVersion() != rs.GetMasterVersion() {
return "merge to main"
}
if rs.lasttag.String() != rs.masterBranchVersion.String() {
if rs.lasttag.String() != rs.GetMasterVersion() {
return "ready to tag version"
}

360
merge.go Normal file
View File

@ -0,0 +1,360 @@
package repostatus
import (
"strconv"
"strings"
"go.wit.com/log"
"go.wit.com/widget"
)
func (rs *RepoStatus) RunDevelMergeB() bool {
startbranch := rs.GetCurrentBranchName()
master := rs.mainWorkingName.String()
log.Warn("RunDevelMergeB() checking out master branch", master)
rs.CheckoutBranch(master)
newbranch := rs.GetCurrentBranchName()
if newbranch != master {
log.Warn("RunDevelMergeB() something went wrong switching branch:", master)
log.Warn("RunDevelMergeB() start working name =", startbranch)
log.Warn("RunDevelMergeB() current working name =", newbranch)
return false
}
log.Warn("RunDevelMergeB() running runGitCommands()")
if !rs.runGitCommands(true) {
log.Warn("RunDevelMergeB() SOMETHING WENT WRONG")
return false
}
rs.UpdateNew()
log.Warn("RunDevelMergeB() THINGS SEEM OK runGitCommands() returned true.")
return true
}
func (rs *RepoStatus) runReleaseVersionB() bool {
if !rs.generateCmd() {
log.Warn("something is wrong. fix the errors first")
return false
}
rs.releaseVersion.Disable()
log.Warn("MAKING A RELEASE AND VERSION")
if !rs.runGitCommands(true) {
log.Warn("SOMETHING WENT WRONG")
rs.UpdateNew()
rs.Enable()
return false
}
log.Warn("THINGS SEEM OK. runReleaseVersionB worked. Release is finished. restart autotypist()")
rs.Hide()
return true
}
func (rs *RepoStatus) runFullAutomation() bool {
if !rs.RunDevelMergeB() {
log.Warn("THINGS FAILED returned false")
return false
}
log.Warn("THINGS SEEM OK returned true. can run this again?")
log.Warn("develMerge =", rs.develMergeB.String())
label := "merge devel into " + rs.GetMasterBranchName()
if label == rs.develMergeB.String() {
log.Warn("LABELS MATCH", label, rs.develMergeB.String())
if !rs.RunDevelMergeB() {
log.Warn("THINGS FAILED returned false")
return false
}
}
if rs.develMergeB.String() == "ready to release" {
log.Warn("THINGS SEEM OK ready to release")
if rs.releaseVersion.String() == "Release!" {
log.Warn("releaseVersion == 'Release!'. safe to do release version HERE?")
log.Warn("rs.newversion =", rs.newversion.String())
log.Warn("rs.targetReleaseVersion =", rs.targetReleaseVersion.String())
log.Warn("Are these equal?")
if rs.newversion.String() == rs.targetReleaseVersion.String() {
log.Warn("THEY ARE EQUAL!")
rs.runReleaseVersionB()
} else {
log.Warn("THEY ARE NOT EQUAL")
}
}
}
return true
}
var releaseRevision string = ""
// over ride the computation of this if a release is being created
func (rs *RepoStatus) setRevision(c string) {
if releaseRevision == "" {
rs.revision.SetText(c)
}
rs.revision.SetText(releaseRevision)
}
func (rs *RepoStatus) SetVersion(a, b, c string, reason string) {
rs.major.SetText(a)
rs.minor.SetText(b)
releaseRevision = c
rs.setRevision(c)
rs.targetReleaseVersion.SetText(a + "." + b + "." + c)
rs.versionMessage.SetLabel(reason)
rs.versionMessage.SetText(reason)
// rs.versionMessage.SetValue(reason)
}
func (rs *RepoStatus) setTag() bool {
lasttag := rs.lasttag.String()
var major, minor, revision string
major, minor, revision = splitVersion(lasttag)
olda, _ := strconv.Atoi(major)
oldb, _ := strconv.Atoi(minor)
oldc, _ := strconv.Atoi(revision)
log.Log(INFO, "current version here", lasttag)
log.Log(INFO, "current release a,b,c =", major, minor, revision)
newa, _ := strconv.Atoi(rs.major.String())
newver := strconv.Itoa(newa)
if newa < olda {
log.Warn("new version bad", newver, "vs old version", lasttag, "newa =", newa, "olda =", olda)
rs.newversion.SetLabel("bad")
return false
}
if newa > olda {
log.Log(INFO, "new version ok", newver, "vs old version", lasttag)
rs.minor.SetText("0")
rs.setRevision("0")
newver := strconv.Itoa(newa) + ".0.0"
rs.newversion.SetLabel(newver)
return true
}
newb, _ := strconv.Atoi(rs.minor.String())
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb)
if newb < oldb {
log.Warn("new version bad", newver, "vs old version", lasttag, "newb =", newb, "oldb =", oldb)
rs.newversion.SetLabel("bad")
return false
}
if newb > oldb {
log.Log(INFO, "new version ok", newver, "vs old version", lasttag)
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb) + ".0"
rs.newversion.SetLabel(newver)
rs.setRevision("0")
return true
}
newc, _ := strconv.Atoi(rs.revision.String())
newver = strconv.Itoa(newa) + "." + strconv.Itoa(newb) + "." + strconv.Itoa(newc)
if newc <= oldc {
log.Warn("new version bad", newver, "vs old version", lasttag)
rs.newversion.SetLabel("bad")
return false
}
log.Log(INFO, "new version ok", newver, "vs old version", lasttag)
rs.newversion.SetLabel(newver)
return true
}
func (rs *RepoStatus) incrementVersion() {
lasttag := rs.lasttag.String()
var major, minor, revision string
if rs.targetReleaseVersion.String() == "" {
major, minor, revision = splitVersion(lasttag)
log.Warn("Should release version here", lasttag)
log.Log(INFO, "Should release a,b,c", major, minor, revision)
} else {
// this means there is a specific release version trying to be done
// use the target release version instead
major, minor, revision = splitVersion(rs.targetReleaseVersion.String())
log.Warn("Should release version here", lasttag)
log.Log(INFO, "Should release a,b,c", major, minor, revision)
}
a, _ := strconv.Atoi(major)
b, _ := strconv.Atoi(minor)
c, _ := strconv.Atoi(revision)
rs.major.AddText(widget.GetString(a))
rs.major.AddText(widget.GetString(a + 1))
rs.major.SetText(widget.GetString(a))
rs.minor.AddText(widget.GetString(b))
rs.minor.AddText(widget.GetString(b + 1))
rs.minor.SetText(widget.GetString(b))
// rs.c := strconv.Atoi(revision)
rs.revision.AddText(widget.GetString(c + 1))
rs.revision.AddText(widget.GetString(c + 2))
rs.setRevision(widget.GetString(c + 1))
}
func (rs *RepoStatus) recommend() {
log.Log(INFO, "Is repo dirty?", rs.dirtyLabel.String())
log.Log(INFO, "list the known tags")
rs.DisableEverything()
rs.populateTags()
log.Log(INFO, "Does devel == user?", rs.develBranchVersion.String(), rs.userBranchVersion.String())
if rs.develBranchVersion.String() != rs.userBranchVersion.String() {
log.Log(INFO, "devel does not equal user")
log.Log(INFO, "merge or squash?")
rs.EnableMergeDevel()
rs.setMergeUserCommands()
label := "merge user into " + rs.GetDevelBranchName()
rs.develMergeB.SetLabel(label)
return
}
log.Log(INFO, "Does master == devel? ", rs.GetMasterVersion(), rs.GetDevelVersion())
if rs.GetMasterVersion() != rs.GetDevelVersion() {
log.Log(INFO, "master does not equal devel. merge devel into master")
rs.EnableMergeDevel()
rs.setMergeDevelCommands()
label := "merge devel into " + rs.GetMasterBranchName()
rs.develMergeB.SetLabel(label)
return
}
if rs.lasttag.String() != rs.GetMasterVersion() {
log.Log(INFO, "master does not equal last tag")
rs.incrementVersion()
rs.EnableSelectTag()
rs.setTag()
return
}
log.Log(INFO, "Is repo pushed upstream? git.wit.org or github?")
}
func (rs *RepoStatus) generateCmd() bool {
// the length of 24 is arbitrary, but should be short
// they should be things like perhaps, major release names
// or something the users might see.
// aka: "Topsy", "Picasso", "Buzz", etc
if !rs.setTag() {
log.Log(INFO, "tag sucked. fix your tag version")
rs.versionMessage.SetLabel("tag message (bad version)")
rs.releaseVersion.Disable()
return false
}
log.Log(INFO, "tag is valid!!!!")
rs.setGitCommands()
if rs.versionMessage.String() == "" {
log.Log(INFO, "tag message is empty!!!!")
rs.releaseVersion.Disable()
return false
}
if len(rs.versionMessage.String()) > 24 {
rs.versionMessage.SetLabel("tag message (too long)")
} else {
rs.versionMessage.SetLabel("tag message")
}
rs.releaseVersion.SetLabel("Release!")
rs.releaseVersion.Enable()
return true
}
func (rs *RepoStatus) runGitCommands(verbose bool) bool {
for _, line := range rs.versionCmds {
s := strings.Join(line, " ")
if verbose {
log.Log(WARN, "RUNNING:", s)
}
rs.develMergeB.SetText(s)
err, b, output := runCmd(rs.realPath.String(), line)
if err != nil {
log.Warn("ABEND EXECUTION")
log.Warn("error =", err)
log.Warn("output =", output)
return false
}
log.Log(INFO, "Returned with b =", b)
log.Log(INFO, "output was =", output)
log.Log(INFO, "RUN DONE")
}
return true
}
func (rs *RepoStatus) setGitCommands() {
var line1, line2, line3 []string
var all [][]string
newTag := rs.newversion.String()
line1 = append(line1, "git", "tag", "v"+newTag, "-m", rs.versionMessage.String())
all = append(all, line1)
line2 = append(line2, "git", "push", "--tags")
all = append(all, line2)
line3 = append(line3, "git", "push", "--prune", "--tags")
all = append(all, line3)
rs.versionCmds = all
var tmp []string
// convert to displayable to the user text
for _, line := range all {
s := strings.Join(line, " ")
log.Log(INFO, "s =", s)
tmp = append(tmp, s)
}
rs.versionCmdOutput.SetValue(strings.Join(tmp, "\n"))
}
func (rs *RepoStatus) setMergeDevelCommands() {
var line1, line2, line3 []string
var all [][]string
master := rs.GetMasterBranchName()
devel := rs.GetDevelBranchName()
line1 = append(line1, "git", "checkout", master)
all = append(all, line1)
line2 = append(line2, "git", "merge", devel)
all = append(all, line2)
line3 = append(line3, "git", "push")
all = append(all, line3)
rs.versionCmds = all
var tmp []string
// convert to displayable to the user text
for _, line := range all {
s := strings.Join(line, " ")
log.Log(INFO, "s =", s)
tmp = append(tmp, s)
}
rs.versionCmdOutput.SetValue(strings.Join(tmp, "\n"))
}
func (rs *RepoStatus) setMergeUserCommands() {
var line1, line2, line3 []string
var all [][]string
devel := rs.GetDevelBranchName()
user := rs.userWorkingName.String()
line1 = append(line1, "git", "checkout", devel)
all = append(all, line1)
line2 = append(line2, "git", "merge", user)
all = append(all, line2)
line3 = append(line3, "git", "push")
all = append(all, line3)
rs.versionCmds = all
var tmp []string
// convert to displayable to the user text
for _, line := range all {
s := strings.Join(line, " ")
log.Log(INFO, "s =", s)
tmp = append(tmp, s)
}
rs.versionCmdOutput.SetValue(strings.Join(tmp, "\n"))
}

24
new.go
View File

@ -2,7 +2,6 @@ package repostatus
import (
"os"
"os/user"
"path/filepath"
"strings"
@ -114,24 +113,13 @@ func NewRepoStatusWindow(path string) *RepoStatus {
if strings.HasPrefix(path, "git.wit.org") {
rs.readOnly.SetValue("false")
}
rs.setMainWorkingName("master")
usr, _ := user.Current()
uname := usr.Username
if rs.TagExists(uname) {
rs.setUserWorkingName(uname)
} else {
rs.setUserWorkingName("")
}
if rs.TagExists("guidevel") {
rs.setDevelWorkingName("guidevel")
} else if rs.TagExists("devel") {
rs.setDevelWorkingName("devel")
} else {
log.Log(WARN, "tag devel does not exist")
rs.setDevelWorkingName("")
}
// tries 'master', 'main', etc.
rs.guessMainWorkingName()
// tries 'devel', etc
rs.guessDevelWorkingName()
// sets this to os.Username
rs.setUserWorkingName()
windowMap[path] = rs
return rs

View File

@ -12,6 +12,9 @@ type RepoStatus struct {
changed bool
changes string
// updates each time CheckDirty() is run
dirty bool
tags map[string]string
window *gadgets.BasicWindow
@ -32,7 +35,7 @@ type RepoStatus struct {
currentVersion *gadgets.OneLiner
lasttag *gadgets.OneLiner
masterBranchVersion *gadgets.OneLiner
mainBranchVersion *gadgets.OneLiner
develBranchVersion *gadgets.OneLiner
userBranchVersion *gadgets.OneLiner