repostatus/update.go

80 lines
1.8 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
"go.wit.com/log"
)
2025-01-07 20:39:30 -06:00
func (rs *RepoStatus) Update() {
2024-02-16 11:41:29 -06:00
if !rs.Ready() {
log.Log(WARN, "can't update yet. ready is false")
log.Error(errors.New("Update() is not ready yet"))
return
}
2024-02-16 17:55:13 -06:00
2025-01-07 04:58:05 -06:00
pb := rs.pb
2024-02-16 17:55:13 -06:00
// store the current checked out branch name and version
rs.checkCurrentBranchName()
rs.checkCurrentBranchVersion()
// read in the tags
2024-02-16 11:41:29 -06:00
rs.populateTags()
2024-02-16 17:55:13 -06:00
// record if the repo is dirty
2025-01-07 04:58:05 -06:00
pb.CheckDirty()
2024-02-16 11:41:29 -06:00
2024-02-16 17:55:13 -06:00
// store the last tag version
rs.setLastTagVersion()
// store the master branch version
2025-01-07 04:58:05 -06:00
ver := pb.GetMasterVersion()
rs.mainBranchVersion.SetValue(ver)
2024-02-16 11:41:29 -06:00
2025-01-07 04:58:05 -06:00
rs.develBranchVersion.SetValue(pb.GetDevelVersion())
rs.userBranchVersion.SetValue(pb.GetUserVersion())
2024-02-19 16:29:10 -06:00
// populates a string into the rs.gitState widget
// todo: make the values from this function a bit cleaner
rs.CheckGitState()
2024-02-16 11:41:29 -06:00
}
2025-01-07 20:39:30 -06:00
func (rs *RepoStatus) CheckGitState() string {
rs.setState()
return rs.gitState.String()
}
func (rs *RepoStatus) setState() {
pb := rs.pb
rs.changed = false
if pb.CheckDirty() {
log.Log(REPO, "CheckDirty() true")
rs.gitState.SetText("dirty")
return
}
if pb.GetUserVersion() != pb.GetDevelVersion() {
rs.gitState.SetText("merge to devel")
return
}
if pb.GetDevelVersion() != pb.GetMasterVersion() {
rs.gitState.SetText("merge to main")
return
}
if pb.GetLastTag() != pb.GetMasterVersion() {
rs.gitState.SetText("unchanged")
return
}
if pb.CheckBranches() {
log.Log(REPO, "Branches are Perfect")
rs.gitState.SetText("PERFECT")
2024-01-09 15:34:53 -06:00
return
}
2025-01-07 20:39:30 -06:00
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
log.Log(REPO, "FIND THIS IN REPO STATUS Branches are not Perfect")
rs.gitState.SetText("unknown branches")
2024-01-09 15:34:53 -06:00
}