repostatus/update.go

161 lines
3.4 KiB
Go

package repostatus
import (
"errors"
"fmt"
"strings"
"time"
"go.wit.com/log"
)
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
}
// store the current checked out branch name and version
rs.checkCurrentBranchName()
rs.checkCurrentBranchVersion()
// read in the tags
rs.populateTags()
// record if the repo is dirty
rs.CheckDirty()
// store the last tag version
rs.setLastTagVersion()
// store the master branch version
mName := rs.GetMasterBranchName()
out, _ := rs.gitDescribeByName(mName)
rs.setMasterVersion(out)
// store the devel branch version
dName := rs.GetDevelBranchName()
if dName == "" {
rs.setDevelVersion("")
} else {
out, _ = rs.gitDescribeByName(dName)
rs.setDevelVersion(out)
}
// store the user branch version
uName := rs.GetUserBranchName()
if uName == "" {
rs.setUserVersion("")
} else {
out, _ = rs.gitDescribeByName(uName)
rs.setUserVersion(out)
}
// populates a string into the rs.gitState widget
// todo: make the values from this function a bit cleaner
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"))
return
}
log.Log(INFO, "Update() START")
duration := timeFunction(func() {
rs.UpdateNew()
})
rs.setSpeed(duration)
log.Log(INFO, "Update() END")
}
func (rs *RepoStatus) setSpeed(duration time.Duration) {
s := fmt.Sprint(duration)
if rs.speedActual == nil {
log.Log(WARN, "rs.speedActual == nil")
return
}
rs.speedActual.SetValue(s)
if duration > 200*time.Millisecond {
rs.speed.SetValue("SLOW")
} else if duration > 50*time.Millisecond {
rs.speed.SetValue("OK")
} else {
rs.speed.SetValue("FAST")
}
}
// 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()
}
}