repostatus/update.go

225 lines
5.3 KiB
Go
Raw Normal View History

2024-01-09 15:34:53 -06:00
package repostatus
import (
"errors"
2024-01-09 15:34:53 -06:00
"fmt"
2024-02-16 11:41:29 -06:00
"strings"
2024-01-09 15:34:53 -06:00
"time"
"go.wit.com/log"
)
2024-02-16 11:41:29 -06:00
func (rs *RepoStatus) gitBranchAll() {
err, out := rs.RunCmd([]string{"git", "branch", "--all"})
if err != nil {
log.Log(WARN, "git branch failed", rs.String())
}
all := strings.Split(out, "\n")
for _, s := range all {
// log.Log(WARN, "found branch", i, s)
rs.targetBranch.AddText(s)
}
// i := len(all)
// log.Log(WARN, "branch count =", i)
}
func (rs *RepoStatus) UpdateNew() {
if !rs.Ready() {
log.Log(WARN, "can't update yet. ready is false")
log.Error(errors.New("Update() is not ready yet"))
return
}
// do things that are safe even if the git tree is dirty
// rs.path.SetValue(rs.repopath)
rs.getCurrentBranchName()
// rs.window.SetTitle(rs.repopath + " GO repo Details")
rs.getCurrentBranchVersion()
rs.getLastTagVersion()
rs.populateTags()
rs.CheckDirty()
// get the master branch version
mName := rs.GetMasterBranchName()
cmd := []string{"git", "describe", "--tags", mName}
err, out := rs.RunCmd(cmd)
if err == nil {
log.Log(INFO, "git cmd =", cmd, "worked =", out)
rs.SetMasterVersion(out)
} else {
log.Log(WARN, "git cmd =", cmd)
log.Log(WARN, "git err =", err)
log.Log(WARN, "git master failed", mName, rs.Path())
}
// get the devel branch version
dName := rs.GetDevelBranchName()
cmd = []string{"git", "describe", "--tags", dName}
err, out = rs.RunCmd(cmd)
if err == nil {
log.Log(INFO, "git cmd =", cmd, "worked =", out)
rs.SetDevelVersion(out)
} else {
log.Log(WARN, "git cmd =", cmd)
log.Log(WARN, "git err =", err)
log.Log(WARN, "git devel failed", dName, rs.Path())
}
// get the user branch version
uName := rs.GetUserBranchName()
cmd = []string{"git", "describe", "--tags", uName}
err, out = rs.RunCmd(cmd)
if err == nil {
log.Log(INFO, "git cmd =", cmd, "worked =", out)
rs.SetUserVersion(out)
} else {
log.Log(WARN, "git cmd =", cmd)
log.Log(WARN, "git err =", err)
log.Log(WARN, "git user failed", uName, rs.Path())
}
}
// deprecate / redo what is left of this
func (rs *RepoStatus) UpdateOld() {
if !rs.Ready() {
2024-01-09 15:34:53 -06:00
log.Log(WARN, "can't update yet. ready is false")
log.Error(errors.New("Update() is not ready yet"))
return
}
log.Log(INFO, "Update() START")
duration := timeFunction(func() {
2024-02-16 11:41:29 -06:00
rs.UpdateNew()
2024-01-09 15:34:53 -06:00
if rs.dirtyLabel.String() != "no" {
log.Warn("dirty label != no. actual value:", rs.dirtyLabel.String())
rs.DisableEverything()
rs.CheckBranches()
return
}
master := rs.mainWorkingName.String()
devel := rs.develWorkingName.String()
user := rs.userWorkingName.String()
2024-01-13 20:30:33 -06:00
// rs.CheckDirty() this runs
log.Log(INFO, "checkoutBranch", master)
rs.checkoutBranch("master", master)
log.Log(INFO, "checkoutBranch", devel)
rs.checkoutBranch("devel", devel)
log.Log(INFO, "checkoutBranch", user)
rs.checkoutBranch("user", user)
rs.recommend()
rs.CheckBranches()
label := "merge " + rs.userWorkingName.String() + " to " + rs.develWorkingName.String()
rs.develMergeB.SetLabel(label)
label = "merge " + rs.develWorkingName.String() + " to " + rs.mainWorkingName.String()
rs.mainMergeB.SetLabel(label)
2024-01-09 15:34:53 -06:00
})
rs.setSpeed(duration)
log.Log(INFO, "Update() END")
2024-01-09 15:34:53 -06:00
}
func (rs *RepoStatus) setSpeed(duration time.Duration) {
s := fmt.Sprint(duration)
if rs.speedActual == nil {
log.Log(WARN, "rs.speedActual == nil")
2024-01-09 15:34:53 -06:00
return
}
rs.speedActual.SetValue(s)
2024-01-09 15:34:53 -06:00
if duration > 500*time.Millisecond {
rs.speed.SetValue("SLOW")
} else if duration > 100*time.Millisecond {
rs.speed.SetValue("OK")
2024-01-09 15:34:53 -06:00
} else {
rs.speed.SetValue("FAST")
2024-01-09 15:34:53 -06:00
}
}
// disable all things besides Update() button
func (rs *RepoStatus) DisableEverything() {
log.Log(INFO, "DisableEverything()")
// choosing a major, minor or revision
rs.major.Disable()
rs.minor.Disable()
rs.revision.Disable()
// disable adding a tag message
rs.versionMessage.Disable()
// disable the merge devel to master button
rs.develMergeB.Disable()
// disable the tag a new version button
rs.releaseVersion.Disable()
}
// this means devel needs to be merged to master
func (rs *RepoStatus) EnableMergeDevel() {
rs.DisableEverything()
rs.develMergeB.Enable()
}
func (rs *RepoStatus) Disable() {
rs.window.Disable()
}
func (rs *RepoStatus) Enable() {
rs.window.Enable()
}
// this means you need to release a new version of the master repository
func (rs *RepoStatus) EnableSelectTag() {
rs.DisableEverything()
// choosing a major, minor or revision
rs.major.Enable()
rs.minor.Enable()
rs.revision.Enable()
// disable adding a tag message
rs.versionMessage.Enable()
rs.develMergeB.SetLabel("ready to release")
if len(rs.versionMessage.String()) == 0 {
// force there to be a commit message
rs.releaseVersion.Disable()
} else {
rs.generateCmd()
rs.releaseVersion.Enable()
}
}
// This doesn't switch branches
func (rs *RepoStatus) UpdateCurrent() {
if !rs.Ready() {
log.Log(WARN, "can't update yet. ready is false")
log.Error(errors.New("Update() is not ready yet"))
return
}
log.Log(INFO, "Update() START")
rs.getCurrentBranchName()
rs.getCurrentBranchVersion()
rs.getLastTagVersion()
rs.populateTags()
rs.CheckDirty()
// read in the .git/config each update
rs.readGitConfig()
// this looks into .git somewhat
rs.CheckBranches()
if rs.dirtyLabel.String() != "no" {
// the repo is dirty
log.Warn("dirty label != no. actual value:", rs.dirtyLabel.String())
rs.DisableEverything()
return
}
}